ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMyStaffAccess.php
Go to the documentation of this file.
1<?php
2
9{
17 const DEFAULT_CONTEXT = 'crs';
21 protected static $instance = null;
26
27
31 public static function getInstance()
32 {
33 global $DIC;
34
35 if (self::$instance === null) {
36 self::$instance = new self();
37
38 self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_"
39 . self::DEFAULT_CONTEXT);
40 self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION
41 . "_" . self::DEFAULT_CONTEXT);
42 self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION
43 . "_" . self::DEFAULT_CONTEXT);
44 self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS . "_user_id_" . $DIC->user()->getId());
45 self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS . "_user_id_" . $DIC->user()->getId());
46 self::$instance->dropTempTable(self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_"
47 . self::DEFAULT_CONTEXT);
48 }
49
50 return self::$instance;
51 }
52
53
57 private function __construct()
58 {
59 }
60
61
66 {
67 global $DIC;
68
69 if (!$DIC->settings()->get("enable_my_staff")) {
70 return false;
71 }
72
74 if (!$operation) {
75 return false;
76 }
77 if ($this->countOrgusOfUserWithOperationAndContext($DIC->user()->getId(), ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, self::DEFAULT_CONTEXT)
78 > 0) {
79 return true;
80 }
81
82 return false;
83 }
84
85
91 public function hasCurrentUserAccessToUser($usr_id = 0)
92 {
93 global $DIC;
94
95 if (in_array($usr_id, $this->getUsersForUser($DIC->user()->getId()))) {
96 return true;
97 }
98
99 return false;
100 }
101
102
109 {
110 global $DIC;
111
112 return $DIC->access()->checkPositionAccess(ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS, $ref_id);
113 }
114
115
120 {
121 global $DIC;
122
123 $arr_usr_id = $this->getUsersForUserOperationAndContext($DIC->user()
124 ->getId(), ilOrgUnitOperation::OP_READ_LEARNING_PROGRESS, self::DEFAULT_CONTEXT);
125 if (count($arr_usr_id) > 0) {
126 return true;
127 }
128
129 return false;
130 }
131
132
139 {
140 global $DIC;
141
142 $q = "SELECT COUNT(orgu_ua.orgu_id) AS 'cnt' FROM il_orgu_permissions AS perm
143 INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id
144 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context is not NULL
145 WHERE orgu_ua.user_id = " . $DIC->database()->quote($user_id, 'integer') . " AND perm.operations is not NULL AND perm.parent_id = -1";
146
147 $set = $DIC->database()->query($q);
148 $rec = $DIC->database()->fetchAssoc($set);
149
150 return $rec['cnt'];
151 }
152
153
161 public function countOrgusOfUserWithOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT)
162 {
163 global $DIC;
164
168 $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context);
169
170 $q = "SELECT COUNT(orgu_ua.orgu_id) AS cnt FROM il_orgu_permissions AS perm
171 INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id
172 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "'
173 and orgu_ua.user_id = " . $DIC->database()->quote($user_id, 'integer') . " AND perm.operations LIKE '%\""
174 . $operation->getOperationId() . "\"%'
175 WHERE perm.parent_id = -1";
176
177 $set = $DIC->database()->query($q);
178 $rec = $DIC->database()->fetchAssoc($set);
179
180 return $rec['cnt'];
181 }
182
183
192 public function getUsersForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $tmp_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX)
193 {
194 global $DIC;
195
196 $tmp_table_name = $this->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string, $context, $tmp_table_name_prefix);
197
198 $q = 'SELECT usr_id FROM ' . $tmp_table_name;
199
200 $user_set = $DIC->database()->query($q);
201
202 $arr_users = array();
203
204 while ($rec = $DIC->database()->fetchAssoc($user_set)) {
205 $arr_users[$rec['usr_id']] = $rec['usr_id'];
206 }
207
208 return $arr_users;
209 }
210
211
217 public function getUsersForUser($user_id)
218 {
219 global $DIC;
220
221 $tmp_orgu_members = $this->buildTempTableOrguMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array());
222
223 $q = "SELECT " . $tmp_orgu_members . ".user_id AS usr_id
224 FROM
225 " . $tmp_orgu_members . "
226 INNER JOIN il_orgu_ua AS orgu_ua_current_user on orgu_ua_current_user.user_id = " . $DIC->database()->quote($user_id, 'integer') . "
227 INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua_current_user.position_id
228 WHERE
229 (
230 /* Identische OrgUnit wie Current User; Nicht Rekursiv; Fixe Position */
231 (orgu_ua_current_user.orgu_id = " . $tmp_orgu_members . ".orgu_id AND auth.scope = 1
232 AND auth.over = " . $tmp_orgu_members . ".user_position_id AND auth.over <> -1
233 )
234 OR
235 /* Identische OrgUnit wie Current User; Nicht Rekursiv; Position egal */
236 (orgu_ua_current_user.orgu_id = " . $tmp_orgu_members . ".orgu_id AND auth.scope = 1 AND auth.over = -1)
237 OR
238 /* Kinder OrgUnit wie Current User */
239 (
240 (
241 " . $tmp_orgu_members . ".orgu_id = orgu_ua_current_user.orgu_id OR
242 " . $tmp_orgu_members . ".tree_path LIKE CONCAT(\"%.\",orgu_ua_current_user.orgu_id ,\".%\")
243 OR
244 " . $tmp_orgu_members . ".tree_path LIKE CONCAT(\"%.\",orgu_ua_current_user.orgu_id )
245 )
246 AND
247 (
248 (
249 (
250 /* Gleiche Position */
251 auth.over = " . $tmp_orgu_members . ".user_position_id AND auth.over <> -1
252 )
253 OR
254 (
255 /* Position Egal */
256 auth.over = -1
257 )
258 )
259 AND auth.scope = 2
260 )
261 )
262 )";
263
264 $user_set = $DIC->database()->query($q);
265
266 $arr_users = array();
267
268 while ($rec = $DIC->database()->fetchAssoc($user_set)) {
269 $arr_users[$rec['usr_id']] = $rec['usr_id'];
270 }
271
272 return $arr_users;
273 }
274
275
283 public function getIlobjectsAndUsersForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT)
284 {
285 global $DIC;
286
290 $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context);
291
292 $tmp_table_name = 'tmp_ilobj_user_matrix_' . $operation->getOperationId();
293
294 $this->buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string, $context, $tmp_table_name);
295
296 $q = 'SELECT * FROM ' . $tmp_table_name;
297
298 $user_set = $DIC->database()->query($q);
299
300 $arr_user_obj = array();
301
302 while ($rec = $DIC->database()->fetchAssoc($user_set)) {
303 $arr_user_obj[] = $rec;
304 }
305
306 return $arr_user_obj;
307 }
308
309
318 public function buildTempTableIlobjectsUserMatrixForUserOperationAndContext($user_id, $org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX)
319 {
320 global $DIC;
321
322 $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context;
323
327 $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context);
328
329 $all_users_for_user = $this->getUsersForUser($GLOBALS['DIC']->user()->getId());
330
331 $tmp_table_objects_specific_perimissions = $this->buildTempTableIlobjectsSpecificPermissionSetForOperationAndContext($org_unit_operation_string, $context, self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS);
332
333 $tmp_table_objects_default_perimissions = $this->buildTempTableIlobjectsDefaultPermissionSetForOperationAndContext($org_unit_operation_string, $context, self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS);
334
335 $tmp_table_orgunit_default_perimissions = $this->buildTempTableIlorgunitDefaultPermissionSetForOperationAndContext($org_unit_operation_string, $context, self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS);
336
337 $tmp_table_course_members = $this->buildTempTableCourseMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, $all_users_for_user);
338
339 $tmp_table_orgu_members = $this->buildTempTableOrguMemberships(self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, $all_users_for_user);
340
341 $tmp_table_orgu_member_path = $this->buildTempTableOrguMemberships('tmp_orgu_members_path', $all_users_for_user);
342
343 if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_"
344 . self::DEFAULT_CONTEXT) {
345 $this->dropTempTable($temporary_table_name);
346 }
347
348 $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . " AS (
349 SELECT DISTINCT user_perm_matrix.perm_for_ref_id, user_perm_matrix.usr_id FROM
350 (
351 SELECT crs.*," . $tmp_table_course_members . ".ref_id," . $tmp_table_course_members . ".usr_id FROM
352 (
353 SELECT * FROM " . $tmp_table_objects_specific_perimissions . "
354 UNION
355 SELECT * FROM " . $tmp_table_objects_default_perimissions . "
356 ) AS crs
357 INNER JOIN " . $tmp_table_course_members . " on " . $tmp_table_course_members . ".ref_id = crs.perm_for_ref_id
358 and (
359 (
360 " . $tmp_table_course_members . ".orgu_id = crs.perm_for_orgu_id AND " . $tmp_table_course_members . ".position_id = crs.perm_over_user_with_position AND perm_orgu_scope = 1
361 )
362 or perm_orgu_scope = 2
363 )
364 UNION
365 SELECT " . $tmp_table_orgunit_default_perimissions . ".*, " . $tmp_table_orgu_members . ".orgu_id AS ref_id, "
366 . $tmp_table_orgu_members . ".user_id FROM " . $tmp_table_orgunit_default_perimissions . "
367 INNER JOIN " . $tmp_table_orgu_members . " on " . $tmp_table_orgu_members . ".orgu_id = "
368 . $tmp_table_orgunit_default_perimissions . ".perm_for_ref_id
369 and (
370 (
371 " . $tmp_table_orgu_members . ".orgu_id = " . $tmp_table_orgunit_default_perimissions . ".perm_for_orgu_id AND "
372 . $tmp_table_orgu_members . ".user_position_id = " . $tmp_table_orgunit_default_perimissions . ".perm_over_user_with_position AND perm_orgu_scope = 1
373 )
374 or perm_orgu_scope = 2
375 )
376
377 ) AS user_perm_matrix
378 INNER JOIN " . $tmp_table_orgu_member_path . " AS path on path.user_id = user_perm_matrix.usr_id
379
380 INNER JOIN il_orgu_ua AS orgu_ua_current_user on orgu_ua_current_user.user_id = " . $DIC->database()->quote($user_id, 'integer') . "
381 INNER JOIN il_orgu_permissions AS perm on perm.position_id = orgu_ua_current_user.position_id AND perm.parent_id = -1
382 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '$context'
383 and perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%'
384
385 AND
386 (
387 /* Identische OrgUnit wie Current User; Nicht Rekursiv; Fixe Position */
388 (orgu_ua_current_user.orgu_id = user_perm_matrix.perm_for_orgu_id AND user_perm_matrix.perm_orgu_scope = 1
389 AND orgu_ua_current_user.position_id = user_perm_matrix.perm_for_position_id AND user_perm_matrix.perm_over_user_with_position <> -1
390 )
391 OR
392 /* Identische OrgUnit wie Current User; Nicht Rekursiv; Position egal */
393 (orgu_ua_current_user.orgu_id = user_perm_matrix.perm_for_orgu_id AND user_perm_matrix.perm_orgu_scope = 1 AND user_perm_matrix.perm_over_user_with_position = -1)
394 OR
395 /* Kinder OrgUnit wie Current User */
396 (
397 orgu_ua_current_user.orgu_id = user_perm_matrix.perm_for_orgu_id
398 AND
399 (
400 path.orgu_id = user_perm_matrix.perm_for_orgu_id OR
401 path.tree_path LIKE CONCAT(\"%.\",user_perm_matrix.perm_for_orgu_id ,\".%\")
402 OR
403 path.tree_path LIKE CONCAT(\"%.\",user_perm_matrix.perm_for_orgu_id )
404 )
405 AND
406 (
407 (
408 (
409 /* Gleiche Position */
410 orgu_ua_current_user.position_id = user_perm_matrix.perm_for_position_id AND user_perm_matrix.perm_over_user_with_position <> -1
411 )
412 OR
413 (
414 /* Position Egal */
415 user_perm_matrix.perm_over_user_with_position = -1
416 )
417 )
418 AND user_perm_matrix.perm_orgu_scope = 2
419 )
420 )
421 )
422 );";
423
424 $DIC->database()->manipulate($q);
425
426 return $temporary_table_name;
427 }
428
429
437 public function buildTempTableIlobjectsSpecificPermissionSetForOperationAndContext($org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS)
438 {
439 global $DIC;
440
441 $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context;
442
446 $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context);
447
448 if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_"
449 . self::DEFAULT_CONTEXT) {
450 $this->dropTempTable($temporary_table_name);
451 }
452
453 $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . "
454 (INDEX i1 (perm_for_ref_id), INDEX i2 (perm_for_orgu_id), INDEX i3 (perm_orgu_scope), INDEX i4 (perm_for_position_id), INDEX i5 (perm_over_user_with_position))
455 AS (
456 SELECT
457 obj_ref.ref_id AS perm_for_ref_id,
458 orgu_ua.orgu_id AS perm_for_orgu_id,
459 auth.scope AS perm_orgu_scope,
460 orgu_ua.position_id AS perm_for_position_id,
461 auth.over AS perm_over_user_with_position
462 FROM
463 il_orgu_permissions AS perm
464 INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id
465 INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua.position_id AND orgu_ua.user_id = " . $GLOBALS['DIC']->user()
466 ->getId() . "
467 INNER JOIN object_reference AS obj_ref ON obj_ref.ref_id = perm.parent_id
468 INNER JOIN object_data AS obj ON obj.obj_id = obj_ref.obj_id AND obj.type = '$context'
469 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '$context'
470 WHERE
471 perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%'
472 );";
473
474 $DIC->database()->manipulate($q);
475
476 return $temporary_table_name;
477 }
478
479
487 public function buildTempTableIlobjectsDefaultPermissionSetForOperationAndContext($org_unit_operation_string = ilOrgUnitOperation::OP_ACCESS_ENROLMENTS, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS)
488 {
489 global $DIC;
490
491 $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context;
492
496 $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context);
497
498 if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_"
499 . self::DEFAULT_CONTEXT) {
500 $this->dropTempTable($temporary_table_name);
501 }
502
503 $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . "
504 (INDEX i1 (perm_for_ref_id), INDEX i2 (perm_for_orgu_id), INDEX i3 (perm_orgu_scope), INDEX i4 (perm_for_position_id),INDEX i5 (perm_over_user_with_position))
505 AS (
506 SELECT
507 obj_ref.ref_id AS perm_for_ref_id,
508 orgu_ua.orgu_id AS perm_for_orgu_id,
509 auth.scope AS perm_orgu_scope,
510 orgu_ua.position_id AS perm_for_position_id,
511 auth.over AS perm_over_user_with_position
512 FROM
513 object_data AS obj
514 INNER JOIN object_reference AS obj_ref ON obj_ref.obj_id = obj.obj_id
515 INNER JOIN il_orgu_permissions AS perm ON perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%' AND perm.parent_id = -1
516 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "'
517 INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id AND orgu_ua.user_id = " . $GLOBALS['DIC']->user()
518 ->getId() . "
519 INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua.position_id
520
521 WHERE
522 obj.type = '" . $context . "'
523 AND (obj_ref.ref_id , orgu_ua.position_id)
524
525 NOT IN (SELECT
526 perm.parent_id, orgu_ua.position_id
527 FROM
528 il_orgu_permissions AS perm
529 INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id
530 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "'
531 WHERE perm.parent_id <> -1)
532 );";
533
534 $DIC->database()->manipulate($q);
535
536 return $temporary_table_name;
537 }
538
539
547 public function buildTempTableIlorgunitDefaultPermissionSetForOperationAndContext($org_unit_operation_string = self::DEFAULT_ORG_UNIT_OPERATION, $context = self::DEFAULT_CONTEXT, $temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS)
548 {
549 global $DIC;
550
551 $temporary_table_name = $temporary_table_name_prefix . "_" . $org_unit_operation_string . "_" . $context;
555 $operation = ilOrgUnitOperationQueries::findByOperationString($org_unit_operation_string, $context);
556
557 if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS . "_" . self::DEFAULT_ORG_UNIT_OPERATION . "_"
558 . self::DEFAULT_CONTEXT) {
559 $this->dropTempTable($temporary_table_name);
560 }
561
562 $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . "
563 (INDEX i1 (perm_for_ref_id), INDEX i2 (perm_for_orgu_id), INDEX i3 (perm_orgu_scope), INDEX i4 (perm_for_position_id), INDEX i5 (perm_over_user_with_position))
564 AS (
565 SELECT
566 orgu_ua.orgu_id AS perm_for_ref_id, /* Table has to be identical to the other Permission For Operation And Context-Tables! */
567 orgu_ua.orgu_id AS perm_for_orgu_id,
568 auth.scope AS perm_orgu_scope,
569 orgu_ua.position_id AS perm_for_position_id,
570 auth.over AS perm_over_user_with_position
571 FROM
572 il_orgu_permissions AS perm
573 INNER JOIN il_orgu_ua AS orgu_ua ON orgu_ua.position_id = perm.position_id AND perm.parent_id = -1 AND orgu_ua.user_id = "
574 . $GLOBALS['DIC']->user()->getId() . "
575 INNER JOIN il_orgu_authority AS auth ON auth.position_id = orgu_ua.position_id
576 INNER JOIN il_orgu_op_contexts AS contexts on contexts.id = perm.context_id AND contexts.context = '" . $context . "'
577 WHERE
578 perm.operations LIKE '%\"" . $operation->getOperationId() . "\"%'
579 );";
580
581 $DIC->database()->manipulate($q);
582
583 return $temporary_table_name;
584 }
585
586
593 public function buildTempTableCourseMemberships($temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, array $only_courses_of_user_ids = array())
594 {
595 global $DIC;
596
597 $temporary_table_name = $temporary_table_name_prefix . "_user_id_" . $DIC->user()->getId();
598
599 if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS . "_user_id_" . $DIC->user()->getId()
600 || count($only_courses_of_user_ids) > 0) {
601 $this->dropTempTable($temporary_table_name);
602 }
603
604 $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . "
605 (INDEX i1(ref_id), INDEX i2 (usr_id), INDEX i3 (position_id), INDEX i4 (orgu_id))
606 AS (
607 SELECT crs_members_crs_ref.ref_id, crs_members.usr_id, orgu_ua.position_id, orgu_ua.orgu_id
608 FROM (
609 SELECT obj_id, usr_id FROM obj_members WHERE member = 1
610 AND " . $DIC->database()->in('obj_members.usr_id', $only_courses_of_user_ids, false, 'integer') . "
611 UNION
612 SELECT obj_id, usr_id FROM crs_waiting_list
613 WHERE " . $DIC->database()->in('crs_waiting_list.usr_id', $only_courses_of_user_ids, false, 'integer') . "
614 UNION
615 SELECT obj_id, usr_id FROM il_subscribers
616 WHERE " . $DIC->database()->in('il_subscribers.usr_id', $only_courses_of_user_ids, false, 'integer') . "
617 ) AS crs_members
618 INNER JOIN object_reference AS crs_members_crs_ref on crs_members_crs_ref.obj_id = crs_members.obj_id
619 INNER JOIN il_orgu_ua AS orgu_ua on orgu_ua.user_id = crs_members.usr_id
620 );";
621
622 $DIC->database()->manipulate($q);
623
624 return $temporary_table_name;
625 }
626
627
634 public function buildTempTableOrguMemberships($temporary_table_name_prefix = self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array $only_orgus_of_user_ids = array())
635 {
636 global $DIC;
637
638 $temporary_table_name = $temporary_table_name_prefix . "_user_id_" . $DIC->user()->getId();
639
640 if ($temporary_table_name != self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS . "_user_id_" . $DIC->user()->getId()
641 || count($only_orgus_of_user_ids) > 0) {
642 $this->dropTempTable($temporary_table_name);
643 }
644
645 $q = "CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . "
646 (INDEX i1(orgu_id), INDEX i2 (tree_path), INDEX i3 (tree_child), INDEX i4 (tree_parent), INDEX i5 (tree_lft), INDEX i6 (tree_rgt), INDEX i7 (user_position_id), INDEX i8 (user_id))
647 AS (
648 SELECT orgu_ua.orgu_id AS orgu_id,
649 tree_orgu.path AS tree_path,
650 tree_orgu.child AS tree_child,
651 tree_orgu.parent AS tree_parent,
652 tree_orgu.lft AS tree_lft,
653 tree_orgu.rgt AS tree_rgt,
654 orgu_ua.position_id AS user_position_id,
655 orgu_ua.user_id AS user_id
656 FROM
657 il_orgu_ua AS orgu_ua
658 INNER JOIN object_reference AS obj_ref on obj_ref.ref_id = orgu_ua.orgu_id AND obj_ref.deleted is null
659 LEFT JOIN tree AS tree_orgu ON tree_orgu.child = orgu_ua.orgu_id";
660
661 if (count($only_orgus_of_user_ids) > 0) {
662 $q .= " WHERE " . $DIC->database()->in('orgu_ua.user_id', $only_orgus_of_user_ids, false, 'integer') . " ";
663 }
664
665 $q .= ");";
666
667 $DIC->database()->manipulate($q);
668
669 return $temporary_table_name;
670 }
671
672
678 public function dropTempTable($temporary_table_name)
679 {
680 global $DIC;
681
682 $q = "DROP TABLE IF EXISTS " . $temporary_table_name;
683 $DIC->database()->manipulate($q);
684
685 return true;
686 }
687}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Class ilMyStaffAccess.
hasCurrentUserAccessToLearningProgressInObject($ref_id=0)
dropTempTable($temporary_table_name)
buildTempTableOrguMemberships($temporary_table_name_prefix=self::TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS, array $only_orgus_of_user_ids=array())
hasCurrentUserAccessToUser($usr_id=0)
const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX
const TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS
const TMP_DEFAULT_TABLE_NAME_PREFIX_ORGU_MEMBERS
countOrgusOfUserWithAtLeastOneOperation($user_id)
static $orgu_users_of_current_user_show_staff_permission
const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_SPEC_PERMISSIONS
getUsersForUserOperationAndContext($user_id, $org_unit_operation_string=self::DEFAULT_ORG_UNIT_OPERATION, $context=self::DEFAULT_CONTEXT, $tmp_table_name_prefix=self::TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_USER_MATRIX)
const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_ORGU_DEFAULT_PERMISSIONS
const TMP_DEFAULT_TABLE_NAME_PREFIX_IL_OBJ_DEFAULT_PERMISSIONS
hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()
buildTempTableCourseMemberships($temporary_table_name_prefix=self::TMP_DEFAULT_TABLE_NAME_PREFIX_CRS_MEMBERS, array $only_courses_of_user_ids=array())
Class ilObjectAccess.
static findByOperationString($operation_string, $context_name)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $DIC
Definition: saml.php:7