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")
407 $ilDB->manipulate(
"INSERT INTO ut_lp_marks ".
408 "(status, status_changed, usr_id, obj_id, status_dirty) VALUES (".
409 $ilDB->quote($a_status,
"integer").
",".
411 $ilDB->quote($a_user_id,
"integer").
",".
412 $ilDB->quote($a_obj_id,
"integer").
",".
413 $ilDB->quote(0,
"integer").
415 $update_collections =
true;
419 if ($a_percentage !==
false || $a_force_per)
421 $a_percentage = max(0, (
int) $a_percentage);
422 $a_percentage = min(100, $a_percentage);
423 $ret = $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
424 " percentage = ".$ilDB->quote($a_percentage,
"integer").
425 " WHERE usr_id = ".$ilDB->quote($a_user_id,
"integer").
426 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
431 if ($update_collections)
434 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
437 $set = $ilDB->query(
"SELECT ut_lp_collections.obj_id obj_id FROM ".
438 "object_reference JOIN ut_lp_collections ON ".
439 "(object_reference.obj_id = ".$ilDB->quote($a_obj_id,
"integer").
440 " AND object_reference.ref_id = ut_lp_collections.item_id)");
441 while ($rec = $ilDB->fetchAssoc($set))
453 return $update_collections;
467 $needs_update =
false;
469 $set = $ilDB->query(
"SELECT usr_id, status FROM ut_lp_marks WHERE ".
470 " obj_id = ".$ilDB->quote($a_obj_id,
"integer").
" AND ".
471 " usr_id = ".$ilDB->quote($a_user_id,
"integer")
473 if ($rec = $ilDB->fetchAssoc($set))
476 if($rec[
"status"] == self::LP_STATUS_NOT_ATTEMPTED_NUM)
478 $needs_update =
true;
484 $needs_update =
true;
489 require_once
"Services/Tracking/classes/class.ilLPStatusWrapper.php";
504 $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
505 " status_dirty = ".$ilDB->quote(1,
"integer")
520 $ilDB->manipulate(
"UPDATE ut_lp_marks SET ".
521 " status_dirty = ".$ilDB->quote(1,
"integer").
522 " WHERE obj_id = ".$ilDB->quote($a_obj_id,
"integer")
536 $set = $ilDB->query(
"SELECT status FROM ut_lp_marks WHERE ".
537 " status_dirty = ".$ilDB->quote(0,
"integer").
538 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
539 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
541 if ($rec = $ilDB->fetchAssoc($set))
543 return $rec[
"status"];
547 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
549 $set = $ilDB->query(
"SELECT status FROM ut_lp_marks WHERE ".
550 " status_dirty = ".$ilDB->quote(0,
"integer").
551 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
552 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
554 if ($rec = $ilDB->fetchAssoc($set))
556 return $rec[
"status"];
570 return (self::_lookupStatus($a_obj_id, $a_user_id) == self::LP_STATUS_COMPLETED_NUM);
583 $set = $ilDB->query(
"SELECT status_changed FROM ut_lp_marks WHERE ".
584 " status_dirty = ".$ilDB->quote(0,
"integer").
585 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
586 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
588 if ($rec = $ilDB->fetchAssoc($set))
590 return $rec[
"status_changed"];
594 include_once(
"./Services/Tracking/classes/class.ilLPStatusWrapper.php");
596 $set = $ilDB->query(
"SELECT status_changed FROM ut_lp_marks WHERE ".
597 " status_dirty = ".$ilDB->quote(0,
"integer").
598 " AND usr_id = ".$ilDB->quote($a_user_id,
"integer").
599 " AND obj_id = ".$ilDB->quote($a_obj_id,
"integer")
601 if ($rec = $ilDB->fetchAssoc($set))
603 return $rec[
"status_changed"];
620 $sql =
"SELECT usr_id, status, status_dirty FROM ut_lp_marks".
621 " WHERE obj_id = ".$ilDB->quote($a_obj_id,
"integer").
622 " AND status = ".$ilDB->quote($a_status,
"integer");
625 $sql .=
" AND ".$ilDB->in(
"usr_id", $a_user_ids,
"",
"integer");
628 $set = $ilDB->query($sql);
630 while($rec = $ilDB->fetchAssoc($set))
632 if(
$res[
"status_dirty"])
635 if(self::_lookupStatus($a_obj_id, $rec[
"usr_id"]) != $a_status)
640 $res[] = $rec[
"usr_id"];
688 include_once(
"Services/Tracking/classes/class.ilObjUserTracking.php");
689 if($ilUser->getId() != ANONYMOUS_USER_ID &&
694 include_once
"Services/Object/classes/class.ilObjectLP.php";
699 foreach($existing as
$obj_id => $obj_mode)
707 if(
sizeof($existing) !=
sizeof($a_obj_ids))
710 foreach(array_diff($a_obj_ids, $existing) as
$obj_id)
713 $mode = $olp->getCurrentMode();
730 $sql =
"SELECT status, status_dirty, obj_id FROM ut_lp_marks".
731 " WHERE ".$ilDB->in(
"obj_id",
$valid,
"",
"integer").
732 " AND usr_id = ".$ilDB->quote($ilUser->getId(),
"integer");
733 $set = $ilDB->query($sql);
734 while(
$row = $ilDB->fetchAssoc($set))
736 if(!
$row[
"status_dirty"])
738 $res[
$row[
"obj_id"]] = $row[
"status"];
749 if(!isset(
$res[$obj_id]))
756 $lng->loadLanguageModule(
"trac");
757 include_once(
"./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php");
758 foreach(
$res as $obj_id => $status)
766 self::$list_gui_cache =
$res;
771 return self::$list_gui_cache[$a_obj_id];