ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilLMTracker Class Reference

Track access to ILIAS learning modules. More...

+ Collaboration diagram for ilLMTracker:

Public Member Functions

 trackAccess ($a_page_id)
 Track access to lm page. More...
 
 trackLastPageAccess ($usr_id, $lm_id, $obj_id)
 Track last accessed page for a learning module. More...
 
 setCurrentPage ($a_val)
 Set current page. More...
 
 getCurrentPage ()
 Get current page. More...
 
 getAllQuestionsCorrect ()
 Have all questoins been answered correctly (and questions exist)? More...
 
 getIconForLMObject ($a_node, $a_highlighted_node=0)
 Get icon for lm object. More...
 
 hasPredIncorrectAnswers ($a_obj_id, $a_ignore_unlock=false)
 Has predecessing incorrect answers. More...
 
 getBlockedUsersInformation ()
 Get blocked users information. More...
 

Static Public Member Functions

static getInstance ($a_ref_id, $a_user_id=0)
 Get instance. More...
 
static getInstanceByObjId ($a_obj_id, $a_user_id=0)
 Get instance. More...
 
static _isNodeVisible ($a_node)
 Is node visible for the learner. More...
 

Data Fields

const NOT_ATTEMPTED = 0
 
const IN_PROGRESS = 1
 
const COMPLETED = 2
 
const FAILED = 3
 
const CURRENT = 99
 

Static Public Attributes

static $instances = array()
 
static $instancesbyobj = array()
 

Protected Member Functions

 trackPageAndChapterAccess ($a_page_id)
 Track page and chapter access. More...
 
 loadLMTrackingData ()
 Load LM tracking data. More...
 
 determineProgressStatus ($a_obj_id, &$a_has_pred_incorrect_answers, &$a_has_pred_incorrect_not_unlocked_answers)
 Determine progress status of nodes. More...
 

Protected Attributes

 $lm_ref_id
 
 $lm_obj_id
 
 $lm_tree
 
 $lm_obj_ids = array()
 
 $tree_arr = array()
 
 $re_arr = array()
 
 $loaded_for_node = false
 
 $dirty = false
 
 $page_questions = array()
 
 $all_questions = array()
 
 $answer_status = array()
 
 $has_incorrect_answers = false
 
 $current_page_id = 0
 

Private Member Functions

 __construct ($a_id, $a_by_obj_id=false, $a_user_id)
 Constructor. More...
 

Detailed Description

Track access to ILIAS learning modules.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 of file class.ilLMTracker.php.

Constructor & Destructor Documentation

◆ __construct()

ilLMTracker::__construct (   $a_id,
  $a_by_obj_id = false,
  $a_user_id 
)
private

Constructor.

Parameters
ilObjLearningModule$a_lmlearning module

Definition at line 46 of file class.ilLMTracker.php.

References ilObject\_lookupObjId(), and ilLMTree\getInstance().

47  {
48  $this->user_id = $a_user_id;
49 
50  if ($a_by_obj_id)
51  {
52  $this->lm_ref_id = 0;
53  $this->lm_obj_id = $a_id;
54  }
55  else
56  {
57  $this->lm_ref_id = $a_id;
58  $this->lm_obj_id = ilObject::_lookupObjId($a_id);
59  }
60 
61  include_once("./Modules/LearningModule/classes/class.ilLMTree.php");
62  $this->lm_tree = ilLMTree::getInstance($this->lm_obj_id);
63  }
static _lookupObjId($a_id)
static getInstance($a_tree_id)
Get Instance.
+ Here is the call graph for this function:

Member Function Documentation

◆ _isNodeVisible()

static ilLMTracker::_isNodeVisible (   $a_node)
static

Is node visible for the learner.

Parameters
mixed$a_nodenode object/array
Returns
boolean node visible true/false

Definition at line 653 of file class.ilLMTracker.php.

References $lm_set, ilPageObject\_lookupActivationData(), ilPageObject\_lookupActive(), and ilUtil\now().

Referenced by ilLMTOCExplorerGUI\isNodeVisible().

654  {
655  include_once("./Services/COPage/classes/class.ilPageObject.php");
656 
657  if ($a_node["type"] != "pg")
658  {
659  return true;
660  }
661 
662  $lm_set = new ilSetting("lm");
663  $active = ilPageObject::_lookupActive($a_node["child"], "lm",
664  $lm_set->get("time_scheduled_page_activation"));
665 
666  if(!$active)
667  {
668  $act_data = ilPageObject::_lookupActivationData((int) $a_node["child"], "lm");
669  if ($act_data["show_activation_info"] &&
670  (ilUtil::now() < $act_data["activation_start"]))
671  {
672  return true;
673  }
674  else
675  {
676  return false;
677  }
678  }
679  else
680  {
681  return true;
682  }
683  }
ILIAS Setting Class.
static now()
Return current timestamp in Y-m-d H:i:s format.
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
static _lookupActivationData($a_id, $a_parent_type, $a_lang="-")
Lookup activation data.
$lm_set
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ determineProgressStatus()

ilLMTracker::determineProgressStatus (   $a_obj_id,
$a_has_pred_incorrect_answers,
$a_has_pred_incorrect_not_unlocked_answers 
)
protected

Determine progress status of nodes.

Parameters
int$a_obj_idlm object id
Returns
int status

Definition at line 408 of file class.ilLMTracker.php.

References COMPLETED, CURRENT, FAILED, getCurrentPage(), IN_PROGRESS, NOT_ATTEMPTED, and ilUtil\sortArray().

Referenced by loadLMTrackingData().

409  {
410  $status = ilLMTracker::NOT_ATTEMPTED;
411 
412  if (isset($this->tree_arr["nodes"][$a_obj_id]))
413  {
414  $this->tree_arr["nodes"][$a_obj_id]["has_pred_incorrect_answers"] = $a_has_pred_incorrect_answers;
415  $this->tree_arr["nodes"][$a_obj_id]["has_pred_incorrect_not_unlocked_answers"] = $a_has_pred_incorrect_not_unlocked_answers;
416 
417  if (is_array($this->tree_arr["childs"][$a_obj_id]))
418  {
419  // sort childs in correct order
420  $this->tree_arr["childs"][$a_obj_id] = ilUtil::sortArray($this->tree_arr["childs"][$a_obj_id], "lft", "asc", true);
421 
422  $cnt_completed = 0;
423  foreach ($this->tree_arr["childs"][$a_obj_id] as $c)
424  {
425  // if child is not activated/displayed count child as implicitly completed
426  // rationale: everything that is visible for the learner determines the status
427  // see also bug #14642
428  if (!self::_isNodeVisible($c))
429  {
430  $cnt_completed++;
431  continue;
432  }
433  $c_stat = $this->determineProgressStatus($c["child"], $a_has_pred_incorrect_answers,
434  $a_has_pred_incorrect_not_unlocked_answers);
435  if ($status != ilLMTracker::FAILED)
436  {
437  if ($c_stat == ilLMTracker::FAILED)
438  {
439  $status = ilLMTracker::IN_PROGRESS;
440  }
441  else if ($c_stat == ilLMTracker::IN_PROGRESS)
442  {
443  $status = ilLMTracker::IN_PROGRESS;
444  }
445  else if ($c_stat == ilLMTracker::COMPLETED || $c_stat == ilLMTracker::CURRENT)
446  {
447  $status = ilLMTracker::IN_PROGRESS;
448  $cnt_completed++;
449  }
450  }
451  // if an item is failed or in progress or (not attempted and contains questions)
452  // the next item has predecessing incorrect answers
453  if ($this->tree_arr["nodes"][$c["child"]]["type"] == "pg")
454  {
455  if ($c_stat == ilLMTracker::FAILED || $c_stat == ilLMTracker::IN_PROGRESS ||
456  ($c_stat == ilLMTracker::NOT_ATTEMPTED && is_array($this->page_questions[$c["child"]]) && count($this->page_questions[$c["child"]]) > 0))
457  {
458  $a_has_pred_incorrect_answers = true;
459  if (!$this->tree_arr["nodes"][$c["child"]]["unlocked"])
460  {
461  $a_has_pred_incorrect_not_unlocked_answers = true;
462  }
463  }
464  }
465  }
466  if ($cnt_completed == count($this->tree_arr["childs"][$a_obj_id]))
467  {
468  $status = ilLMTracker::COMPLETED;
469  }
470  }
471  else if ($this->tree_arr["nodes"][$a_obj_id]["type"] == "pg")
472  {
473  // check read event data
474  if (isset($this->re_arr[$a_obj_id]) && $this->re_arr[$a_obj_id]["read_count"] > 0)
475  {
476  $status = ilLMTracker::COMPLETED;
477  }
478  else if ($a_obj_id == $this->getCurrentPage())
479  {
480  $status = ilLMTracker::CURRENT;
481  }
482 
483  $unlocked = false;
484  if (is_array($this->page_questions[$a_obj_id]))
485  {
486  // check questions, if one is failed -> failed
487  $unlocked = true;
488  foreach ($this->page_questions[$a_obj_id] as $q_id)
489  {
490  if (is_array($this->answer_status[$q_id])
491  && $this->answer_status[$q_id]["try"] > 0
492  && !$this->answer_status[$q_id]["passed"])
493  {
494  $status = ilLMTracker::FAILED;
495  if (!$this->answer_status[$q_id]["unlocked"])
496  {
497  $unlocked = false;
498  }
499  }
500  }
501 
502  // check questions, if one is not answered -> in progress
503  if ($status != ilLMTracker::FAILED)
504  {
505  foreach ($this->page_questions[$a_obj_id] as $q_id)
506  {
507  if (!is_array($this->answer_status[$q_id])
508  || $this->answer_status[$q_id]["try"] == 0)
509  {
510  if ($status != ilLMTracker::NOT_ATTEMPTED)
511  {
512  $status = ilLMTracker::IN_PROGRESS;
513  }
514  }
515  }
516  $unlocked = false;
517  }
518  }
519  $this->tree_arr["nodes"][$a_obj_id]["unlocked"] = $unlocked;
520  $this->tree_arr["nodes"][$a_obj_id]["has_pred_incorrect_answers"] = $a_has_pred_incorrect_answers;
521  $this->tree_arr["nodes"][$a_obj_id]["has_pred_incorrect_not_unlocked_answers"] = $a_has_pred_incorrect_not_unlocked_answers;
522  }
523  }
524  else // free pages (currently not called, since only walking through tree structure)
525  {
526 
527  }
528  $this->tree_arr["nodes"][$a_obj_id]["status"] = $status;
529 
530  return $status;
531  }
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
getCurrentPage()
Get current page.
determineProgressStatus($a_obj_id, &$a_has_pred_incorrect_answers, &$a_has_pred_incorrect_not_unlocked_answers)
Determine progress status of nodes.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAllQuestionsCorrect()

ilLMTracker::getAllQuestionsCorrect ( )

Have all questoins been answered correctly (and questions exist)?

Returns
bool true, if learning module contains any question and all questions (in the chapter structure) have been answered correctly

Definition at line 391 of file class.ilLMTracker.php.

References loadLMTrackingData().

392  {
393  $this->loadLMTrackingData();
394  if (count($this->all_questions) > 0 && !$this->has_incorrect_answers)
395  {
396  return true;
397  }
398  return false;
399  }
loadLMTrackingData()
Load LM tracking data.
+ Here is the call graph for this function:

◆ getBlockedUsersInformation()

ilLMTracker::getBlockedUsersInformation ( )

Get blocked users information.

Parameters

Definition at line 599 of file class.ilLMTracker.php.

References $ilDB, $ilUser, $lng, ilObjUser\_lookupName(), ilLMObject\_lookupTitle(), array, ilPageQuestionProcessor\getAnswerStatus(), and ilLMPageObject\queryQuestionsOfLearningModule().

600  {
601  global $ilDB, $lng, $ilPluginAdmin, $ilUser;
602 
603  $blocked_users = array();
604 
605  // load question/pages information
606  $this->page_questions = array();
607  $this->all_questions = array();
608  $page_for_question = array();
609  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
610  $q = ilLMPageObject::queryQuestionsOfLearningModule($this->lm_obj_id, "", "", 0, 0);
611  foreach ($q["set"] as $quest)
612  {
613  $this->page_questions[$quest["page_id"]][] = $quest["question_id"];
614  $this->all_questions[] = $quest["question_id"];
615  $page_for_question[$quest["question_id"]] = $quest["page_id"];
616  }
617  // get question information
618  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionList.php");
619  $qlist = new ilAssQuestionList($ilDB, $lng, $ilPluginAdmin);
620  $qlist->setParentObjId(0);
621  $qlist->setJoinObjectData(false);
622  $qlist->addFieldFilter("question_id", $this->all_questions);
623  $qlist->load();
624  $qdata = $qlist->getQuestionDataArray();
625 
626  // load question answer information
627  include_once("./Services/COPage/classes/class.ilPageQuestionProcessor.php");
628  $this->answer_status = ilPageQuestionProcessor::getAnswerStatus($this->all_questions);
629  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
630  foreach ($this->answer_status as $as)
631  {
632  if ($as["try"] >= $qdata[$as["qst_id"]]["nr_of_tries"] && $qdata[$as["qst_id"]]["nr_of_tries"] > 0 && !$as["passed"])
633  {
634  //var_dump($qdata[$as["qst_id"]]);
635  $name = ilObjUser::_lookupName($as["user_id"]);
636  $as["user_name"] = $name["lastname"].", ".$name["firstname"]." [".$name["login"]."]";
637  $as["question_text"] = $qdata[$as["qst_id"]]["question_text"];
638  $as["page_id"] = $page_for_question[$as["qst_id"]];
639  $as["page_title"] = ilLMPageObject::_lookupTitle($as["page_id"]);
640  $blocked_users[] = $as;
641  }
642  }
643 
644  return $blocked_users;
645  }
static _lookupName($a_user_id)
lookup user name
static queryQuestionsOfLearningModule($a_lm_id, $a_order_field, $a_order_dir, $a_offset, $a_limit)
Get questions of learning module.
static _lookupTitle($a_obj_id)
Lookup title.
static getAnswerStatus($a_q_id, $a_user_id=0)
Get statistics for question.
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
global $ilDB
+ Here is the call graph for this function:

◆ getCurrentPage()

ilLMTracker::getCurrentPage ( )

Get current page.

Returns
id current page id

Definition at line 311 of file class.ilLMTracker.php.

References $current_page_id.

Referenced by determineProgressStatus(), and loadLMTrackingData().

312  {
313  return $this->current_page_id;
314  }
+ Here is the caller graph for this function:

◆ getIconForLMObject()

ilLMTracker::getIconForLMObject (   $a_node,
  $a_highlighted_node = 0 
)

Get icon for lm object.

Parameters
array$a_nodenode array
int$a_highlighted_nodecurrent node id
Returns
string image path

Definition at line 541 of file class.ilLMTracker.php.

References COMPLETED, FAILED, ilUtil\getImagePath(), IN_PROGRESS, and loadLMTrackingData().

542  {
543  $this->loadLMTrackingData();
544  if ($a_node["child"] == $a_highlighted_node)
545  {
546  return ilUtil::getImagePath('scorm/running.svg');
547  }
548  if (isset($this->tree_arr["nodes"][$a_node["child"]]))
549  {
550  switch ($this->tree_arr["nodes"][$a_node["child"]]["status"])
551  {
553  return ilUtil::getImagePath('scorm/incomplete.svg');
554 
555  case ilLMTracker::FAILED:
556  return ilUtil::getImagePath('scorm/failed.svg');
557 
559  return ilUtil::getImagePath('scorm/completed.svg');
560  }
561  }
562  return ilUtil::getImagePath('scorm/not_attempted.svg');
563  }
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
loadLMTrackingData()
Load LM tracking data.
+ Here is the call graph for this function:

◆ getInstance()

static ilLMTracker::getInstance (   $a_ref_id,
  $a_user_id = 0 
)
static

Get instance.

Parameters

Definition at line 71 of file class.ilLMTracker.php.

References $ilUser.

Referenced by ilLMBlockedUsersTableGUI\__construct(), and ilLMPresentationGUI\getTracker().

72  {
73  global $ilUser;
74 
75  if ($a_user_id == 0)
76  {
77  $a_user_id = $ilUser->getId();
78  }
79 
80  if (!isset(self::$instances[$a_ref_id][$a_user_id]))
81  {
82  self::$instances[$a_ref_id][$a_user_id] = new ilLMTracker($a_ref_id, false, $a_user_id);
83  }
84  return self::$instances[$a_ref_id][$a_user_id];
85  }
Track access to ILIAS learning modules.
$ilUser
Definition: imgupload.php:18
+ Here is the caller graph for this function:

◆ getInstanceByObjId()

static ilLMTracker::getInstanceByObjId (   $a_obj_id,
  $a_user_id = 0 
)
static

Get instance.

Parameters

Definition at line 93 of file class.ilLMTracker.php.

References $ilUser.

Referenced by ilLPStatusQuestions\_getCompleted(), and ilLPStatusQuestions\determineStatus().

94  {
95  global $ilUser;
96 
97  if ($a_user_id == 0)
98  {
99  $a_user_id = $ilUser->getId();
100  }
101 
102  if (!isset(self::$instancesbyobj[$a_obj_id][$a_user_id]))
103  {
104  self::$instancesbyobj[$a_obj_id][$a_user_id] = new ilLMTracker($a_obj_id, true, $a_user_id);
105  }
106  return self::$instancesbyobj[$a_obj_id][$a_user_id];
107  }
Track access to ILIAS learning modules.
$ilUser
Definition: imgupload.php:18
+ Here is the caller graph for this function:

◆ hasPredIncorrectAnswers()

ilLMTracker::hasPredIncorrectAnswers (   $a_obj_id,
  $a_ignore_unlock = false 
)

Has predecessing incorrect answers.

Parameters
int$a_obj_id
Returns
bool true if incorrect/unsanswered questions exist in predecessing pages

Definition at line 571 of file class.ilLMTracker.php.

References $ret, and loadLMTrackingData().

572  {
573  $this->loadLMTrackingData();
574  $ret = false;
575  if (is_array($this->tree_arr["nodes"][$a_obj_id]))
576  {
577  if ($a_ignore_unlock)
578  {
579  $ret = $this->tree_arr["nodes"][$a_obj_id]["has_pred_incorrect_answers"];
580  }
581  else
582  {
583  $ret = $this->tree_arr["nodes"][$a_obj_id]["has_pred_incorrect_not_unlocked_answers"];
584  }
585  }
586  return $ret;
587  }
$ret
Definition: parser.php:6
loadLMTrackingData()
Load LM tracking data.
+ Here is the call graph for this function:

◆ loadLMTrackingData()

ilLMTracker::loadLMTrackingData ( )
protected

Load LM tracking data.

Loaded when needed.

Parameters

Definition at line 322 of file class.ilLMTracker.php.

References $ilDB, ilLMObject\_getAllLMObjectsOfLM(), array, determineProgressStatus(), ilPageQuestionProcessor\getAnswerStatus(), getCurrentPage(), and ilLMPageObject\queryQuestionsOfLearningModule().

Referenced by getAllQuestionsCorrect(), getIconForLMObject(), and hasPredIncorrectAnswers().

323  {
324  global $ilDB;
325 
326  // we must prevent loading tracking data multiple times during a request where possible
327  // please note that the dirty flag works only to a certain limit
328  // e.g. if questions are answered the flag is not set (yet)
329  // or if pages/chapter are added/deleted the flag is not set
330  if ($this->loaded_for_node === (int) $this->getCurrentPage() && !$this->dirty)
331  {
332  return;
333  }
334 
335  $this->loaded_for_node = (int) $this->getCurrentPage();
336  $this->dirty = false;
337 
338  // load lm tree in array
339  $this->tree_arr = array();
340  $nodes = $this->lm_tree->getSubTree($this->lm_tree->getNodeData($this->lm_tree->readRootId()));
341  foreach ($nodes as $node)
342  {
343  $this->tree_arr["childs"][$node["parent"]][] = $node;
344  $this->tree_arr["parent"][$node["child"]] = $node["parent"];
345  $this->tree_arr["nodes"][$node["child"]] = $node;
346  }
347 
348  // load all lm obj ids of learning module
349  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
350  $this->lm_obj_ids = ilLMObject::_getAllLMObjectsOfLM($this->lm_obj_id);
351 
352  // load read event data
353  $this->re_arr = array();
354  $set = $ilDB->query("SELECT * FROM lm_read_event ".
355  " WHERE ".$ilDB->in("obj_id", $this->lm_obj_ids, false, "integer").
356  " AND usr_id = ".$ilDB->quote($this->user_id, "integer"));
357  while ($rec = $ilDB->fetchAssoc($set))
358  {
359  $this->re_arr[$rec["obj_id"]] = $rec;
360  }
361 
362  // load question/pages information
363  $this->page_questions = array();
364  $this->all_questions = array();
365  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
366  $q = ilLMPageObject::queryQuestionsOfLearningModule($this->lm_obj_id, "", "", 0, 0);
367  foreach ($q["set"] as $quest)
368  {
369  $this->page_questions[$quest["page_id"]][] = $quest["question_id"];
370  $this->all_questions[] = $quest["question_id"];
371  }
372 
373  // load question answer information
374  include_once("./Services/COPage/classes/class.ilPageQuestionProcessor.php");
375  $this->answer_status = ilPageQuestionProcessor::getAnswerStatus($this->all_questions, $this->user_id);
376 
377  $this->has_incorrect_answers = false;
378 
379  $has_pred_incorrect_answers = false;
380  $has_pred_incorrect_not_unlocked_answers = false;
381  $this->determineProgressStatus($this->lm_tree->readRootId(), $has_pred_incorrect_answers, $has_pred_incorrect_not_unlocked_answers);
382 
383  $this->has_incorrect_answers = $has_pred_incorrect_answers;
384  }
static _getAllLMObjectsOfLM($a_lm_id, $a_type="")
Get all objects of learning module.
static queryQuestionsOfLearningModule($a_lm_id, $a_order_field, $a_order_dir, $a_offset, $a_limit)
Get questions of learning module.
getCurrentPage()
Get current page.
static getAnswerStatus($a_q_id, $a_user_id=0)
Get statistics for question.
determineProgressStatus($a_obj_id, &$a_has_pred_incorrect_answers, &$a_has_pred_incorrect_not_unlocked_answers)
Determine progress status of nodes.
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrentPage()

ilLMTracker::setCurrentPage (   $a_val)

Set current page.

Parameters
id$a_valcurrent page id

Definition at line 301 of file class.ilLMTracker.php.

302  {
303  $this->current_page_id = $a_val;
304  }

◆ trackAccess()

ilLMTracker::trackAccess (   $a_page_id)

Track access to lm page.

Parameters
int$a_page_idpage id

Definition at line 118 of file class.ilLMTracker.php.

References ilLearningProgress\_tracProgress(), ilLPStatusWrapper\_updateStatus(), trackLastPageAccess(), and trackPageAndChapterAccess().

119  {
120  if ($this->lm_ref_id == 0)
121  {
122  die("ilLMTracker: No Ref Id given.");
123  }
124 
125  // track page and chapter access
126  $this->trackPageAndChapterAccess($a_page_id);
127 
128  // track last page access (must be done after calling trackPageAndChapterAccess())
129  $this->trackLastPageAccess($this->user_id, $this->lm_ref_id, $a_page_id);
130 
131  // #9483
132  // general learning module lp tracking
133  include_once("./Services/Tracking/classes/class.ilLearningProgress.php");
134  ilLearningProgress::_tracProgress($this->user_id, $this->lm_obj_id,
135  $this->lm_ref_id, "lm");
136 
137  // obsolete?
138  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
139  ilLPStatusWrapper::_updateStatus($this->lm_obj_id, $this->user_id);
140 
141  // mark currently loaded data as dirty to force reload if necessary
142  $this->dirty = true;
143  }
trackLastPageAccess($usr_id, $lm_id, $obj_id)
Track last accessed page for a learning module.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _tracProgress($a_user_id, $a_obj_id, $a_ref_id, $a_obj_type='')
trackPageAndChapterAccess($a_page_id)
Track page and chapter access.
+ Here is the call graph for this function:

◆ trackLastPageAccess()

ilLMTracker::trackLastPageAccess (   $usr_id,
  $lm_id,
  $obj_id 
)

Track last accessed page for a learning module.

Parameters
int$usr_iduser id
int$lm_idlearning module id
int$obj_idpage id

Definition at line 152 of file class.ilLMTracker.php.

References $ilDB, and $title.

Referenced by trackAccess().

153  {
154  global $ilDB;
155 
156  // first check if an entry for this user and this lm already exist, when so, delete
157  $q = "DELETE FROM lo_access ".
158  "WHERE usr_id = ".$ilDB->quote((int) $usr_id, "integer")." ".
159  "AND lm_id = ".$ilDB->quote((int) $lm_id, "integer");
160  $ilDB->manipulate($q);
161 
162  $title = "";
163 
164  $q = "INSERT INTO lo_access ".
165  "(timestamp,usr_id,lm_id,obj_id,lm_title) ".
166  "VALUES ".
167  "(".$ilDB->now().",".
168  $ilDB->quote((int) $usr_id, "integer").",".
169  $ilDB->quote((int) $lm_id, "integer").",".
170  $ilDB->quote((int) $obj_id, "integer").",".
171  $ilDB->quote($title, "text").")";
172  $ilDB->manipulate($q);
173  }
global $ilDB
+ Here is the caller graph for this function:

◆ trackPageAndChapterAccess()

ilLMTracker::trackPageAndChapterAccess (   $a_page_id)
protected

Track page and chapter access.

Definition at line 179 of file class.ilLMTracker.php.

References $ilDB, $res, $row, $time_diff, ilObjUserTracking\_getValidTimeSpan(), array, IL_CAL_DATETIME, IL_CAL_UNIX, and time.

Referenced by trackAccess().

180  {
181  global $ilDB;
182 
183  $now = time();
184 
185  //
186  // 1. Page access: current page
187  //
188  $set = $ilDB->query("SELECT obj_id FROM lm_read_event".
189  " WHERE obj_id = ".$ilDB->quote($a_page_id, "integer").
190  " AND usr_id = ".$ilDB->quote($this->user_id, "integer"));
191  if (!$ilDB->fetchAssoc($set))
192  {
193  $fields = array(
194  "obj_id" => array("integer", $a_page_id),
195  "usr_id" => array("integer", $this->user_id)
196  );
197  // $ilDB->insert("lm_read_event", $fields);
198  $ilDB->replace("lm_read_event", $fields, array()); // #15144
199  }
200 
201  // update all parent chapters
202  $ilDB->manipulate("UPDATE lm_read_event SET".
203  " read_count = read_count + 1 ".
204  " , last_access = ".$ilDB->quote($now, "integer").
205  " WHERE obj_id = ".$ilDB->quote($a_page_id, "integer").
206  " AND usr_id = ".$ilDB->quote($this->user_id, "integer"));
207 
208 
209  //
210  // 2. Chapter access: based on last page accessed
211  //
212 
213  // get last accessed page
214  $set = $ilDB->query("SELECT * FROM lo_access WHERE ".
215  "usr_id = ".$ilDB->quote($this->user_id, "integer")." AND ".
216  "lm_id = ".$ilDB->quote($this->lm_ref_id, "integer"));
217  $res = $ilDB->fetchAssoc($set);
218  if($res["obj_id"])
219  {
220  include_once('Services/Tracking/classes/class.ilObjUserTracking.php');
221  $valid_timespan = ilObjUserTracking::_getValidTimeSpan();
222 
223  $pg_ts = new ilDateTime($res["timestamp"], IL_CAL_DATETIME);
224  $pg_ts = $pg_ts->get(IL_CAL_UNIX);
225  $pg_id = $res["obj_id"];
226  if(!$this->lm_tree->isInTree($pg_id))
227  {
228  return;
229  }
230 
231  $time_diff = $read_diff = 0;
232 
233  // spent_seconds or read_count ?
234  if (($now-$pg_ts) <= $valid_timespan)
235  {
236  $time_diff = $now-$pg_ts;
237  }
238  else
239  {
240  $read_diff = 1;
241  }
242 
243  // find parent chapter(s) for that page
244  $parent_st_ids = array();
245  foreach($this->lm_tree->getPathFull($pg_id) as $item)
246  {
247  if($item["type"] == "st")
248  {
249  $parent_st_ids[] = $item["obj_id"];
250  }
251  }
252 
253  if($parent_st_ids && ($time_diff || $read_diff))
254  {
255  // get existing chapter entries
256  $ex_st = array();
257  $set = $ilDB->query("SELECT obj_id FROM lm_read_event".
258  " WHERE ".$ilDB->in("obj_id", $parent_st_ids, "", "integer").
259  " AND usr_id = ".$ilDB->quote($this->user_id, "integer"));
260  while($row = $ilDB->fetchAssoc($set))
261  {
262  $ex_st[] = $row["obj_id"];
263  }
264 
265  // add missing chapter entries
266  $missing_st = array_diff($parent_st_ids, $ex_st);
267  if(sizeof($missing_st))
268  {
269  foreach($missing_st as $st_id)
270  {
271  $fields = array(
272  "obj_id" => array("integer", $st_id),
273  "usr_id" => array("integer", $this->user_id)
274  );
275  // $ilDB->insert("lm_read_event", $fields);
276  $ilDB->replace("lm_read_event", $fields, array()); // #15144
277  }
278  }
279 
280  // update all parent chapters
281  $ilDB->manipulate("UPDATE lm_read_event SET".
282  " read_count = read_count + ".$ilDB->quote($read_diff, "integer").
283  " , spent_seconds = spent_seconds + ".$ilDB->quote($time_diff, "integer").
284  " , last_access = ".$ilDB->quote($now, "integer").
285  " WHERE ".$ilDB->in("obj_id", $parent_st_ids, "", "integer").
286  " AND usr_id = ".$ilDB->quote($this->user_id, "integer"));
287  }
288  }
289  }
const IL_CAL_DATETIME
const IL_CAL_UNIX
$time_diff
Definition: langcheck.php:760
Date and time handling
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $all_questions

ilLMTracker::$all_questions = array()
protected

Definition at line 29 of file class.ilLMTracker.php.

◆ $answer_status

ilLMTracker::$answer_status = array()
protected

Definition at line 30 of file class.ilLMTracker.php.

◆ $current_page_id

ilLMTracker::$current_page_id = 0
protected

Definition at line 32 of file class.ilLMTracker.php.

Referenced by getCurrentPage().

◆ $dirty

ilLMTracker::$dirty = false
protected

Definition at line 27 of file class.ilLMTracker.php.

◆ $has_incorrect_answers

ilLMTracker::$has_incorrect_answers = false
protected

Definition at line 31 of file class.ilLMTracker.php.

◆ $instances

ilLMTracker::$instances = array()
static

Definition at line 34 of file class.ilLMTracker.php.

◆ $instancesbyobj

ilLMTracker::$instancesbyobj = array()
static

Definition at line 35 of file class.ilLMTracker.php.

◆ $lm_obj_id

ilLMTracker::$lm_obj_id
protected

Definition at line 21 of file class.ilLMTracker.php.

◆ $lm_obj_ids

ilLMTracker::$lm_obj_ids = array()
protected

Definition at line 23 of file class.ilLMTracker.php.

◆ $lm_ref_id

ilLMTracker::$lm_ref_id
protected

Definition at line 20 of file class.ilLMTracker.php.

◆ $lm_tree

ilLMTracker::$lm_tree
protected

Definition at line 22 of file class.ilLMTracker.php.

◆ $loaded_for_node

ilLMTracker::$loaded_for_node = false
protected

Definition at line 26 of file class.ilLMTracker.php.

◆ $page_questions

ilLMTracker::$page_questions = array()
protected

Definition at line 28 of file class.ilLMTracker.php.

◆ $re_arr

ilLMTracker::$re_arr = array()
protected

Definition at line 25 of file class.ilLMTracker.php.

◆ $tree_arr

ilLMTracker::$tree_arr = array()
protected

Definition at line 24 of file class.ilLMTracker.php.

◆ COMPLETED

const ilLMTracker::COMPLETED = 2

Definition at line 16 of file class.ilLMTracker.php.

Referenced by determineProgressStatus(), and getIconForLMObject().

◆ CURRENT

const ilLMTracker::CURRENT = 99

Definition at line 18 of file class.ilLMTracker.php.

Referenced by determineProgressStatus().

◆ FAILED

const ilLMTracker::FAILED = 3

Definition at line 17 of file class.ilLMTracker.php.

Referenced by determineProgressStatus(), and getIconForLMObject().

◆ IN_PROGRESS

const ilLMTracker::IN_PROGRESS = 1

Definition at line 15 of file class.ilLMTracker.php.

Referenced by determineProgressStatus(), and getIconForLMObject().

◆ NOT_ATTEMPTED

const ilLMTracker::NOT_ATTEMPTED = 0

Definition at line 14 of file class.ilLMTracker.php.

Referenced by determineProgressStatus().


The documentation for this class was generated from the following file: