00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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 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 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
00151 $header = $this->lng->txt('learning_progress').': '.ilFormat::formatUnixTime(time(),true);
00152 $this->writer->xmlElement('Header',null,$header);
00153
00154
00155 $this->writer->xmlElement('Footer',null,'powered by ILIAS');
00156
00157
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
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
00209 $this->writer->xmlStartTag('Items');
00210 $this->writer->xmlStartTag('ItemHeader');
00211 $this->writer->xmlElement('HeaderTitle',null,$this->lng->txt('trac_objects'));
00212
00213
00214 include_once '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
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;
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 $this->writer->xmlStartTag('Item');
00268 switch($item_list->getMode())
00269 {
00270 case LP_MODE_OBJECTIVES:
00271 $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,'objective',$level + 2);
00272 break;
00273
00274 case LP_MODE_SCORM:
00275 $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,'sahs_item',$level + 2);
00276 break;
00277
00278 default:
00279 $this->__renderContainerRow($a_item_id,$child_id,$a_usr_id,
00280 $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($child_id)),$level + 2);
00281 break;
00282 }
00283 $this->writer->xmlEndTag('Item');
00284 }
00285 }
00286
00287 function __toFO()
00288 {
00289 include_once 'Services/Transformation/classes/class.ilXML2FO.php';
00290
00291 $xml2FO = new ilXML2FO();
00292 $xml2FO->setXSLTLocation($this->tpl->getTemplatePath('learning_progress_fo.xsl','Services/Tracking'));
00293 $xml2FO->setXMLString($this->writer->xmlDumpMem());
00294 $xml2FO->transform();
00295
00296 $this->fo_string = $xml2FO->getFOString();
00297 #var_dump("<pre>",htmlentities($this->fo_string),"<pre>");
00298 return true;
00299 }
00300
00301 function __toPDF()
00302 {
00303 include_once 'Services/Transformation/classes/class.ilFO2PDF.php';
00304
00305 $fo2pdf = new ilFO2PDF();
00306 $fo2pdf->setFOString($this->fo_string);
00307 $pdf_base64 = $fo2pdf->send();
00308
00309 if(!$pdf_base64)
00310 {
00311 sendInfo($this->lng->txt('trac_error_pdf',true));
00312 $this->ctrl->returnToParent($this);
00313 }
00314 ilUtil::deliverData($pdf_base64,'learning_progress.pdf','application/pdf');
00315 }
00316
00317 function __createPersonalProgressList()
00318 {
00319 global $ilObjDataCache,$ilUser;
00320
00321
00322 $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
00323 $this->__addMain();
00324
00325 $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
00326 $this->filter->setRequiredPermission('read');
00327 $type = $this->filter->getFilterType();
00328 $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
00329
00330
00331 $objs = $this->filter->getObjects();
00332 $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
00333
00334 $counter = 0;
00335 foreach($sorted_objs as $object_id)
00336 {
00337 $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
00338 $item_list->setCurrentUser($this->getCurrentUserId());
00339 $item_list->readUserInfo();
00340 $item_list->renderSimpleProgressFO();
00341 }
00342
00343
00344 $this->__convert();
00345 }
00346
00347 function __createObjectList()
00348 {
00349 global $ilObjDataCache,$ilUser;
00350
00351
00352 $this->tpl = new ilTemplate('tpl.lp_pdf_list.xml',true,true,'Services/Tracking');
00353 $this->__addMain();
00354
00355 $this->tpl->setVariable("FILTER",$this->filter_gui->getFO());
00356 $this->filter->setRequiredPermission('read');
00357 $type = $this->filter->getFilterType();
00358 $this->tpl->setVariable("TXT_OBJS",$this->lng->txt('objs_'.$type));
00359
00360
00361 $objs = $this->filter->getObjects();
00362 $sorted_objs = $this->__sort(array_keys($objs),'object_data','title','obj_id');
00363
00364 $counter = 0;
00365 foreach($sorted_objs as $object_id)
00366 {
00367 $item_list =& ilLPItemListFactory::_getInstance(0,$object_id,$ilObjDataCache->lookupType($object_id));
00368 #$item_list->setCurrentUser($this->tracked_user->getId());
00369 $item_list->setCurrentUser($this->getCurrentUserId());
00370 $item_list->readUserInfo();
00371 $item_list->renderObjectListFO();
00372 }
00373
00374
00375 $this->__convert();
00376 }
00377
00378
00379 function __addMain()
00380 {
00381 global $ilUser,$ilObjDataCache;
00382
00383 $this->tpl->setVariable("LEARNING_PROGRESS_OF",$this->lng->txt('learning_progress'));
00384 switch($this->getType())
00385 {
00386 case LP_ACTIVE_PROGRESS:
00387 $name = ilObjUser::_lookupName($this->getCurrentUserId());
00388 $this->tpl->setVariable("USER_FULLNAME",$name['lastname'].', '.$name['firstname']);
00389 break;
00390 }
00391 $this->tpl->setVariable("DATE",ilFormat::formatUnixTime(time(),true));
00392
00393 return true;
00394 }
00395
00396
00397 function __convert()
00398 {
00399 #include_once 'Services/Transformation/classes/class.ilContentObject2FO.php';
00400 #$co2fo = new ilContentObject2FO();
00401 #$co2fo->setXMLString($xml = $this->xml_tpl->get());
00402
00403 #if(!$co2fo->transform())
00404 #{
00405 #endInfo($this->lng->txt('trac_error_pdf',true));
00406 # $this->ctrl->returnToParent($this);
00407 #}
00408
00409 include_once 'Services/Transformation/classes/class.ilFO2PDF.php';
00410
00411 $fo2pdf = new ilFO2PDF();
00412 #echo htmlentities($this->tpl->get());
00413 $fo2pdf->setFOString($this->tpl->get());
00414
00415 #var_dump("<pre>",htmlentities($fo2pdf->getFOString()),"<pre>");
00416
00417 $pdf_base64 = $fo2pdf->send();
00418
00419 if(!$pdf_base64)
00420 {
00421 sendInfo($this->lng->txt('trac_error_pdf',true));
00422 $this->ctrl->returnToParent($this);
00423 }
00424 ilUtil::deliverData($pdf_base64,'learning_progress.pdf','application/pdf');
00425 }
00426 }
00427 ?>