19declare(strict_types=0);
56 $this->obj_id = $a_obj_id;
57 $this->db =
$DIC->database();
58 $this->ilObjDataCache =
$DIC[
'ilObjDataCache'];
215 ?
object $a_obj =
null,
216 bool $a_percentage =
false,
217 bool $a_force_raise =
false
222 "obj_id: %s, user id: %s, object: %s",
225 (is_object($a_obj) ? get_class($a_obj) :
'null')
244 if (!$changed && $a_force_raise) {
258 ?
object $a_obj =
null
279 ?array $a_users =
null
290 $sql =
"SELECT usr_id FROM ut_lp_marks WHERE " .
291 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
292 " status_dirty = " .
$ilDB->quote(1,
"integer");
293 if (is_array($a_users) && count($a_users) > 0) {
294 $sql .=
" AND " .
$ilDB->in(
"usr_id", $a_users,
false,
"integer");
296 $set =
$ilDB->query($sql);
298 if ($rec =
$ilDB->fetchAssoc($set)) {
304 if (!$dirty && is_array($a_users) && count($a_users) > 0) {
306 "SELECT count(usr_id) cnt FROM ut_lp_marks WHERE " .
307 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
308 $ilDB->in(
"usr_id", $a_users,
false,
"integer")
310 $r =
$ilDB->fetchAssoc($set);
311 if ($r[
"cnt"] < count($a_users)) {
317 if ($dirty || $missing) {
319 $trac_obj->refreshStatus($a_obj_id, $a_users);
332 $ilAppEventHandler =
$DIC[
'ilAppEventHandler'];
336 "obj_id: " . $a_obj_id .
", user id: " . $a_usr_id .
", status: " .
337 $a_status .
", percentage: " . $a_percentage
340 $ilAppEventHandler->raise(
344 "obj_id" => $a_obj_id,
345 "usr_id" => $a_usr_id,
346 "status" => $a_status,
347 "old_status" => $a_old_status,
348 "percentage" => $a_percentage
359 foreach ($not_attempted as $user_id) {
360 $percentage = $this->determinePercentage($a_obj_id, $user_id);
361 if (self::writeStatus(
364 self::LP_STATUS_NOT_ATTEMPTED_NUM,
372 foreach ($in_progress as $user_id) {
373 $percentage = $this->determinePercentage($a_obj_id, $user_id);
374 if (self::writeStatus(
377 self::LP_STATUS_IN_PROGRESS_NUM,
385 foreach ($completed as $user_id) {
386 $percentage = $this->determinePercentage($a_obj_id, $user_id);
387 if (self::writeStatus(
390 self::LP_STATUS_COMPLETED_NUM,
398 foreach ($failed as $user_id) {
399 $percentage = $this->determinePercentage($a_obj_id, $user_id);
400 if (self::writeStatus(
403 self::LP_STATUS_FAILED_NUM,
411 $missing_users = array_diff(
413 $not_attempted + $in_progress + $completed + $failed
415 if ($missing_users) {
416 foreach ($missing_users as $user_id) {
430 int $a_percentage = 0,
431 bool $a_force_per =
false,
432 ?
int &$a_old_status = self::LP_STATUS_NOT_ATTEMPTED_NUM
440 'Write status for: ' .
"obj_id: " . $a_obj_id .
", user id: " . $a_user_id .
", status: " . $a_status .
", percentage: " . $a_percentage .
", force: " . $a_force_per
442 $update_dependencies =
false;
444 $a_old_status = self::LP_STATUS_NOT_ATTEMPTED_NUM;
448 "SELECT usr_id,status,status_dirty FROM ut_lp_marks WHERE " .
449 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
450 " usr_id = " .
$ilDB->quote($a_user_id,
"integer")
452 $rec =
$ilDB->fetchAssoc($set);
456 $a_old_status = $rec[
"status"];
459 if ($rec[
"status"] != $a_status) {
460 $ret =
$ilDB->manipulate(
461 "UPDATE ut_lp_marks SET " .
462 " status = " .
$ilDB->quote($a_status,
"integer") .
"," .
463 " status_changed = " .
$ilDB->now() .
"," .
464 " status_dirty = " .
$ilDB->quote(0,
"integer") .
465 " WHERE usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
466 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
469 $update_dependencies =
true;
472 elseif ($rec[
"status_dirty"]) {
474 "UPDATE ut_lp_marks SET " .
475 " status_dirty = " .
$ilDB->quote(0,
"integer") .
476 " WHERE usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
477 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
486 "obj_id" => array(
"integer", $a_obj_id),
487 "usr_id" => array(
"integer", $a_user_id)
490 "status" => array(
"integer", $a_status),
491 "status_changed" => array(
"timestamp", date(
"Y-m-d H:i:s")),
493 "status_dirty" => array(
"integer", 0)
497 $update_dependencies =
true;
501 if ($a_percentage || $a_force_per) {
502 $a_percentage = max(0, $a_percentage);
503 $a_percentage = min(100, $a_percentage);
504 $ret =
$ilDB->manipulate(
505 "UPDATE ut_lp_marks SET " .
506 " percentage = " .
$ilDB->quote($a_percentage,
"integer") .
507 " WHERE usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
508 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
513 'Update dependecies is ' . ($update_dependencies ?
'true' :
'false')
517 if ($update_dependencies) {
518 $log->debug(
'update dependencies');
524 "SELECT ut_lp_collections.obj_id obj_id FROM " .
525 "object_reference JOIN ut_lp_collections ON " .
526 "(object_reference.obj_id = " .
$ilDB->quote(
530 " AND object_reference.ref_id = ut_lp_collections.item_id)"
532 while ($rec =
$ilDB->fetchAssoc($set)) {
535 array(
"crs",
"grp",
"fold")
538 'Calling update status for collection obj_id: ' . $rec[
'obj_id']
542 (
int) $rec[
"obj_id"],
546 (
int) $rec[
"obj_id"],
554 $log->debug(
'update references');
556 $query =
'select obj_id from container_reference ' .
557 'where target_obj_id = ' .
$ilDB->quote(
564 'Calling update status for reference obj_id: ' . $row->obj_id
586 return $update_dependencies;
604 $needs_update =
false;
607 "SELECT usr_id, status FROM ut_lp_marks WHERE " .
608 " obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
" AND " .
609 " usr_id = " .
$ilDB->quote($a_user_id,
"integer")
611 if ($rec =
$ilDB->fetchAssoc($set)) {
613 if ($rec[
"status"] == self::LP_STATUS_NOT_ATTEMPTED_NUM) {
614 $needs_update =
true;
618 $needs_update =
true;
636 "UPDATE ut_lp_marks SET " .
637 " status_dirty = " .
$ilDB->quote(1,
"integer")
644 public static function setDirty(
int $a_obj_id): void
651 "UPDATE ut_lp_marks SET " .
652 " status_dirty = " .
$ilDB->quote(1,
"integer") .
653 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
663 bool $a_create =
true
670 "SELECT status FROM ut_lp_marks WHERE " .
671 " status_dirty = " .
$ilDB->quote(0,
"integer") .
672 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
673 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
675 if ($rec =
$ilDB->fetchAssoc($set)) {
676 return (
int) $rec[
"status"];
677 } elseif ($a_create) {
680 "SELECT status FROM ut_lp_marks WHERE " .
681 " status_dirty = " .
$ilDB->quote(0,
"integer") .
682 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
683 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
685 if ($rec =
$ilDB->fetchAssoc($set)) {
686 return (
int) $rec[
"status"];
704 "SELECT percentage FROM ut_lp_marks WHERE " .
705 " status_dirty = " .
$ilDB->quote(0,
"integer") .
706 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
707 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
709 if ($rec =
$ilDB->fetchAssoc($set)) {
710 return $rec[
"percentage"];
722 return self::_lookupStatus(
725 ) == self::LP_STATUS_COMPLETED_NUM;
740 "SELECT status_changed FROM ut_lp_marks WHERE " .
741 " status_dirty = " .
$ilDB->quote(0,
"integer") .
742 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
743 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
745 if ($rec =
$ilDB->fetchAssoc($set)) {
746 return (
string) $rec[
"status_changed"];
750 "SELECT status_changed FROM ut_lp_marks WHERE " .
751 " status_dirty = " .
$ilDB->quote(0,
"integer") .
752 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer") .
753 " AND obj_id = " .
$ilDB->quote($a_obj_id,
"integer")
755 if ($rec =
$ilDB->fetchAssoc($set)) {
756 return (
string) $rec[
"status_changed"];
768 ?array $a_user_ids =
null
774 $sql =
"SELECT usr_id, status, status_dirty FROM ut_lp_marks" .
775 " WHERE obj_id = " .
$ilDB->quote($a_obj_id,
"integer") .
776 " AND status = " .
$ilDB->quote($a_status,
"integer");
778 $sql .=
" AND " .
$ilDB->in(
"usr_id", $a_user_ids,
"",
"integer");
781 $set =
$ilDB->query($sql);
783 while ($rec =
$ilDB->fetchAssoc($set)) {
787 if ($rec[
"status_dirty"]) {
789 if (self::_lookupStatus(
807 ?array $a_user_ids =
null
809 return self::_lookupStatusForObject(
811 self::LP_STATUS_COMPLETED_NUM,
821 ?array $a_user_ids =
null
823 return self::_lookupStatusForObject(
825 self::LP_STATUS_FAILED_NUM,
835 ?array $a_user_ids =
null
837 return self::_lookupStatusForObject(
839 self::LP_STATUS_IN_PROGRESS_NUM,
852 $lp_invalid = array();
859 foreach ($memberships as $obj_id => $status) {
861 $lp_invalid[] = $obj_id;
865 return array_diff($a_obj_ids, $lp_invalid);
873 array &$a_coll_obj_ids
882 foreach ($existing as $obj_id => $obj_mode) {
884 $valid[$obj_id] = $obj_id;
886 if (in_array($obj_mode, $coll_modes)) {
887 $a_coll_obj_ids[] = $obj_id;
893 $existing_obj_ids = array_keys($existing);
894 if (
sizeof($existing) !=
sizeof($a_obj_ids)) {
895 foreach (array_diff($a_obj_ids, $existing_obj_ids) as $obj_id) {
897 $mode = $olp->getCurrentMode();
902 $valid[$obj_id] = $obj_id;
904 if (in_array($mode, $coll_modes)) {
905 $a_coll_obj_ids[] = $obj_id;
911 return array_values(
$valid);
928 $sql =
"SELECT status, status_dirty, obj_id FROM ut_lp_marks" .
929 " WHERE " .
$ilDB->in(
"obj_id", $a_obj_ids,
"",
"integer") .
930 " AND usr_id = " .
$ilDB->quote($a_user_id,
"integer");
931 $set =
$ilDB->query($sql);
932 while ($row =
$ilDB->fetchAssoc($set)) {
933 if (!$row[
"status_dirty"]) {
934 $res[$row[
"obj_id"]] = $row[
"status"];
936 $res[$row[
"obj_id"]] = self::_lookupStatus(
944 foreach ($a_obj_ids as $obj_id) {
945 if (!isset(
$res[$obj_id])) {
946 $res[$obj_id] = self::_lookupStatus($obj_id, $a_user_id);
947 if (
$res[$obj_id] ===
null) {
948 $res[$obj_id] = self::LP_STATUS_NOT_ATTEMPTED_NUM;
961 if (
$DIC->http()->wrapper()->query()->has(
'ref_id')) {
964 $DIC->refinery()->kindlyTo()->int()
984 $coll_obj_ids = array();
985 $a_obj_ids = self::checkLPModesForObjects(
992 $res = self::getLPStatusForObjects($user_id, $a_obj_ids);
997 $lng->loadLanguageModule(
"trac");
999 foreach (
$res as $obj_id => $status) {
1001 "image" => $icons->renderIconForStatus($status),
1007 self::$list_gui_cache =
$res;
1015 bool $a_image_only =
true
1017 if ($a_image_only) {
1019 if (isset(self::$list_gui_cache[$a_obj_id][
"image"])) {
1020 $image = self::$list_gui_cache[$a_obj_id][
"image"];
1025 return self::$list_gui_cache[$a_obj_id] ??
"";
1030 if (isset(self::$list_gui_cache[$a_obj_id])) {
static getCollectionModes()
const LP_MODE_DEACTIVATED
static _lookupDBModeForObjects(array $a_obj_ids)
static _getInstance(int $a_obj_id, ?int $a_mode=null)
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
static _getInProgress(int $a_obj_id)
Static function to read users who have the status 'in_progress'.
static _getFailed(int $a_obj_id)
Static function to read the users who have the status 'completed'.
static _removeStatusCache(int $a_obj_id, int $a_usr_id)
static _getNotAttempted(int $a_obj_id)
Static function to read the number of user who have the status 'not_attempted'.
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
static _getCompleted(int $a_obj_id)
Static function to read the users who have the status 'completed'.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
static writeStatus(int $a_obj_id, int $a_user_id, int $a_status, int $a_percentage=0, bool $a_force_per=false, ?int &$a_old_status=self::LP_STATUS_NOT_ATTEMPTED_NUM)
Write status for user and object.
static validateLPForObjects(int $a_user_id, array $a_obj_ids, int $a_parent_ref_id)
Process given objects for lp-relevance.
static preloadListGUIData(array $a_obj_ids)
const LP_STATUS_COMPLETED_NUM
static _lookupPercentage(int $a_obj_id, int $a_user_id)
Lookup percentage.
static setDirty(int $a_obj_id)
Sets status of an object to dirty.
const LP_STATUS_NOT_PARTICIPATED
static _getInProgress(int $a_obj_id)
static _hasUserCompleted(int $a_obj_id, int $a_user_id)
Lookup user object completion.
static getListGUIStatus(int $a_obj_id, bool $a_image_only=true)
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
Get completed users for object.
static _getTypicalLearningTime(int $a_obj_id)
__construct(int $a_obj_id)
static setInProgressIfNotAttempted(int $a_obj_id, int $a_user_id)
This function shoudl be clalled for normal "read events".
const LP_STATUS_COMPLETED
determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj=null)
static _getFailed(int $a_obj_id)
const LP_STATUS_NOT_REGISTERED
const LP_STATUS_PARTICIPATED
static _lookupStatusChanged(int $a_obj_id, int $a_user_id)
Lookup status changed.
const LP_STATUS_IN_PROGRESS_NUM
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
Get in progress users for object.
_updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
New status handling (st: status, nr: accesses, p: percentage, t: time spent, m: mark) Learning progre...
static checkLPModesForObjects(array $a_obj_ids, array &$a_coll_obj_ids)
Process lp modes for given objects.
static _getCountCompleted(int $a_obj_id)
static _getNotAttempted(int $a_obj_id)
static raiseEvent(int $a_obj_id, int $a_usr_id, int $a_status, int $a_old_status, int $a_percentage)
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_REGISTERED
static _getCountNotAttempted(int $a_obj_id)
ilObjectDataCache $ilObjDataCache
static _getCountInProgress(int $a_obj_id)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
Get failed users for object.
static _lookupStatus(int $a_obj_id, int $a_user_id, bool $a_create=true)
Lookup status.
static setAllDirty()
Sets all status to dirty.
refreshStatus(int $a_obj_id, ?array $a_users=null)
Refresh status.
static getLPStatusForObjects(int $a_user_id, array $a_obj_ids)
Get LP status for given objects (and user)
static _getCompleted(int $a_obj_id)
static checkStatusForObject(int $a_obj_id, ?array $a_users=null)
This function checks whether the status for a given number of users is dirty and must be recalculated...
const LP_STATUS_FAILED_NUM
static _lookupStatusForObject(int $a_obj_id, int $a_status, ?array $a_user_ids=null)
Get users with given status for object.
static _getStatusInfo(int $a_obj_id)
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
static hasListGUIStatus(int $a_obj_id)
static _getCountFailed(int $a_obj_id)
determineStatus(int $a_obj_id, int $a_usr_id, object $a_obj=null)
static getLogger(string $a_component_id)
Get component logger.
static _getTypicalLearningTimeSeconds(int $a_rbac_id, int $a_obj_id=0)
static _hasLearningProgressListGUI()
static _hasLearningProgressLearner()
static _enabledLearningProgress()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLPMemberships(int $usr_id, array $obj_ids, ?int $parent_ref_id=null, bool $mapped_ref_ids=false)
Get all objects where given user is member (from LP POV)
static getInstance(int $obj_id)
static _lookupType(int $id, bool $reference=false)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']