30 $this->container_obj_id = $a_container_obj_id;
33 $this->container_ref_id = end($refs);
43 if (array_key_exists($a_container_obj_id, self::$instances)) {
44 return self::$instances[$a_container_obj_id];
46 return self::$instances[$a_container_obj_id] =
new self($a_container_obj_id);
75 if ($this->initialized) {
80 include_once
'./Services/Object/classes/class.ilObjectActivation.php';
83 $this->initialized =
true;
94 foreach ($this->
getItemIds() as $item_ref_id) {
95 include_once
'./Services/Object/classes/class.ilObjectActivation.php';
102 include_once
'./Modules/Course/classes/Timings/class.ilTimingUser.php';
103 $user_item =
new ilTimingUser($item[
'obj_id'], $a_usr_id);
105 $user_start = clone $sub_date;
109 $user_end = clone $sub_date;
110 $user_end->increment(
IL_CAL_DAY, $item[
'suggestion_end_rel']);
113 $user_item->update();
125 $ilDB = $DIC->database();
127 $query =
'DELETE FROM crs_timings_user WHERE ' .
$ilDB->in(
'ref_id', $this->item_ids,
false,
'integer') .
' ' .
128 'AND usr_id = ' .
$ilDB->quote($a_usr_id,
'integer');
144 foreach (self::lookupTimings($a_user_ids, $meta,
true,
true) as $user_ids) {
145 foreach ($user_ids as $user_id) {
146 $res[$user_id] = $user_id;
149 return array_values(
$res);
160 public static function lookupTimings(array $a_user_ids, array &$a_meta = null, $a_only_exceeded =
true)
164 $ilDB = $DIC->database();
165 $logger = $DIC->logger()->crs();
173 $logger->debug(
'Course membership assignments');
177 $query =
'SELECT crsi.obj_id sub_ref_id, oref.ref_id, oref.obj_id, crsi.suggestion_start' .
178 ',crsi.suggestion_end,crsi.changeable, crss.timing_mode' .
179 ' FROM crs_settings crss' .
180 ' JOIN object_reference oref ON (oref.obj_id = crss.obj_id AND oref.deleted IS NULL) ' .
181 ' JOIN crs_items crsi ON (crsi.parent_id = oref.ref_id)' .
182 ' JOIN object_reference iref ON (crsi.obj_id = iref.ref_id AND iref.deleted IS NULL) ' .
184 ' AND ' .
$ilDB->in(
'crss.obj_id', array_keys($course_members_map),
false,
'integer') .
190 $user_relevant = $course_map = $course_parent_map = [];
192 $obj_id =
$row[
'obj_id'];
193 $sub_ref_id =
$row[
'sub_ref_id'];
194 $mode =
$row[
'timing_mode'];
197 $course_parent_map[
$row[
'sub_ref_id']] = $row[
'obj_id'];
198 $course_map[$row[
'obj_id']] = $row[
'ref_id'];
201 if (is_array($a_meta)) {
202 foreach ($a_user_ids as $user_id) {
204 if (in_array($user_id, $course_members_map[$obj_id])) {
205 $a_meta[$user_id][$sub_ref_id] = array(
206 'parent' => $row[
'ref_id']
215 if (is_array($a_meta)) {
216 foreach ($a_user_ids as $user_id) {
218 if (in_array($user_id, $course_members_map[$obj_id])) {
219 $a_meta[$user_id][$sub_ref_id][
'start'] = $row[
'suggestion_start'];
220 $a_meta[$user_id][$sub_ref_id][
'end'] = $row[
'suggestion_end'];
226 ($a_only_exceeded && ($row[
'suggestion_end'] && $row[
'suggestion_end'] < $now)) ||
227 (!$a_only_exceeded && ($row[
'suggestion_start'] && $row[
'suggestion_start'] < $now))
229 foreach ($a_user_ids as $user_id) {
231 if (in_array($user_id, $course_members_map[$obj_id])) {
232 $res[$sub_ref_id][$user_id] = $user_id;
239 if ($row[
'changeable'] ||
241 $user_relevant[] = $sub_ref_id;
245 if (count($user_relevant)) {
247 $query =
'SELECT * FROM crs_timings_user' .
248 ' WHERE ' .
$ilDB->in(
'usr_id', $a_user_ids,
false,
'integer') .
249 ' AND ' .
$ilDB->in(
'ref_id', $user_relevant,
false,
'integer');
253 $ref_id =
$row[
'ref_id'];
254 $user_id =
$row[
'usr_id'];
257 $crs_obj_id = $course_parent_map[$ref_id];
258 if (!in_array($user_id, $course_members_map[$crs_obj_id])) {
263 if (is_array($a_meta)) {
264 $a_meta[$user_id][$ref_id][
'start'] =
$row[
'sstart'];
265 $a_meta[$user_id][$ref_id][
'end'] =
$row[
'ssend'];
269 ($a_only_exceeded &&
$row[
'ssend'] &&
$row[
'ssend'] < $now) ||
270 (!$a_only_exceeded &&
$row[
'sstart'] &&
$row[
'sstart'] < $now)
272 $res[$ref_id][$user_id] = $user_id;
275 unset(
$res[$ref_id][$user_id]);
283 foreach (array_keys(
$res) as $ref_id) {
284 if (!
sizeof(
$res[$ref_id])) {
285 if (isset(
$res[
'ref_id']) && !count(
$res[
'ref_id'])) {
286 unset(
$res[$ref_id]);
288 $res[$ref_id] = array_values(
$res[$ref_id]);
295 $invalid_lp = self::getObjectsWithInactiveLP(array_keys(
$res), $obj_map);
297 foreach (array_keys(
$res) as $ref_id) {
299 if (in_array($ref_id, $invalid_lp)) {
300 $res[$ref_id] = array();
304 $user_ids =
$res[$ref_id];
305 if (count($user_ids)) {
306 $res[$ref_id] = array_diff(
314 if (!
sizeof(
$res[$ref_id])) {
315 unset(
$res[$ref_id]);
321 foreach (
$res as $ref_id => $user_ids) {
323 if (!count($user_ids) && isset(
$res[
'ref_id'])) {
324 unset(
$res[$ref_id]);
326 $crs_obj_id = $course_parent_map[$ref_id];
327 $crs_ref_id = $course_map[$crs_obj_id];
328 if (!array_key_exists($crs_ref_id,
$res)) {
329 $res[$crs_ref_id] = $user_ids;
331 $res[$crs_ref_id] = array_unique(array_merge($user_ids,
$res[$crs_ref_id]));
349 $ilDB = $DIC->database();
352 $query =
'SELECT oref.ref_id, oref.obj_id, od.type' .
353 ' FROM object_reference oref' .
354 ' JOIN object_data od ON (oref.obj_id = od.obj_id)' .
355 ' WHERE ' .
$ilDB->in(
'oref.ref_id', $a_ref_ids,
false,
'integer');
357 $item_map = $item_types = array();
359 $item_map[
$row[
'ref_id']] = $row[
'obj_id'];
360 $item_types[$row[
'obj_id']] = $row[
'type'];
363 $a_obj_map = $item_map;
368 $type_modes = array();
369 foreach ($a_ref_ids as $ref_id) {
370 $obj_id = $item_map[$ref_id];
371 $type = $item_types[$obj_id];
379 if (array_key_exists($obj_id, $db_modes)) {
380 $mode = $db_modes[$obj_id];
384 if (!array_key_exists(
$type, $type_modes)) {
386 $type_modes[
$type] = $type_modes[
$type]->getDefaultMode();
388 $mode = $type_modes[
$type];
static getInstanceByContainerId($a_container_obj_id)
Get instance by container id.
const IL_CRS_VIEW_TIMING_ABSOLUTE
__construct($a_container_obj_id)
Singleton constructor.
static isSupportedObjectType($a_type)
TableGUI class for timings administration.
static getItem($a_ref_id)
Get item data.
getContainerObjId()
Get container obj id.
handleNewMembership($a_usr_id, ilDateTime $sub_date)
handleUnsubscribe($a_usr_id)
Handle unsubscribe.
static _getAllReferences($a_id)
get all reference ids of object
init()
Init activation items.
foreach($_POST as $key=> $value) $res
static lookupTimings(array $a_user_ids, array &$a_meta=null, $a_only_exceeded=true)
Lookup references, users with exceeded timings.
const IL_CRS_VIEW_TIMING_RELATIVE
static preloadData(array $a_ref_ids)
Preload data to internal cache.
increment($a_type, $a_count=1)
increment
static _lookupDBModeForObjects(array $a_obj_ids)
const LP_MODE_DEACTIVATED
static getObjectsWithInactiveLP(array $a_ref_ids, array &$a_obj_map=null)
Check object LP modes.
static lookupTimingsExceededByUser(array $a_user_ids)
Check if users currently exceeded ANY object.
static _lookupCompletedForObject($a_obj_id, $a_user_ids=null)
Get completed users for object.
static getUserMembershipAssignmentsByType($a_user_ids, $a_type, $a_only_member_roles)
Get user membership assignments by type.
static getInstance($a_obj_id)
getContainerRefId()
Get container ref_id.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.