42 $this->obj_id = $a_obj_id;
87 include_once
'Services/MetaData/classes/class.ilMDEducational.php';
195 function _updateStatus($a_obj_id, $a_usr_id, $a_obj = null, $a_percentage =
false, $a_no_raise =
false, $a_force_raise =
false)
250 $sql =
"SELECT usr_id FROM ut_lp_marks WHERE ".
251 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
" AND ".
252 " status_dirty = ".$ilDB->quote(1,
"integer");
253 if(is_array($a_users) && count($a_users) > 0)
255 $sql .=
" AND ".$ilDB->in(
"usr_id", $a_users,
false,
"integer");
257 $set = $ilDB->query($sql);
259 if ($rec = $ilDB->fetchAssoc($set))
266 if (!$dirty && is_array($a_users) && count($a_users) > 0)
268 $set = $ilDB->query(
"SELECT count(usr_id) cnt FROM ut_lp_marks WHERE ".
269 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
" AND ".
270 $ilDB->in(
"usr_id", $a_users,
false,
"integer"));
271 $r = $ilDB->fetchAssoc($set);
272 if ($r[
"cnt"] < count($a_users))
279 if ($dirty || $missing)
281 require_once
"Services/Tracking/classes/class.ilLPStatusFactory.php";
283 $trac_obj->refreshStatus($a_obj_id, $a_users);
287 protected function raiseEvent($a_obj_id, $a_usr_id, $a_status, $a_percentage)
289 global $ilAppEventHandler;
291 $ilAppEventHandler->raise(
"Services/Tracking",
"updateStatus", array(
292 "obj_id" => $a_obj_id,
293 "usr_id" => $a_usr_id,
294 "status" => $a_status,
295 "percentage" => $a_percentage
307 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
309 foreach ($not_attempted as $user_id)
312 if(self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_NOT_ATTEMPTED_NUM, $percentage,
true))
314 self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_NOT_ATTEMPTED_NUM, $percentage);
318 foreach ($in_progress as $user_id)
321 if(self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_IN_PROGRESS_NUM, $percentage,
true))
323 self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_IN_PROGRESS_NUM, $percentage);
327 foreach ($completed as $user_id)
330 if(self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_COMPLETED_NUM, $percentage,
true))
332 self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_COMPLETED_NUM, $percentage);
339 if(self::writeStatus($a_obj_id, $user_id, self::LP_STATUS_FAILED_NUM, $percentage,
true))
341 self::raiseEvent($a_obj_id, $user_id, self::LP_STATUS_FAILED_NUM, $percentage);
346 $missing_users = array_diff($a_users, $not_attempted+$in_progress+$completed+
$failed);
349 foreach ($missing_users as $user_id)
363 static function writeStatus($a_obj_id, $a_user_id, $a_status, $a_percentage =
false, $a_force_per =
false)
367 $update_collections =
false;
370 $set = $ilDB->query(
"SELECT usr_id,status,status_dirty FROM ut_lp_marks WHERE ".
371 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
" AND ".
372 " usr_id = ".$ilDB->quote($a_user_id,
"integer")
374 $rec = $ilDB->fetchAssoc($set);
380 if ($rec[
"status"] != $a_status)
382 $ret = $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
383 " status = ".$ilDB->quote($a_status,
"integer").
",".
384 " status_changed = ".$ilDB->now().
",".
385 " status_dirty = ".$ilDB->quote(0,
"integer").
386 " WHERE usr_id = ".$ilDB->quote($a_user_id,
"integer").
387 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
391 $update_collections =
true;
395 else if ($rec[
"status_dirty"])
397 $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
398 " status_dirty = ".$ilDB->quote(0,
"integer").
399 " WHERE usr_id = ".$ilDB->quote($a_user_id,
"integer").
400 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
419 $ilDB->replace(
"ut_lp_marks",
421 "obj_id" => array(
"integer", $a_obj_id),
422 "usr_id" => array(
"integer", $a_user_id)
425 "status" => array(
"integer", $a_status),
426 "status_changed" => array(
"timestamp", date(
"Y-m-d H:i:s")),
427 "status_dirty" => array(
"integer", 0)
431 $update_collections =
true;
435 if ($a_percentage !==
false || $a_force_per)
437 $a_percentage = max(0, (
int) $a_percentage);
438 $a_percentage = min(100, $a_percentage);
439 $ret = $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
440 " percentage = ".$ilDB->quote($a_percentage,
"integer").
441 " WHERE usr_id = ".$ilDB->quote($a_user_id,
"integer").
442 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
447 if ($update_collections)
450 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
453 $set = $ilDB->query(
"SELECT ut_lp_collections.obj_id obj_id FROM ".
454 "object_reference JOIN ut_lp_collections ON ".
455 "(object_reference.obj_id = ".$ilDB->quote($a_obj_id,
"integer").
456 " AND object_reference.ref_id = ut_lp_collections.item_id)");
457 while ($rec = $ilDB->fetchAssoc($set))
469 return $update_collections;
483 $needs_update =
false;
485 $set = $ilDB->query(
"SELECT usr_id, status FROM ut_lp_marks WHERE ".
486 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
" AND ".
487 " usr_id = ".$ilDB->quote($a_user_id,
"integer")
489 if ($rec = $ilDB->fetchAssoc($set))
492 if($rec[
"status"] == self::LP_STATUS_NOT_ATTEMPTED_NUM)
494 $needs_update =
true;
500 $needs_update =
true;
505 require_once
"Services/Tracking/classes/class.ilLPStatusWrapper.php";
520 $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
521 " status_dirty = ".$ilDB->quote(1,
"integer")
536 $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
537 " status_dirty = ".$ilDB->quote(1,
"integer").
538 " WHERE obj_id = ".$ilDB->quote($a_obj_id,
"integer")
549 public static function _lookupStatus($a_obj_id, $a_user_id, $a_create =
true)
553 $set = $ilDB->query(
"SELECT status FROM ut_lp_marks WHERE ".
554 " status_dirty = ".$ilDB->quote(0,
"integer").
555 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
556 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
558 if ($rec = $ilDB->fetchAssoc($set))
560 return $rec[
"status"];
562 else if((
bool)$a_create)
564 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
566 $set = $ilDB->query(
"SELECT status FROM ut_lp_marks WHERE ".
567 " status_dirty = ".$ilDB->quote(0,
"integer").
568 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
569 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
571 if ($rec = $ilDB->fetchAssoc($set))
573 return $rec[
"status"];
588 $set = $ilDB->query(
"SELECT percentage FROM ut_lp_marks WHERE ".
589 " status_dirty = ".$ilDB->quote(0,
"integer").
590 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
591 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
593 if ($rec = $ilDB->fetchAssoc($set))
595 return $rec[
"percentage"];
608 return (self::_lookupStatus($a_obj_id, $a_user_id) == self::LP_STATUS_COMPLETED_NUM);
621 $set = $ilDB->query(
"SELECT status_changed FROM ut_lp_marks WHERE ".
622 " status_dirty = ".$ilDB->quote(0,
"integer").
623 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
624 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
626 if ($rec = $ilDB->fetchAssoc($set))
628 return $rec[
"status_changed"];
632 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
634 $set = $ilDB->query(
"SELECT status_changed FROM ut_lp_marks WHERE ".
635 " status_dirty = ".$ilDB->quote(0,
"integer").
636 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
637 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
639 if ($rec = $ilDB->fetchAssoc($set))
641 return $rec[
"status_changed"];
658 $sql =
"SELECT usr_id, status, status_dirty FROM ut_lp_marks".
659 " WHERE obj_id = ".$ilDB->quote($a_obj_id,
"integer").
660 " AND status = ".$ilDB->quote($a_status,
"integer");
663 $sql .=
" AND ".$ilDB->in(
"usr_id", $a_user_ids,
"",
"integer");
666 $set = $ilDB->query($sql);
668 while($rec = $ilDB->fetchAssoc($set))
670 if(
$res[
"status_dirty"])
673 if(self::_lookupStatus($a_obj_id, $rec[
"usr_id"]) != $a_status)
678 $res[] = $rec[
"usr_id"];
726 include_once(
"Services/Tracking/classes/class.ilObjUserTracking.php");
727 if($ilUser->getId() != ANONYMOUS_USER_ID &&
732 include_once
"Services/Object/classes/class.ilObjectLP.php";
737 foreach($existing as
$obj_id => $obj_mode)
745 if(
sizeof($existing) !=
sizeof($a_obj_ids))
748 foreach(array_diff($a_obj_ids, $existing) as
$obj_id)
751 $mode = $olp->getCurrentMode();
768 $sql =
"SELECT status, status_dirty, obj_id FROM ut_lp_marks".
769 " WHERE ".$ilDB->in(
"obj_id",
$valid,
"",
"integer").
770 " AND usr_id = ".$ilDB->quote($ilUser->getId(),
"integer");
771 $set = $ilDB->query($sql);
772 while(
$row = $ilDB->fetchAssoc($set))
774 if(!
$row[
"status_dirty"])
776 $res[
$row[
"obj_id"]] = $row[
"status"];
787 if(!isset(
$res[$obj_id]))
790 if(
$res[$obj_id] === null)
798 $lng->loadLanguageModule(
"trac");
799 include_once(
"./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
800 foreach(
$res as $obj_id => $status)
808 self::$list_gui_cache =
$res;
813 return self::$list_gui_cache[$a_obj_id];