44 $this->obj_id = $a_obj_id;
95 include_once
'Services/MetaData/classes/class.ilMDEducational.php';
203 public function _updateStatus($a_obj_id, $a_usr_id, $a_obj = null, $a_percentage =
false, $a_force_raise =
false)
207 "obj_id: %s, user id: %s, object: %s",
210 (is_object($a_obj) ? get_class($a_obj) :
'null')
216 $changed = self::writeStatus($a_obj_id, $a_usr_id, $status, $percentage,
false, $old_status);
221 if (!
$changed && (
bool) $a_force_raise) {
222 self::raiseEvent($a_obj_id, $a_usr_id, $status, $old_status, $percentage);
260 $ilDB = $DIC[
'ilDB'];
267 $sql =
"SELECT usr_id FROM ut_lp_marks WHERE " .
268 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
269 " status_dirty = " .
$ilDB->quote(1,
"integer");
270 if (is_array($a_users) && count($a_users) > 0) {
271 $sql .=
" AND " .
$ilDB->in(
"usr_id", $a_users,
false,
"integer");
273 $set =
$ilDB->query($sql);
275 if ($rec =
$ilDB->fetchAssoc($set)) {
281 if (!$dirty && is_array($a_users) && count($a_users) > 0) {
282 $set =
$ilDB->query(
"SELECT count(usr_id) cnt FROM ut_lp_marks WHERE " .
283 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
284 $ilDB->in(
"usr_id", $a_users,
false,
"integer"));
285 $r =
$ilDB->fetchAssoc($set);
286 if ($r[
"cnt"] < count($a_users)) {
292 if ($dirty || $missing) {
293 require_once
"Services/Tracking/classes/class.ilLPStatusFactory.php";
295 $trac_obj->refreshStatus($a_obj_id, $a_users);
299 protected static function raiseEvent($a_obj_id, $a_usr_id, $a_status, $a_old_status, $a_percentage)
303 $ilAppEventHandler = $DIC[
'ilAppEventHandler'];
306 $log->debug(
"obj_id: " . $a_obj_id .
", user id: " . $a_usr_id .
", status: " .
307 $a_status .
", percentage: " . $a_percentage);
309 $ilAppEventHandler->raise(
"Services/Tracking",
"updateStatus", array(
310 "obj_id" => $a_obj_id,
311 "usr_id" => $a_usr_id,
312 "status" => $a_status,
313 "old_status" => $a_old_status,
314 "percentage" => $a_percentage
326 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
328 foreach ($not_attempted as $user_id) {
330 if (self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_NOT_ATTEMPTED_NUM, $percentage,
true)) {
335 foreach ($in_progress as $user_id) {
337 if (self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_IN_PROGRESS_NUM, $percentage,
true)) {
342 foreach ($completed as $user_id) {
344 if (self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_COMPLETED_NUM, $percentage,
true)) {
349 foreach (
$failed as $user_id) {
351 if (self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_FAILED_NUM, $percentage,
true)) {
356 $missing_users = array_diff($a_users, $not_attempted + $in_progress + $completed +
$failed);
357 if ($missing_users) {
358 foreach ($missing_users as $user_id) {
371 public static function writeStatus($a_obj_id, $a_user_id, $a_status, $a_percentage =
false, $a_force_per =
false, &$a_old_status = self::LP_STATUS_NOT_ATTEMPTED_NUM)
375 $ilDB = $DIC->database();
376 $log = $DIC->logger()->trac();
378 $log->debug(
'Write status for: ' .
"obj_id: " . $a_obj_id .
", user id: " . $a_user_id .
", status: " . $a_status .
", percentage: " . $a_percentage .
", force: " . $a_force_per);
379 $update_dependencies =
false;
381 $a_old_status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
385 "SELECT usr_id,status,status_dirty FROM ut_lp_marks WHERE " .
386 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
387 " usr_id = " .
$ilDB->quote($a_user_id,
"integer")
389 $rec =
$ilDB->fetchAssoc($set);
393 $a_old_status = $rec[
"status"];
396 if ($rec[
"status"] != $a_status) {
398 "UPDATE ut_lp_marks SET " .
399 " status = " .
$ilDB->quote($a_status,
"integer") .
"," .
400 " status_changed = " .
$ilDB->now() .
"," .
401 " status_dirty = " .
$ilDB->quote(0,
"integer") .
402 " WHERE usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
403 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
406 $update_dependencies =
true;
410 elseif ($rec[
"status_dirty"]) {
412 "UPDATE ut_lp_marks SET " .
413 " status_dirty = " .
$ilDB->quote(0,
"integer") .
414 " WHERE usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
415 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
425 "obj_id" => array(
"integer", $a_obj_id),
426 "usr_id" => array(
"integer", $a_user_id)
429 "status" => array(
"integer", $a_status),
430 "status_changed" => array(
"timestamp", date(
"Y-m-d H:i:s")),
431 "status_dirty" => array(
"integer", 0)
435 $update_dependencies =
true;
439 if ($a_percentage !==
false || $a_force_per) {
440 $a_percentage = max(0, (
int) $a_percentage);
441 $a_percentage = min(100, $a_percentage);
443 "UPDATE ut_lp_marks SET " .
444 " percentage = " .
$ilDB->quote($a_percentage,
"integer") .
445 " WHERE usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
446 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
450 $log->debug(
'Update dependecies is ' . ($update_dependencies ?
'true' :
'false'));
453 if ($update_dependencies) {
454 $log->debug(
'update dependencies');
457 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
460 $set =
$ilDB->query(
"SELECT ut_lp_collections.obj_id obj_id FROM " .
461 "object_reference JOIN ut_lp_collections ON " .
462 "(object_reference.obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
463 " AND object_reference.ref_id = ut_lp_collections.item_id)");
464 while ($rec =
$ilDB->fetchAssoc($set)) {
466 $log->debug(
'Calling update status for collection obj_id: ' . $rec[
'obj_id']);
475 $log->debug(
'update references');
477 $query =
'select obj_id from container_reference ' .
481 $log->debug(
'Calling update status for reference obj_id: ' . $row->obj_id);
487 self::raiseEvent($a_obj_id, $a_user_id, $a_status, $a_old_status, $a_percentage);
490 return $update_dependencies;
502 $ilDB = $DIC[
'ilDB'];
506 $needs_update =
false;
509 "SELECT usr_id, status FROM ut_lp_marks WHERE " .
510 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
511 " usr_id = " .
$ilDB->quote($a_user_id,
"integer")
513 if ($rec =
$ilDB->fetchAssoc($set)) {
515 if ($rec[
"status"] == self::LP_STATUS_NOT_ATTEMPTED_NUM) {
516 $needs_update =
true;
520 $needs_update =
true;
524 require_once
"Services/Tracking/classes/class.ilLPStatusWrapper.php";
539 $ilDB = $DIC[
'ilDB'];
542 "UPDATE ut_lp_marks SET " .
543 " status_dirty = " .
$ilDB->quote(1,
"integer")
557 $ilDB = $DIC[
'ilDB'];
560 "UPDATE ut_lp_marks SET " .
561 " status_dirty = " .
$ilDB->quote(1,
"integer") .
562 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
573 public static function _lookupStatus($a_obj_id, $a_user_id, $a_create =
true)
577 $ilDB = $DIC[
'ilDB'];
580 "SELECT status FROM ut_lp_marks WHERE " .
581 " status_dirty = " .
$ilDB->quote(0,
"integer") .
582 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
583 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
585 if ($rec =
$ilDB->fetchAssoc($set)) {
586 return $rec[
"status"];
587 } elseif ((
bool) $a_create) {
588 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
591 "SELECT status FROM ut_lp_marks WHERE " .
592 " status_dirty = " .
$ilDB->quote(0,
"integer") .
593 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
594 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
596 if ($rec =
$ilDB->fetchAssoc($set)) {
597 return $rec[
"status"];
612 $ilDB = $DIC[
'ilDB'];
615 "SELECT percentage FROM ut_lp_marks WHERE " .
616 " status_dirty = " .
$ilDB->quote(0,
"integer") .
617 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
618 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
620 if ($rec =
$ilDB->fetchAssoc($set)) {
621 return $rec[
"percentage"];
634 return (self::_lookupStatus($a_obj_id, $a_user_id) == self::LP_STATUS_COMPLETED_NUM);
647 $ilDB = $DIC[
'ilDB'];
650 "SELECT status_changed FROM ut_lp_marks WHERE " .
651 " status_dirty = " .
$ilDB->quote(0,
"integer") .
652 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
653 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
655 if ($rec =
$ilDB->fetchAssoc($set)) {
656 return $rec[
"status_changed"];
658 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
661 "SELECT status_changed FROM ut_lp_marks WHERE " .
662 " status_dirty = " .
$ilDB->quote(0,
"integer") .
663 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
664 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
666 if ($rec =
$ilDB->fetchAssoc($set)) {
667 return $rec[
"status_changed"];
684 $ilDB = $DIC[
'ilDB'];
686 $sql =
"SELECT usr_id, status, status_dirty FROM ut_lp_marks" .
687 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
688 " AND status = " .
$ilDB->quote($a_status,
"integer");
690 $sql .=
" AND " .
$ilDB->in(
"usr_id", $a_user_ids,
"",
"integer");
693 $set =
$ilDB->query($sql);
695 while ($rec =
$ilDB->fetchAssoc($set)) {
696 if (
$res[
"status_dirty"]) {
698 if (self::_lookupStatus($a_obj_id, $rec[
"usr_id"]) != $a_status) {
702 $res[] = $rec[
"usr_id"];
717 return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_COMPLETED_NUM, $a_user_ids);
729 return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_FAILED_NUM, $a_user_ids);
741 return self::_lookupStatusForObject($a_obj_id, self::LP_STATUS_IN_PROGRESS_NUM, $a_user_ids);
759 $lp_invalid = array();
761 include_once
"Services/Object/classes/class.ilObjectLP.php";
763 foreach ($memberships as
$obj_id => $status) {
769 return array_diff($a_obj_ids, $lp_invalid);
783 include_once
"Services/Tracking/classes/collection/class.ilLPCollection.php";
786 include_once
"Services/Tracking/classes/class.ilLPObjSettings.php";
790 foreach ($existing as
$obj_id => $obj_mode) {
794 if (in_array($obj_mode, $coll_modes)) {
801 include_once
"Services/Object/classes/class.ilObjectLP.php";
802 if (
sizeof($existing) !=
sizeof($a_obj_ids)) {
803 foreach (array_diff($a_obj_ids, $existing) as
$obj_id) {
805 $mode = $olp->getCurrentMode();
812 if (in_array($mode, $coll_modes)) {
820 return array_values(
$valid);
834 $ilDB = $DIC[
'ilDB'];
839 $sql =
"SELECT status, status_dirty, obj_id FROM ut_lp_marks" .
840 " WHERE " .
$ilDB->in(
"obj_id", $a_obj_ids,
"",
"integer") .
841 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer");
842 $set =
$ilDB->query($sql);
843 while ($row =
$ilDB->fetchAssoc($set)) {
844 if (!$row[
"status_dirty"]) {
845 $res[$row[
"obj_id"]] = $row[
"status"];
847 $res[$row[
"obj_id"]] = self::_lookupStatus($row[
"obj_id"], $a_user_id);
852 foreach ($a_obj_ids as
$obj_id) {
853 if (!isset(
$res[$obj_id])) {
854 $res[
$obj_id] = self::_lookupStatus($obj_id, $a_user_id);
855 if (
$res[$obj_id] === null) {
875 include_once(
"Services/Tracking/classes/class.ilObjUserTracking.php");
876 if (
$ilUser->getId() != ANONYMOUS_USER_ID &&
883 $a_obj_ids = self::validateLPForObjects($user_id, $a_obj_ids, (
int)
$_GET[
"ref_id"]);
886 $coll_obj_ids = array();
887 $a_obj_ids = self::checkLPModesForObjects($a_obj_ids, $coll_obj_ids);
892 $res = self::getLPStatusForObjects($user_id, $a_obj_ids);
898 $lng->loadLanguageModule(
"trac");
899 include_once(
"./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
910 self::$list_gui_cache =
$res;
917 if (isset(self::$list_gui_cache[$a_obj_id][
"image"])) {
918 $image = self::$list_gui_cache[$a_obj_id][
"image"];
923 return self::$list_gui_cache[$a_obj_id];
const LP_STATUS_COMPLETED_NUM
static _getInProgress($a_obj_id)
Static function to read users who have the status 'in_progress'.
static _lookupFailedForObject($a_obj_id, $a_user_ids=null)
Get failed users for object.
refreshStatus($a_obj_id, $a_users=null)
Refresh status.
determineStatus($a_obj_id, $a_usr_id, $a_obj=null)
Determine status.
static _getCompleted($a_obj_id)
Static function to read the users who have the status 'completed'.
static _getTypicalLearningTimeSeconds($a_rbac_id, $a_obj_id=0)
static _getImagePathForStatus($a_status)
Get image path for status.
static preloadListGUIData($a_obj_ids)
static checkStatusForObject($a_obj_id, $a_users=false)
This function checks whether the status for a given number of users is dirty and must be recalculated...
static _hasLearningProgressLearner()
const LP_STATUS_PARTICIPATED
const LP_STATUS_NOT_ATTEMPTED
static _getStatusText($a_status, $a_lng=null)
Get status alt text.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
static _lookupPercentage($a_obj_id, $a_user_id)
Lookup percentage.
static validateLPForObjects($a_user_id, $a_obj_ids, $a_parent_ref_id)
Process given objects for lp-relevance.
const LP_STATUS_IN_PROGRESS_NUM
static _getInstance($a_obj_id, $a_mode=null)
static _getNotAttempted($a_obj_id)
static _getTypicalLearningTime($a_obj_id)
const LP_STATUS_IN_PROGRESS
static _getNotAttempted($a_obj_id)
Static function to read the number of user who have the status 'not_attempted'.
static _getFailed($a_obj_id)
Static function to read the users who have the status 'completed'.
static _getCompleted($a_obj_id)
static _enabledLearningProgress()
check wether learing progress is enabled or not
const LP_STATUS_NOT_PARTICIPATED
foreach($_POST as $key=> $value) $res
static _getStatusInfo($a_obj_id)
static _hasUserCompleted($a_obj_id, $a_user_id)
Lookup user object completion.
static _getCountInProgress($a_obj_id)
static _getCountNotAttempted($a_obj_id)
static getListGUIStatus($a_obj_id, $a_image_only=true)
static _lookupStatusForObject($a_obj_id, $a_status, $a_user_ids=null)
Get users with given status for object.
static _lookupStatusChanged($a_obj_id, $a_user_id)
Lookup status changed.
static checkLPModesForObjects($a_obj_ids, array &$a_coll_obj_ids)
Process lp modes for given objects.
_updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
New status handling (st: status, nr: accesses, p: percentage, t: time spent, m: mark) ...
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
static _lookupDBModeForObjects(array $a_obj_ids)
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getInProgress($a_obj_id)
static writeStatus($a_obj_id, $a_user_id, $a_status, $a_percentage=false, $a_force_per=false, &$a_old_status=self::LP_STATUS_NOT_ATTEMPTED_NUM)
Write status for user and object.
static _removeStatusCache($a_obj_id, $a_usr_id)
static _hasLearningProgressListGUI()
const LP_STATUS_NOT_ATTEMPTED_NUM
static _lookupInProgressForObject($a_obj_id, $a_user_ids=null)
Get in progress users for object.
const LP_STATUS_REGISTERED
static setDirty($a_obj_id)
Sets status of an object to dirty.
const LP_MODE_DEACTIVATED
static getLPStatusForObjects($a_user_id, $a_obj_ids)
Get LP status for given objects (and user)
static setInProgressIfNotAttempted($a_obj_id, $a_user_id)
This function shoudl be clalled for normal "read events".
static _getCountCompleted($a_obj_id)
static _getFailed($a_obj_id)
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static getLogger($a_component_id)
Get component logger.
determinePercentage($a_obj_id, $a_usr_id, $a_obj=null)
Determine percentage.
static setAllDirty()
Sets all status to dirty.
static getLPMemberships($a_usr_id, array $a_obj_ids, $a_parent_ref_id=null, $a_mapped_ref_ids=false)
Get all objects where given user is member (from LP POV)
const LP_STATUS_COMPLETED
static getInstance($a_obj_id)
static raiseEvent($a_obj_id, $a_usr_id, $a_status, $a_old_status, $a_percentage)
static getCollectionModes()
const LP_STATUS_NOT_REGISTERED
static _lookupStatus($a_obj_id, $a_user_id, $a_create=true)
Lookup status.
const LP_STATUS_FAILED_NUM