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

Generated on Fri Dec 13 2013 13:52:12 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1