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

Services/Tracking/classes/class.ilLearningProgressBaseGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00035 define("LP_MODE_PERSONAL_DESKTOP",1);
00036 define("LP_MODE_ADMINISTRATION",2);
00037 define("LP_MODE_REPOSITORY",3);
00038 define("LP_MODE_USER_FOLDER",4);
00039 
00040 define("LP_ACTIVE_SETTINGS",1);
00041 define("LP_ACTIVE_OBJECTS",2);
00042 define("LP_ACTIVE_PROGRESS",3);
00043 
00044 include_once 'Services/Tracking/classes/class.ilObjUserTracking.php';
00045 
00046 /* Base class for all Learning progress gui classes.
00047  * Defines modes for presentation according to the context in which it was called
00048  * E.g: mode LP_MODE_PERSONAL_DESKTOP displays only listOfObjects.
00049  */
00050 
00051 class ilLearningProgressBaseGUI 
00052 {
00053         var $tpl = null;
00054         var $ctrl = null;
00055         var $lng = null;
00056 
00057         var $ref_id = 0;
00058 
00059         var $mode = 0;
00060 
00061         function ilLearningProgressBaseGUI($a_mode,$a_ref_id = 0,$a_usr_id = 0)
00062         {
00063                 global $tpl,$ilCtrl,$lng,$ilObjDataCache,$ilTabs;
00064 
00065                 $this->tpl =& $tpl;
00066                 $this->ctrl =& $ilCtrl;
00067                 $this->lng =& $lng;
00068                 $this->lng->loadLanguageModule('trac');
00069                 $this->tabs_gui =& $ilTabs;
00070 
00071                 $this->mode = $a_mode;
00072                 $this->ref_id = $a_ref_id;
00073                 $this->obj_id = $ilObjDataCache->lookupObjId($this->ref_id);
00074                 $this->usr_id = $a_usr_id;
00075 
00076                 $this->anonymized = (bool) !ilObjUserTracking::_enabledUserRelatedData();
00077         }
00078 
00079         function isAnonymized()
00080         {
00081                 return $this->anonymized;
00082         }
00083         
00084         function getMode()
00085         {
00086                 return $this->mode;
00087         }
00088 
00089         function getRefId()
00090         {
00091                 return $this->ref_id;
00092         }
00093 
00094         function getObjId()
00095         {
00096                 return $this->obj_id;
00097         }
00098 
00099         function getUserId()
00100         {
00101                 if($this->usr_id)
00102                 {
00103                         return $this->usr_id;
00104                 }
00105                 if((int) $_GET['user_id'])
00106                 {
00107                         return (int) $_GET['user_id'];
00108                 }
00109                 return 0;
00110         }
00111 
00112         // Protected
00113         function __getDefaultCommand()
00114         {
00115                 if(strlen($cmd = $this->ctrl->getCmd()))
00116                 {
00117                         return $cmd;
00118                 }
00119                 return 'show';
00120         }
00121 
00122         function __setSubTabs($a_active)
00123         {
00124                 global $rbacsystem,$ilObjDataCache;
00125 
00126 
00127                 
00128                 switch($this->getMode())
00129                 {
00130                         case LP_MODE_PERSONAL_DESKTOP:
00131 
00132                                 $this->tabs_gui->addSubTabTarget('trac_progress',
00133                                                                                                  $this->ctrl->getLinkTargetByClass('illplistofprogressgui',''),
00134                                                                                                  "","","",$a_active == LP_ACTIVE_PROGRESS);
00135                                 $this->tabs_gui->addSubTabTarget('trac_objects',
00136                                                                                                  $this->ctrl->getLinkTargetByClass("illplistofobjectsgui",''),
00137                                                                                                  "","","",$a_active == LP_ACTIVE_OBJECTS);
00138                                 break;
00139 
00140 
00141                         case LP_MODE_REPOSITORY:
00142 
00143                                 if($rbacsystem->checkAccess('edit_learning_progress',$this->getRefId()))
00144                                 {
00145                                         $this->ctrl->setParameterByClass('illplistofprogressgui','user_id',$this->getUserId());
00146                                         $this->tabs_gui->addSubTabTarget('trac_progress',
00147                                                                                            $this->ctrl->getLinkTargetByClass('illplistofprogressgui',''),
00148                                                                                            "","","",$a_active == LP_ACTIVE_PROGRESS);
00149                                         if(!$this->isAnonymized())
00150                                         {
00151                                                 // Check if it is a course
00152                                                 $sub_tab = ($ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($this->getRefId())) == 'crs') ?
00153                                                         'trac_crs_objects' :
00154                                                         'trac_objects';
00155 
00156                                                 $this->tabs_gui->addSubTabTarget($sub_tab,
00157                                                                                                                  $this->ctrl->getLinkTargetByClass("illplistofobjectsgui",''),
00158                                                                                                                  "","","",$a_active == LP_ACTIVE_OBJECTS);
00159                                         }
00160                                         $this->tabs_gui->addSubTabTarget('trac_settings',
00161                                                                                                          $this->ctrl->getLinkTargetByClass('illplistofsettingsgui',''),
00162                                                                                                          "","","",$a_active == LP_ACTIVE_SETTINGS);
00163                                 }
00164                                 break;
00165 
00166                         case LP_MODE_ADMINISTRATION:
00167                                 
00168                                 $this->tabs_gui->addSubTabTarget('trac_progress',
00169                                                                          $this->ctrl->getLinkTargetByClass('illplistofprogressgui',''),
00170                                                                          "","","",$a_active == LP_ACTIVE_PROGRESS);
00171                                 $this->tabs_gui->addSubTabTarget('trac_objects',
00172                                                                          $this->ctrl->getLinkTargetByClass("illplistofobjectsgui",''),
00173                                                                          "","","",$a_active == LP_ACTIVE_OBJECTS);
00174                                 break;
00175 
00176                         case LP_MODE_USER_FOLDER:
00177                                 
00178                                 // No tabs default class is lpprogressgui
00179                                 break;
00180 
00181                         default:
00182                                 die ('No valid mode given');
00183                                 break;
00184                 }
00185 
00186                 return true;
00187         }
00188 
00189         function __buildFooter()
00190         {
00191                 switch($this->getMode())
00192                 {
00193                         case LP_MODE_PERSONAL_DESKTOP:
00194 
00195                                 $this->tpl->show(true);
00196                 }
00197         }
00198 
00199         function __buildHeader()
00200         {
00201                 if($this->getMode() == LP_MODE_PERSONAL_DESKTOP)
00202                 {
00203                         $this->tpl->setCurrentBlock("header_image");
00204                         $this->tpl->setVariable("IMG_HEADER", ilUtil::getImagePath("icon_pd_b.gif"));
00205                         $this->tpl->parseCurrentBlock();
00206                         $this->tpl->setVariable("HEADER",$this->lng->txt("personal_desktop"));
00207                         
00208                         // set locator
00209                         $this->tpl->setVariable("TXT_LOCATOR", $this->lng->txt("locator"));
00210                         $this->tpl->touchBlock("locator_separator");
00211                         $this->tpl->setCurrentBlock("locator_item");
00212                         $this->tpl->setVariable("ITEM", $this->lng->txt("personal_desktop"));
00213                         $this->tpl->setVariable("LINK_ITEM",
00214                                                                         $this->ctrl->getLinkTargetByClass("ilpersonaldesktopgui"));
00215                         $this->tpl->parseCurrentBlock();
00216                         
00217                         $this->tpl->setCurrentBlock("locator_item");
00218                         $this->tpl->setVariable("ITEM", $this->lng->txt("learning_progress"));
00219                         $this->tpl->setVariable("LINK_ITEM",
00220                                                                         $this->ctrl->getLinkTargetByClass('illearningprogressgui'));
00221                         $this->tpl->parseCurrentBlock();
00222                 
00223                         // catch feedback message
00224                         sendInfo();
00225                         // display infopanel if something happened
00226                         infoPanel();
00227                 }
00228 
00229         }
00230 
00234         function __insertPath(&$a_tpl,$a_ref_id)
00235         {
00236                 global $tree;
00237 
00238                 $path_arr = $tree->getPathFull($a_ref_id);
00239                 $counter = 0;
00240                 foreach($tree->getPathFull($a_ref_id) as $data)
00241                 {
00242                         if($counter++)
00243                         {
00244                                 $path .= " -> ";
00245                         }
00246                         $path .= $data['title'];
00247                 }
00248                 $a_tpl->setCurrentBlock("path_item");
00249                 $a_tpl->setVariable("PATH_ITEM",$path);
00250                 $a_tpl->parseCurrentBlock();
00251 
00252                 $a_tpl->setCurrentBlock("path");
00253                 $a_tpl->parseCurrentBlock();
00254 
00255                 return $path;
00256         }
00257 
00258         function __showImageByStatus(&$tpl,$a_status,$tpl_prefix = "")
00259         {
00260                 switch($a_status)
00261                 {
00262                         case LP_STATUS_IN_PROGRESS:
00263                                 $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/incomplete.gif'));
00264                                 $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
00265                                 break;
00266 
00267                         case LP_STATUS_COMPLETED:
00268                                 $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/complete.gif'));
00269                                 $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
00270                                 break;
00271                         
00272                         case LP_STATUS_NOT_ATTEMPTED:
00273                                 $tpl->setVariable($tpl_prefix."STATUS_IMG",ilUtil::getImagePath('scorm/not_attempted.gif'));
00274                                 $tpl->setVariable($tpl_prefix."STATUS_ALT",$this->lng->txt($a_status));
00275                                 break;
00276                 }
00277                 return true;
00278         }
00279 
00280 
00281         // Protected Table gui methods
00282         function &__initTableGUI()
00283         {
00284                 include_once "./classes/class.ilTableGUI.php";
00285 
00286                 return new ilTableGUI(0,false);
00287         }
00288 
00289 
00293         function __showObjectDetails(&$info,$item_id = 0)
00294         {
00295                 global $ilObjDataCache;
00296 
00297                 $details_id = $item_id ? $item_id : $this->details_id;
00298 
00299 
00300                 // Section object details
00301                 $info->addSection($this->lng->txt('details'));
00302                 $info->addProperty($this->lng->txt('title'),$ilObjDataCache->lookupTitle($details_id));
00303                 if(strlen($desc = $ilObjDataCache->lookupDescription($details_id)))
00304                 {
00305                         $info->addProperty($this->lng->txt('description'),$desc);
00306                 }
00307                 $info->addProperty($this->lng->txt('trac_mode'),ilLPObjSettings::_mode2Text(ilLPObjSettings::_lookupMode($details_id)));
00308 
00309                 if(ilLPObjSettings::_lookupMode($details_id) == LP_MODE_VISITS)
00310                 {
00311                         $info->addProperty($this->lng->txt('trac_required_visits'),ilLPObjSettings::_lookupVisits($details_id));
00312                 }
00313                 
00314                 include_once './Services/MetaData/classes/class.ilMDEducational.php';
00315                 if($seconds = ilMDEducational::_getTypicalLearningTimeSeconds($details_id))
00316                 {
00317                         $info->addProperty($this->lng->txt('meta_typical_learning_time'),ilFormat::_secondsToString($seconds));
00318                 }
00319         }
00320 
00321         function __appendLPDetails(&$info,$item_id,$user_id)
00322         {
00323                 global $ilObjDataCache;
00324 
00325                 $type = $ilObjDataCache->lookupType($item_id);
00326                 
00327                 // Section learning_progress
00328                 $info->addSection($this->lng->txt('trac_learning_progress'));
00329         
00330                 switch($type)
00331                 {
00332                         case 'lm':
00333                                 include_once 'Services/Tracking/classes/class.ilLearningProgress.php';
00334                                 $progress = ilLearningProgress::_getProgress($user_id,$item_id);
00335                         
00336                                 if($progress['access_time'])
00337                                 {
00338                                         $info->addProperty($this->lng->txt('last_access'),date('Y-m-d H:i:s',$progress['access_time']));
00339                                 }
00340                                 else
00341                                 {
00342                                         $info->addProperty($this->lng->txt('last_access'),$this->lng->txt('trac_not_accessed'));
00343                                 }
00344                                 $info->addProperty($this->lng->txt('trac_visits'),(int) $progress['visits']);
00345                                 $info->addProperty($this->lng->txt('trac_spent_time'),ilFormat::_secondsToString($progress['spent_time']));
00346                                 $info->addProperty($this->lng->txt('trac_status'),$this->lng->txt($this->__readStatus($item_id,$user_id)));
00347                                 break;
00348 
00349                         case 'tst':
00350                         case 'crs':
00351                         case 'sahs':
00352                                 $info->addProperty($this->lng->txt('trac_status'),$this->lng->txt($this->__readStatus($item_id,$user_id)));
00353                                 break;
00354 
00355                 }
00356 
00357                 include_once 'Services/Tracking/classes/class.ilLPMarks.php';
00358                 if(strlen($mark = ilLPMarks::_lookupMark($user_id,$item_id)))
00359                 {
00360                         $info->addProperty($this->lng->txt('trac_mark'),$mark);
00361                 }
00362                 if(strlen($comment = ilLPMarks::_lookupComment($user_id,$item_id)))
00363                 {
00364                         $info->addProperty($this->lng->txt('trac_comment'),$comment);
00365                 }
00366         }
00367 
00368         function __readStatus($a_obj_id,$user_id)
00369         {
00370                 include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
00371 
00372                 if(in_array($user_id,ilLPStatusWrapper::_getInProgress($a_obj_id)))
00373                 {
00374                         return $status = LP_STATUS_IN_PROGRESS;
00375                 }
00376                 elseif(in_array($user_id,ilLPStatusWrapper::_getCompleted($a_obj_id)))
00377                 {
00378                         return $status = LP_STATUS_COMPLETED;
00379                 }
00380                 else
00381                 {
00382                         return $status = LP_STATUS_NOT_ATTEMPTED;
00383                 }
00384         }
00385 
00386         function __showButton($a_link,$a_text,$a_target = '')
00387         {
00388                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00389 
00390                 // display button
00391                 $this->tpl->setCurrentBlock("btn_cell");
00392                 $this->tpl->setVariable("BTN_LINK",$a_link);
00393                 $this->tpl->setVariable("BTN_TXT",$a_text);
00394                 if($a_target)
00395                 {
00396                         $this->tpl->setVariable("BTN_TARGET",$a_target);
00397                 }
00398 
00399                 $this->tpl->parseCurrentBlock();
00400         }
00401 
00402 
00415         function __sort($a_ids,$a_table,$a_field,$a_id_name)
00416         {
00417                 global $ilDB;
00418 
00419                 if(!$a_ids)
00420                 {
00421                         return array();
00422                 }
00423 
00424                 // use database to sort user array
00425                 $where = "WHERE ".$a_id_name." IN ('";
00426                 $where .= implode("','",$a_ids);
00427                 $where .= "') ";
00428 
00429                 $query = "SELECT ".$a_id_name." FROM ".$a_table." ".
00430                         $where.
00431                         "ORDER BY ".$a_field;
00432 
00433                 $res = $ilDB->query($query);
00434                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00435                 {
00436                         $ids[] = $row->$a_id_name;
00437                 }
00438                 return $ids ? $ids : array();
00439         }
00440 
00441         function __getPercent($max,$reached)
00442         {
00443                 if(!$max)
00444                 {
00445                         return "0%";
00446                 }
00447 
00448                 return sprintf("%.2f%%",$reached / $max * 100);
00449         }
00450 
00451         function __readItemStatusInfo($a_items)
00452         {
00453                 global $ilObjDataCache;
00454 
00455                 foreach($a_items as $item_id)
00456                 {
00457                         $this->obj_data[$item_id]['mode'] = ilLPObjSettings::_lookupMode($item_id);
00458                         $this->obj_data[$item_id]['type'] = $ilObjDataCache->lookupType($item_id);
00459                         if($this->obj_data[$item_id]['mode'] == LP_MODE_TLT)
00460                         {
00461                                 include_once './Services/MetaData/classes/class.ilMDEducational.php';
00462                                 $this->obj_data[$item_id]['tlt'] = ilMDEducational::_getTypicalLearningTimeSeconds($item_id);
00463                         }
00464                         if($this->obj_data[$item_id]['mode'] == LP_MODE_VISITS)
00465                         {
00466                                 include_once './Services/Tracking/classes/class.ilLPObjSettings.php';
00467                                 $this->obj_data[$item_id]['visits'] = ilLPObjSettings::_lookupVisits($item_id);
00468                         }
00469                         if($this->obj_data[$item_id]['mode'] == LP_MODE_SCORM)
00470                         {
00471                                 include_once './Services/Tracking/classes/class.ilLPCollections.php';
00472                                 $this->obj_data[$item_id]['scos'] = count(ilLPCollections::_getItems($item_id));
00473                         }
00474                 }
00475         }
00476 
00477 
00478         function __getStatusInfo($a_obj_id,$a_user_id)
00479         {
00480                 switch($this->obj_data[$a_obj_id]['mode'])
00481                 {
00482                         case LP_MODE_TEST_PASSED:
00483                                 // Get stored test results
00484                                 include_once './Services/Tracking/classes/class.ilTestResultCache.php';
00485                                 $test_res_cache =& ilTestResultCache::_getInstance();
00486                                 $result = $test_res_cache->get($a_obj_id);
00487 
00488                                 foreach($result as $res)
00489                                 {
00490                                         if($a_user_id == $res['user_id'])
00491                                         {
00492                                                 return array($this->lng->txt('trac_reached_points'),
00493                                                                          $this->__getPercent($res['max_points'],$res['reached_points']));
00494                                         }
00495                                 }
00496                                         return array($this->lng->txt('trac_reached_points'),
00497                                                                  "0.00%");
00498                                                                  
00499                         case LP_MODE_TLT:
00500                                 if(!$this->obj_data[$a_obj_id]['tlt'])
00501                                 {
00502                                         return false;
00503                                 }
00504                                 include_once './Services/Tracking/classes/class.ilLearningProgress.php';
00505                                 $user_data = ilLearningProgress::_getProgress($a_user_id,$a_obj_id);
00506 
00507                                 return array($this->lng->txt('trac_edit_time'),
00508                                                          $this->__getPercent($this->obj_data[$a_obj_id]['tlt'],$user_data['spent_time']));
00509 
00510                         case LP_MODE_VISITS:
00511                                 if(!$this->obj_data[$a_obj_id]['visits'])
00512                                 {
00513                                         return false;
00514                                 }
00515                                 $user_data = ilLearningProgress::_getProgress($a_user_id,$a_obj_id);
00516 
00517                                 return array($this->lng->txt('trac_reached_visits'),
00518                                                          $this->__getPercent($this->obj_data[$a_obj_id]['visits'],$user_data['visits']));
00519 
00520                         case LP_MODE_SCORM:
00521                                 if(!$this->obj_data[$a_obj_id]['scos'])
00522                                 {
00523                                         return false;
00524                                 }
00525                                 $scorm_data = $this->__readScormCompleted($a_obj_id);
00526                                 return array($this->lng->txt('trac_edited_scos'),
00527                                                          $this->__getPercent($this->obj_data[$a_obj_id]['scos'],$scorm_data[$a_user_id]));
00528                 }
00529         }
00530 
00531         function __readScormCompleted($a_obj_id)
00532         {
00533                 if(is_array($this->scorm_data[$a_obj_id]))
00534                 {
00535                         return $this->scorm_data[$a_obj_id];
00536                 }
00537 
00538                 include_once './content/classes/SCORM/class.ilObjSCORMTracking.php';
00539                 include_once './Services/Tracking/classes/class.ilLPCollections.php';
00540 
00541                 $this->scorm_data[$a_obj_id] = ilObjSCORMTracking::_getCountCompletedPerUser(ilLPCollections::_getItems($a_obj_id),$a_obj_id);
00542                 return $this->scorm_data[$a_obj_id];
00543         }       
00544 }
00545 ?>

Generated on Fri Dec 13 2013 11:57:59 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1