ILIAS  Release_4_2_x_branch Revision 61807
 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 './Services/Xml/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 './Services/Xml/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 './Services/Xml/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  global $ilLog;
305 
306  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
307  try
308  {
309  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($this->fo_string);
310  ilUtil::deliverData($pdf_base64->scalar,'learning_progress.pdf','application/pdf');
311  }
312  catch(XML_RPC2_FaultException $e)
313  {
314  ilUtil::sendFailure($e->getMessage(),true);
315  $ilLog->write(__METHOD__.': '.$e->getMessage());
316  $this->ctrl->returnToParent($this);
317  return false;
318  }
319  catch(Exception $e)
320  {
321  ilUtil::sendFailure($e->getMessage(),true);
322  $ilLog->write(__METHOD__.': '.$e->getMessage());
323  $this->ctrl->returnToParent($this);
324  return false;
325  }
326  }
327 
329  {
330  global $ilObjDataCache,$ilUser;
331 
332  // Load and fill xml template
333  $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
334  $this->__addMain();
335 
336  $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
337  $this->filter->setRequiredPermission('read');
338  $type = $this->filter->getFilterType();
339  $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
340 
341  // Sort objects by title
342  $objs = $this->filter->getObjects();
343  $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
344  // Render item list
345  $counter = 0;
346  foreach($sorted_objs as $object_id)
347  {
348  $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
349  $item_list->setCurrentUser($this->getCurrentUserId());
350  $item_list->readUserInfo();
351  $item_list->renderSimpleProgressFO();
352  }
353 
354  // Finally convert to fop
355  $this->__convert();
356  }
357 
359  {
360  global $ilObjDataCache,$ilUser;
361 
362  // Load and fill xml template
363  $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
364  $this->__addMain();
365 
366  $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
367  $this->filter->setRequiredPermission('read');
368  $type = $this->filter->getFilterType();
369  $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
370 
371  // Sort objects by title
372  $objs = $this->filter->getObjects();
373  $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
374  // Render item list
375  $counter = 0;
376  foreach($sorted_objs as $object_id)
377  {
378  $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
379  #$item_list->setCurrentUser($this->tracked_user->getId());
380  $item_list->setCurrentUser($this->getCurrentUserId());
381  $item_list->readUserInfo();
382  $item_list->renderObjectListFO();
383  }
384 
385  // Finally convert to fop
386  $this->__convert();
387  }
388 
389 
390  function __addMain()
391  {
392  global $ilUser,$ilObjDataCache;
393 
394  $this->tpl->setVariable("LEARNING_PROGRESS_OF",$this->lng->txt('learning_progress'));
395  switch($this->getType())
396  {
397  case LP_ACTIVE_PROGRESS:
398  $name = ilObjUser::_lookupName($this->getCurrentUserId());
399  $this->tpl->setVariable("USER_FULLNAME",$name['lastname'].', '.$name['firstname']);
400  break;
401  }
402  $this->tpl->setVariable("DATE",ilFormat::formatUnixTime(time(),true));
403 
404  return true;
405  }
406 
407 
408  function __convert()
409  {
410  global $ilLog;
411 
412  include_once './Services/WebServices/RPC/classes/class.ilRpcClientFactory.php';
413  try
414  {
415  $pdf_base64 = ilRpcClientFactory::factory('RPCTransformationHandler')->ilFO2PDF($this->tpl->get());
416  ilUtil::deliverData($pdf_base64->scalar,'learning_progress.pdf','application/pdf');
417  return true;
418  }
419  catch(XML_RPC2_FaultException $e)
420  {
421  ilUtil::sendFailure($e->getMessage(),true);
422  $ilLog->write(__METHOD__.': '.$e->getMessage());
423  $this->ctrl->returnToParent($this);
424  return false;
425  }
426  catch(Exception $e)
427  {
428  ilUtil::sendFailure($e->getMessage(),true);
429  $ilLog->write(__METHOD__.': '.$e->getMessage());
430  $this->ctrl->returnToParent($this);
431  return false;
432  }
433  }
434 }
435 ?>