• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Tracking/classes/class.ilPDFPresentation.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    +-----------------------------------------------------------------------------+
00004    | ILIAS open source                                                           |
00005    +-----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007    |                                                                             |
00008    | This program is free software; you can redistribute it and/or               |
00009    | modify it under the terms of the GNU General Public License                 |
00010    | as published by the Free Software Foundation; either version 2              |
00011    | of the License, or (at your option) any later version.                      |
00012    |                                                                             |
00013    | This program is distributed in the hope that it will be useful,             |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016    | GNU General Public License for more details.                                |
00017    |                                                                             |
00018    | You should have received a copy of the GNU General Public License           |
00019    | along with this program; if not, write to the Free Software                 |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021    +-----------------------------------------------------------------------------+
00022   */
00023 
00040 include_once 'Services/Tracking/classes/ItemList/class.ilLPItemListFactory.php';
00041 include_once 'classes/class.ilXmlWriter.php';
00042 
00043 class ilPDFPresentation extends ilLearningProgressBaseGUI
00044 {
00045         var $type = '';
00046 
00047 
00048         function ilPDFPresentation($a_mode,$a_ref_id,$a_user_id = 0,$a_tracked_user = 0)
00049         {
00050                 global $lng,$ilCtrl;
00051 
00052                 parent::ilLearningProgressBaseGUI($a_mode,$a_ref_id,$a_user_id);
00053 
00054                 $this->ctrl =& $ilCtrl;
00055                 $this->lng =& $lng;
00056 
00057                 $this->current_user_id = $a_tracked_user;
00058 
00059                 $this->__init();
00060         }
00061 
00062         function &getCurrentUserId()
00063         {
00064                 return $this->current_user_id;
00065         }
00066 
00067         
00068 
00072         function &executeCommand()
00073         {
00074                 $this->ctrl->setReturn($this, "");
00075                 switch($this->ctrl->getNextClass())
00076                 {
00077                         default:
00078                                 $cmd = $this->ctrl->getCmd();
00079                                 $this->$cmd();
00080 
00081                 }
00082                 return true;
00083         }
00084 
00085         function setType($a_type)
00086         {
00087                 $this->type = $a_type;
00088         }
00089         function getType()
00090         {
00091                 return $this->type;
00092         }
00093 
00094 
00095         // PRIVATE
00096         function __init()
00097         {
00098                 global $ilUser;
00099 
00100                 include_once './classes/class.ilXmlWriter.php';
00101                 $this->xmlWriter = new ilXmlWriter();
00102 
00103                 include_once './Services/Tracking/classes/class.ilLPFilter.php';
00104                 $this->filter = new ilLPFilter($ilUser->getId());
00105 
00106                 include_once './Services/Tracking/classes/class.ilLPFilterGUI.php';
00107                 $this->filter_gui = new ilLPFilterGUI($ilUser->getId());
00108         }
00109 
00110         function createList()
00111         {
00112                 switch($this->getType())
00113                 {
00114                         case LP_ACTIVE_PROGRESS:
00115                                 return $this->__createPersonalProgressList();
00116 
00117                         case LP_ACTIVE_OBJECTS:
00118                                 return $this->__createObjectList();
00119 
00120                         default:
00121                                 ilUtil::sendInfo('trac_pdf_error'. ' '.$this->getMode(),true);
00122                 }
00123 
00124                 $this->ctrl->returnToParent($this);
00125         }
00126 
00127         function createDetails()
00128         {
00129                 switch($this->getType())
00130                 {
00131                         case LP_ACTIVE_OBJECTS:
00132                         case LP_ACTIVE_PROGRESS:
00133                                 return $this->__createObjectDetails();
00134                                 
00135                         default:
00136                                 ilUtil::sendInfo('trac_pdf_error'. ' '.$this->getMode(),true);
00137                 }
00138         }
00139 
00140         function __createObjectDetails()
00141         {
00142                 global $ilObjDataCache;
00143 
00144                 include_once 'classes/class.ilXmlWriter.php';
00145                 $this->writer = new ilXmlWriter();
00146                 $this->writer->xmlHeader();
00147                 $this->writer->xmlStartTag('LearningProgress');
00148                 $this->writer->xmlElement('Title',null,$this->lng->txt('learning_progress'));
00149 
00150                 // Header
00151                 $header = $this->lng->txt('learning_progress').': '.ilFormat::formatUnixTime(time(),true);
00152                 $this->writer->xmlElement('Header',null,$header);
00153                 
00154                 // Footer
00155                 $this->writer->xmlElement('Footer',null,'powered by ILIAS');
00156 
00157                 // Info
00158                 include_once 'Services/Tracking/classes/ItemList/class.ilLPItemListFactory.php';
00159                 $this->details_obj_id = $ilObjDataCache->lookupObjId($this->getRefId());
00160                 $item_list =& ilLPItemListFactory::_getInstance(0,$this->details_obj_id,$ilObjDataCache->lookupType($this->details_obj_id));
00161 
00162                 if($this->getType() == LP_ACTIVE_PROGRESS)
00163                 {
00164                         $item_list->setCurrentUser($this->current_user_id);
00165                         $item_list->readUserInfo();
00166                         $item_list->renderObjectInfoXML($this->writer,true,true);
00167                 }
00168                 else
00169                 {
00170                         $item_list->renderObjectInfoXML($this->writer,false,false);
00171                 }
00172                 // Items
00173                 include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
00174                 if(ilLPObjSettings::_isContainer(ilLPObjSettings::_lookupMode($this->details_obj_id)) or $this->getType() == LP_ACTIVE_OBJECTS)
00175                 {
00176                         $this->__showItems();
00177                 }
00178                 
00179                 $this->writer->xmlEndTag('LearningProgress');
00180 
00181                 $this->__toFO();
00182                 $this->__toPDF();
00183         }
00184 
00185         function __showItems()
00186         {
00187                 include_once 'Services/Tracking/classes/class.ilLPMarks.php';
00188 
00189                 global $ilObjDataCache,$ilUser;
00190 
00191                 $not_attempted = ilLPStatusWrapper::_getNotAttempted($this->details_obj_id);
00192                 $in_progress = ilLPStatusWrapper::_getInProgress($this->details_obj_id);
00193                 $completed = ilLPStatusWrapper::_getCompleted($this->details_obj_id);
00194                 $failed = ilLPStatusWrapper::_getFailed($this->details_obj_id);
00195 
00196                 switch($this->getType())
00197                 {
00198                         case LP_ACTIVE_OBJECTS:
00199                                 $all_users = array_merge($completed,$in_progress,$not_attempted,$failed);
00200                                 $all_users = $this->__sort($all_users,'usr_data','lastname','usr_id');
00201                                 break;
00202 
00203                         case LP_ACTIVE_PROGRESS:
00204                                 $all_users = array($this->current_user_id);
00205                                 break;
00206                 }
00207 
00208                 // Header
00209                 $this->writer->xmlStartTag('Items');
00210                 $this->writer->xmlStartTag('ItemHeader');
00211                 $this->writer->xmlElement('HeaderTitle',null,$this->lng->txt('trac_objects'));
00212                 
00213                 // Show timings header
00214                 include_once 'Modules/Course/classes/class.ilCourseItems.php';
00215                 if($this->has_timings = ilCourseItems::_hasCollectionTimings($this->getRefId()))
00216                 {
00217                         $this->writer->xmlElement('HeaderInfo',null,$this->lng->txt('trac_head_timing'));
00218                 }
00219                 $this->writer->xmlEndTag('ItemHeader');
00220 
00221                 // Render item list
00222                 $this->container_row_counter = 0;
00223                 foreach($all_users as $user)
00224                 {
00225                         $this->writer->xmlStartTag('Item');
00226                         $this->__renderContainerRow(0,$this->getRefId(),$user,'usr',0);
00227                         $this->writer->xmlEndTag('Item');
00228                 }
00229                 $this->writer->xmlEndTag('Items');
00230         }
00231         function __renderContainerRow($a_parent_id,$a_item_id,$a_usr_id,$type,$level)
00232         {
00233                 global $ilObjDataCache,$ilUser,$ilAccess;
00234 
00235                 include_once 'Services/Tracking/classes/ItemList/class.ilLPItemListFactory.php';
00236 
00237                 $item_list =& ilLPItemListFactory::_getInstanceByRefId($a_parent_id,$a_item_id,$type);
00238                 if($this->has_timings)
00239                 {
00240                         $item_list->readTimings();
00241                         $item_list->enable('timings');
00242                 }
00243                 $item_list->setCurrentUser($a_usr_id);
00244                 $item_list->readUserInfo();
00245                 $item_list->setIndentLevel($level);
00246 
00247 
00248                 $item_list->renderObjectDetailsXML($this->writer);
00249 
00250                 if($type == 'sahs_item' or
00251                    $type == 'objective' or
00252                    $type == 'event')
00253                 {
00254                         return true;
00255                 }
00256                 
00257                 include_once './Services/Tracking/classes/class.ilLPEventCollections.php';
00258                 foreach(ilLPEventCollections::_getItems($ilObjDataCache->lookupObjId($a_item_id)) as $event_id)
00259                 {
00260                         $this->writer->xmlStartTag('Item');
00261                         $this->__renderContainerRow($a_item_id,$event_id,$a_usr_id,'event',$level+2);
00262                         $this->writer->xmlEndTag('Item');
00263                 }
00264                 include_once './Services/Tracking/classes/class.ilLPCollectionCache.php';
00265                 foreach(ilLPCollectionCache::_getItems($ilObjDataCache->lookupObjId($a_item_id)) as $child_id)
00266                 {
00267                         switch($item_list->getMode())
00268                         {
00269                                 case LP_MODE_OBJECTIVES:
00270                                         $this->writer->xmlStartTag('Item');
00271                                         $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,'objective',$level + 2);
00272                                         $this->writer->xmlEndTag('Item');
00273                                         break;
00274 
00275                                 case LP_MODE_SCORM:
00276                                         $this->writer->xmlStartTag('Item');
00277                                         $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,'sahs_item',$level + 2);
00278                                         $this->writer->xmlEndTag('Item');
00279                                         break;
00280 
00281                                 default:
00282                                         if(!$ilAccess->checkAccess('read','',$child_id))
00283                                         {
00284                                                 break;
00285                                         }                               
00286                                         $this->writer->xmlStartTag('Item');
00287                                         $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,
00288                                                                                                 $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($child_id)),$level + 2);
00289                                         $this->writer->xmlEndTag('Item');
00290                                         break;
00291                         }
00292                 }
00293         }
00294 
00295         function __toFO()
00296         {
00297                 include_once 'Services/Transformation/classes/class.ilXML2FO.php';
00298                 
00299                 $xml2FO = new ilXML2FO();
00300                 $xml2FO->setXSLTLocation($this->tpl->getTemplatePath('learning_progress_fo.xsl','Services/Tracking'));
00301                 $xml2FO->setXMLString($this->writer->xmlDumpMem());
00302                 $xml2FO->transform();
00303 
00304                 $this->fo_string = $xml2FO->getFOString();
00305                 #var_dump("<pre>",htmlentities($this->fo_string),"<pre>");
00306                 return true;
00307         }
00308 
00309         function __toPDF()
00310         {
00311                 include_once 'Services/Transformation/classes/class.ilFO2PDF.php';
00312 
00313                 $fo2pdf = new ilFO2PDF();
00314                 $fo2pdf->setFOString($this->fo_string);
00315                 $pdf_base64 = $fo2pdf->send();
00316 
00317                 if(!$pdf_base64)
00318                 {
00319                         ilUtil::sendInfo($this->lng->txt('trac_error_pdf',true));
00320                         $this->ctrl->returnToParent($this);
00321                 }
00322                 ilUtil::deliverData($pdf_base64,'learning_progress.pdf','application/pdf');
00323         }
00324 
00325         function __createPersonalProgressList()
00326         {
00327                 global $ilObjDataCache,$ilUser;
00328 
00329                 // Load and fill xml template
00330                 $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
00331                 $this->__addMain();
00332 
00333                 $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
00334                 $this->filter->setRequiredPermission('read');
00335                 $type = $this->filter->getFilterType();
00336                 $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
00337 
00338                 // Sort objects by title
00339                 $objs = $this->filter->getObjects();
00340                 $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
00341                 // Render item list
00342                 $counter = 0;
00343                 foreach($sorted_objs as $object_id)
00344                 {
00345                         $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
00346                         $item_list->setCurrentUser($this->getCurrentUserId());
00347                         $item_list->readUserInfo();
00348                         $item_list->renderSimpleProgressFO();
00349                 }
00350 
00351                 // Finally convert to fop
00352                 $this->__convert();
00353         }
00354 
00355         function __createObjectList()
00356         {
00357                 global $ilObjDataCache,$ilUser;
00358 
00359                 // Load and fill xml template
00360                 $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
00361                 $this->__addMain();
00362 
00363                 $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
00364                 $this->filter->setRequiredPermission('read');
00365                 $type = $this->filter->getFilterType();
00366                 $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
00367 
00368                 // Sort objects by title
00369                 $objs = $this->filter->getObjects();
00370                 $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
00371                 // Render item list
00372                 $counter = 0;
00373                 foreach($sorted_objs as $object_id)
00374                 {
00375                         $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
00376                         #$item_list->setCurrentUser($this->tracked_user->getId());
00377                         $item_list->setCurrentUser($this->getCurrentUserId());
00378                         $item_list->readUserInfo();
00379                         $item_list->renderObjectListFO();
00380                 }
00381 
00382                 // Finally convert to fop
00383                 $this->__convert();
00384         }               
00385 
00386 
00387         function __addMain()
00388         {
00389                 global $ilUser,$ilObjDataCache;
00390 
00391                 $this->tpl->setVariable("LEARNING_PROGRESS_OF",$this->lng->txt('learning_progress'));
00392                 switch($this->getType())
00393                 {
00394                         case LP_ACTIVE_PROGRESS:
00395                                 $name = ilObjUser::_lookupName($this->getCurrentUserId());
00396                                 $this->tpl->setVariable("USER_FULLNAME",$name['lastname'].', '.$name['firstname']);
00397                                 break;
00398                 }                               
00399                 $this->tpl->setVariable("DATE",ilFormat::formatUnixTime(time(),true));
00400                 
00401                 return true;
00402         }
00403 
00404 
00405         function __convert()
00406         {
00407                 #include_once 'Services/Transformation/classes/class.ilContentObject2FO.php';
00408                 #$co2fo = new ilContentObject2FO();
00409                 #$co2fo->setXMLString($xml = $this->xml_tpl->get());
00410 
00411                 #if(!$co2fo->transform())
00412                 #{
00413                 #endInfo($this->lng->txt('trac_error_pdf',true));
00414                 #       $this->ctrl->returnToParent($this);
00415                 #}
00416 
00417                 include_once 'Services/Transformation/classes/class.ilFO2PDF.php';
00418 
00419                 $fo2pdf = new ilFO2PDF();
00420                 #echo htmlentities($this->tpl->get());
00421                 $fo2pdf->setFOString($this->tpl->get());
00422 
00423                 #var_dump("<pre>",htmlentities($fo2pdf->getFOString()),"<pre>");
00424 
00425                 $pdf_base64 = $fo2pdf->send();
00426 
00427                 if(!$pdf_base64)
00428                 {
00429                         ilUtil::sendInfo($this->lng->txt('trac_error_pdf',true));
00430                         $this->ctrl->returnToParent($this);
00431                 }
00432                 ilUtil::deliverData($pdf_base64,'learning_progress.pdf','application/pdf');
00433         }
00434 }       
00435 ?>

Generated on Fri Dec 13 2013 17:57:01 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1