ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDFPresentation.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22  */
23 
40 include_once 'Services/Tracking/classes/ItemList/class.ilLPItemListFactory.php';
41 include_once 'classes/class.ilXmlWriter.php';
42 
44 {
45  var $type = '';
46 
47 
48  function ilPDFPresentation($a_mode,$a_ref_id,$a_user_id = 0,$a_tracked_user = 0)
49  {
50  global $lng,$ilCtrl;
51 
52  parent::ilLearningProgressBaseGUI($a_mode,$a_ref_id,$a_user_id);
53 
54  $this->ctrl =& $ilCtrl;
55  $this->lng =& $lng;
56 
57  $this->current_user_id = $a_tracked_user;
58 
59  $this->__init();
60  }
61 
62  function &getCurrentUserId()
63  {
64  return $this->current_user_id;
65  }
66 
67 
68 
72  function &executeCommand()
73  {
74  $this->ctrl->setReturn($this, "");
75  switch($this->ctrl->getNextClass())
76  {
77  default:
78  $cmd = $this->ctrl->getCmd();
79  $this->$cmd();
80 
81  }
82  return true;
83  }
84 
85  function setType($a_type)
86  {
87  $this->type = $a_type;
88  }
89  function getType()
90  {
91  return $this->type;
92  }
93 
94 
95  // PRIVATE
96  function __init()
97  {
98  global $ilUser;
99 
100  include_once './classes/class.ilXmlWriter.php';
101  $this->xmlWriter = new ilXmlWriter();
102 
103  include_once './Services/Tracking/classes/class.ilLPFilter.php';
104  $this->filter = new ilLPFilter($ilUser->getId());
105 
106  include_once './Services/Tracking/classes/class.ilLPFilterGUI.php';
107  $this->filter_gui = new ilLPFilterGUI($ilUser->getId());
108  }
109 
110  function createList()
111  {
112  switch($this->getType())
113  {
114  case LP_ACTIVE_PROGRESS:
115  return $this->__createPersonalProgressList();
116 
117  case LP_ACTIVE_OBJECTS:
118  return $this->__createObjectList();
119 
120  default:
121  ilUtil::sendInfo('trac_pdf_error'. ' '.$this->getMode(),true);
122  }
123 
124  $this->ctrl->returnToParent($this);
125  }
126 
127  function createDetails()
128  {
129  switch($this->getType())
130  {
131  case LP_ACTIVE_OBJECTS:
132  case LP_ACTIVE_PROGRESS:
133  return $this->__createObjectDetails();
134 
135  default:
136  ilUtil::sendInfo('trac_pdf_error'. ' '.$this->getMode(),true);
137  }
138  }
139 
141  {
142  global $ilObjDataCache;
143 
144  include_once 'classes/class.ilXmlWriter.php';
145  $this->writer = new ilXmlWriter();
146  $this->writer->xmlHeader();
147  $this->writer->xmlStartTag('LearningProgress');
148  $this->writer->xmlElement('Title',null,$this->lng->txt('learning_progress'));
149 
150  // Header
151  $header = $this->lng->txt('learning_progress').': '.ilFormat::formatUnixTime(time(),true);
152  $this->writer->xmlElement('Header',null,$header);
153 
154  // Footer
155  $this->writer->xmlElement('Footer',null,'powered by ILIAS');
156 
157  // Info
158  include_once 'Services/Tracking/classes/ItemList/class.ilLPItemListFactory.php';
159  $this->details_obj_id = $ilObjDataCache->lookupObjId($this->getRefId());
160  $item_list =& ilLPItemListFactory::_getInstance(0,$this->details_obj_id,$ilObjDataCache->lookupType($this->details_obj_id));
161 
162  if($this->getType() == LP_ACTIVE_PROGRESS)
163  {
164  $item_list->setCurrentUser($this->current_user_id);
165  $item_list->readUserInfo();
166  $item_list->renderObjectInfoXML($this->writer,true,true);
167  }
168  else
169  {
170  $item_list->renderObjectInfoXML($this->writer,false,false);
171  }
172  // Items
173  include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
175  {
176  $this->__showItems();
177  }
178 
179  $this->writer->xmlEndTag('LearningProgress');
180 
181  $this->__toFO();
182  $this->__toPDF();
183  }
184 
185  function __showItems()
186  {
187  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
188 
189  global $ilObjDataCache,$ilUser;
190 
191  $not_attempted = ilLPStatusWrapper::_getNotAttempted($this->details_obj_id);
192  $in_progress = ilLPStatusWrapper::_getInProgress($this->details_obj_id);
193  $completed = ilLPStatusWrapper::_getCompleted($this->details_obj_id);
194  $failed = ilLPStatusWrapper::_getFailed($this->details_obj_id);
195 
196  switch($this->getType())
197  {
198  case LP_ACTIVE_OBJECTS:
199  $all_users = array_merge($completed,$in_progress,$not_attempted,$failed);
200  $all_users = $this->__sort($all_users,'usr_data','lastname','usr_id');
201  break;
202 
203  case LP_ACTIVE_PROGRESS:
204  $all_users = array($this->current_user_id);
205  break;
206  }
207 
208  // Header
209  $this->writer->xmlStartTag('Items');
210  $this->writer->xmlStartTag('ItemHeader');
211  $this->writer->xmlElement('HeaderTitle',null,$this->lng->txt('trac_objects'));
212 
213  // Show timings header
214  include_once 'Modules/Course/classes/class.ilCourseItems.php';
215  if($this->has_timings = ilCourseItems::_hasCollectionTimings($this->getRefId()))
216  {
217  $this->writer->xmlElement('HeaderInfo',null,$this->lng->txt('trac_head_timing'));
218  }
219  $this->writer->xmlEndTag('ItemHeader');
220 
221  // Render item list
222  $this->container_row_counter = 0;
223  foreach($all_users as $user)
224  {
225  $this->writer->xmlStartTag('Item');
226  $this->__renderContainerRow(0,$this->getRefId(),$user,'usr',0);
227  $this->writer->xmlEndTag('Item');
228  }
229  $this->writer->xmlEndTag('Items');
230  }
231  function __renderContainerRow($a_parent_id,$a_item_id,$a_usr_id,$type,$level)
232  {
233  global $ilObjDataCache,$ilUser,$ilAccess;
234 
235  include_once 'Services/Tracking/classes/ItemList/class.ilLPItemListFactory.php';
236 
237  $item_list =& ilLPItemListFactory::_getInstanceByRefId($a_parent_id,$a_item_id,$type);
238  if($this->has_timings)
239  {
240  $item_list->readTimings();
241  $item_list->enable('timings');
242  }
243  $item_list->setCurrentUser($a_usr_id);
244  $item_list->readUserInfo();
245  $item_list->setIndentLevel($level);
246 
247 
248  $item_list->renderObjectDetailsXML($this->writer);
249 
250  if($type == 'sahs_item' or
251  $type == 'objective' or
252  $type == 'event')
253  {
254  return true;
255  }
256 
257  include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
258  foreach(ilLPCollectionCache::_getItems($ilObjDataCache->lookupObjId($a_item_id)) as $child_id)
259  {
260  switch($item_list->getMode())
261  {
262  case LP_MODE_OBJECTIVES:
263  $this->writer->xmlStartTag('Item');
264  $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,'objective',$level + 2);
265  $this->writer->xmlEndTag('Item');
266  break;
267 
268  case LP_MODE_SCORM:
269  $this->writer->xmlStartTag('Item');
270  $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,'sahs_item',$level + 2);
271  $this->writer->xmlEndTag('Item');
272  break;
273 
274  default:
275  if(!$ilAccess->checkAccess('read','',$child_id))
276  {
277  break;
278  }
279  $this->writer->xmlStartTag('Item');
280  $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,
281  $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($child_id)),$level + 2);
282  $this->writer->xmlEndTag('Item');
283  break;
284  }
285  }
286  }
287 
288  function __toFO()
289  {
290  include_once 'Services/Transformation/classes/class.ilXML2FO.php';
291 
292  $xml2FO = new ilXML2FO();
293  $xml2FO->setXSLTLocation($this->tpl->getTemplatePath('learning_progress_fo.xsl','Services/Tracking'));
294  $xml2FO->setXMLString($this->writer->xmlDumpMem());
295  $xml2FO->transform();
296 
297  $this->fo_string = $xml2FO->getFOString();
298  #var_dump("<pre>",htmlentities($this->fo_string),"<pre>");
299  return true;
300  }
301 
302  function __toPDF()
303  {
304  include_once 'Services/Transformation/classes/class.ilFO2PDF.php';
305 
306  $fo2pdf = new ilFO2PDF();
307  $fo2pdf->setFOString($this->fo_string);
308  $pdf_base64 = $fo2pdf->send();
309 
310  if(!$pdf_base64)
311  {
312  ilUtil::sendInfo($this->lng->txt('trac_error_pdf',true));
313  $this->ctrl->returnToParent($this);
314  }
315  ilUtil::deliverData($pdf_base64,'learning_progress.pdf','application/pdf');
316  }
317 
319  {
320  global $ilObjDataCache,$ilUser;
321 
322  // Load and fill xml template
323  $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
324  $this->__addMain();
325 
326  $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
327  $this->filter->setRequiredPermission('read');
328  $type = $this->filter->getFilterType();
329  $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
330 
331  // Sort objects by title
332  $objs = $this->filter->getObjects();
333  $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
334  // Render item list
335  $counter = 0;
336  foreach($sorted_objs as $object_id)
337  {
338  $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
339  $item_list->setCurrentUser($this->getCurrentUserId());
340  $item_list->readUserInfo();
341  $item_list->renderSimpleProgressFO();
342  }
343 
344  // Finally convert to fop
345  $this->__convert();
346  }
347 
349  {
350  global $ilObjDataCache,$ilUser;
351 
352  // Load and fill xml template
353  $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
354  $this->__addMain();
355 
356  $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
357  $this->filter->setRequiredPermission('read');
358  $type = $this->filter->getFilterType();
359  $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
360 
361  // Sort objects by title
362  $objs = $this->filter->getObjects();
363  $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
364  // Render item list
365  $counter = 0;
366  foreach($sorted_objs as $object_id)
367  {
368  $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
369  #$item_list->setCurrentUser($this->tracked_user->getId());
370  $item_list->setCurrentUser($this->getCurrentUserId());
371  $item_list->readUserInfo();
372  $item_list->renderObjectListFO();
373  }
374 
375  // Finally convert to fop
376  $this->__convert();
377  }
378 
379 
380  function __addMain()
381  {
382  global $ilUser,$ilObjDataCache;
383 
384  $this->tpl->setVariable("LEARNING_PROGRESS_OF",$this->lng->txt('learning_progress'));
385  switch($this->getType())
386  {
387  case LP_ACTIVE_PROGRESS:
388  $name = ilObjUser::_lookupName($this->getCurrentUserId());
389  $this->tpl->setVariable("USER_FULLNAME",$name['lastname'].', '.$name['firstname']);
390  break;
391  }
392  $this->tpl->setVariable("DATE",ilFormat::formatUnixTime(time(),true));
393 
394  return true;
395  }
396 
397 
398  function __convert()
399  {
400  #include_once 'Services/Transformation/classes/class.ilContentObject2FO.php';
401  #$co2fo = new ilContentObject2FO();
402  #$co2fo->setXMLString($xml = $this->xml_tpl->get());
403 
404  #if(!$co2fo->transform())
405  #{
406  #endInfo($this->lng->txt('trac_error_pdf',true));
407  # $this->ctrl->returnToParent($this);
408  #}
409 
410  include_once 'Services/Transformation/classes/class.ilFO2PDF.php';
411 
412  $fo2pdf = new ilFO2PDF();
413  #echo htmlentities($this->tpl->get());
414  $fo2pdf->setFOString($this->tpl->get());
415 
416  #var_dump("<pre>",htmlentities($fo2pdf->getFOString()),"<pre>");
417 
418  $pdf_base64 = $fo2pdf->send();
419 
420  if(!$pdf_base64)
421  {
422  ilUtil::sendInfo($this->lng->txt('trac_error_pdf',true));
423  $this->ctrl->returnToParent($this);
424  }
425  ilUtil::deliverData($pdf_base64,'learning_progress.pdf','application/pdf');
426  }
427 }
428 ?>