53 $this->logger = $DIC->logger()->crs();
75 $this->ref_id = $a_ref_id;
83 $this->obj_id = $a_obj_id;
91 return $this->container_type;
95 $this->container_type =
$a_type;
109 $this->title = $a_title;
117 $this->description = $a_desc;
125 $this->unique_field = $a_uni;
129 return $this->unique_field;
141 $tree = $DIC[
'tree'];
143 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
145 $conditions = array();
146 foreach ($condition_data as $condition) {
147 if (
$tree->isDeleted($condition[
'target_ref_id'])) {
150 $conditions[] = $condition;
152 return count($conditions) ? $conditions : array();
155 public function delete()
159 $ilDB = $DIC[
'ilDB'];
161 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
164 $query =
"DELETE FROM object_data WHERE obj_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" ";
167 $query =
"DELETE FROM crs_groupings " .
168 "WHERE crs_grp_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" ";
173 $condh->deleteByObjId($this->
getId());
180 public function create($a_course_ref_id, $a_course_id)
185 $ilDB = $DIC[
'ilDB'];
189 $query =
"INSERT INTO object_data " .
190 "(obj_id, type,title,description,owner,create_date,last_update) " .
193 $ilDB->quote($this->
getId(),
"integer") .
"," .
194 $ilDB->quote($this->type,
"text") .
"," .
202 $ilDB->manipulate($query);
205 $query =
"INSERT INTO crs_groupings (crs_grp_id,crs_ref_id,crs_id,unique_field) " .
207 $ilDB->quote($this->
getId(),
'integer') .
", " .
208 $ilDB->quote($a_course_ref_id,
'integer') .
", " .
209 $ilDB->quote($a_course_id,
'integer') .
", " .
214 return $this->
getId();
221 $ilDB = $DIC[
'ilDB'];
225 $query =
"UPDATE object_data " .
226 "SET title = " .
$ilDB->quote($this->
getTitle(),
'text') .
", " .
228 "WHERE obj_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" " .
229 "AND type = " .
$ilDB->quote($this->
getType(),
'text') .
" ";
233 $query =
"UPDATE crs_groupings " .
235 "WHERE crs_grp_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" ";
239 $query =
"UPDATE conditions " .
241 "WHERE trigger_obj_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" " .
242 "AND trigger_type = 'crsg'";
253 if ($a_course_id == $condition_data[
'target_obj_id']) {
264 $ilObjDataCache = $DIC[
'ilObjDataCache'];
265 $ilDB = $DIC[
'ilDB'];
267 $query =
"SELECT * FROM object_data " .
268 "WHERE obj_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" ";
276 $query =
"SELECT * FROM crs_groupings " .
277 "WHERE crs_grp_id = " .
$ilDB->quote($this->
getId(),
'integer') .
" ";
284 $this->
setContainerType($ilObjDataCache->lookupType($this->getContainerObjId()));
294 $ilAccess = $DIC[
'ilAccess'];
295 $tree = $DIC[
'tree'];
299 $found_invisible =
false;
300 foreach ($tmp_grouping_obj->getAssignedItems() as $condition) {
301 if (!$ilAccess->checkAccess(
'write',
'', $condition[
'target_ref_id'])) {
302 $found_invisible =
true;
306 return $found_invisible ? false :
true;
321 $ilObjDataCache = $DIC[
'ilObjDataCache'];
322 $ilAccess = $DIC[
'ilAccess'];
323 $ilDB = $DIC[
'ilDB'];
325 $container_type = $ilObjDataCache->lookupType($a_obj_id) ==
'grp' ?
'grp' :
'crs';
329 $query =
"SELECT * FROM object_data WHERE type = 'crsg' ORDER BY title";
331 $groupings = array();
333 $groupings[] =
$row->obj_id;
337 foreach ($groupings as $grouping_id) {
341 if ($tmp_grouping_obj->getContainerType() != $container_type) {
345 if ($tmp_grouping_obj->getContainerObjId() == $a_obj_id) {
346 $visible_groupings[] = $grouping_id;
350 if (count($items = $tmp_grouping_obj->getAssignedItems())) {
351 foreach ($items as $condition_data) {
352 if ($ilAccess->checkAccess(
'write',
'', $condition_data[
'target_ref_id'])) {
353 $visible_groupings[] = $grouping_id;
359 return $visible_groupings ? $visible_groupings : array();
362 public function assign($a_crs_ref_id, $a_course_id)
371 public function deassign($a_crs_ref_id, $a_course_id)
373 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
379 if ($this->getCountAssignedCourses() == 2) {
380 $condh->deleteByObjId($this->
getId());
386 if ($cond_data[
'target_ref_id'] == $a_crs_ref_id
and 387 $cond_data[
'target_obj_id'] == $a_course_id) {
388 $condh->deleteCondition($cond_data[
'id']);
401 $this->logger->debug(
'Start cloning membership limitations...');
409 $this->logger->dump($target_ref_id);
410 $this->logger->dump($target_obj_id);
412 if (!$target_ref_id || !$target_obj_id) {
413 $this->logger->debug(
'No target ref_id found.');
417 $new_grouping = new \ilObjCourseGrouping();
418 $new_grouping->setTitle($this->
getTitle());
420 $new_grouping->setContainerRefId($target_ref_id);
421 $new_grouping->setContainerObjId($target_obj_id);
424 $new_grouping->create($target_ref_id, $target_obj_id);
427 if (!$obj_instance instanceof \
ilObject) {
428 $this->logger->info(
'Cannot create object instance for membership limitation');
431 $limitation_items = self::_getGroupingItems($obj_instance);
432 $this->logger->dump($limitation_items);
434 foreach ($limitation_items as $item_ref_id) {
435 $target_item_ref_id = 0;
436 $target_item_obj_id = 0;
437 if (array_key_exists($item_ref_id, $mappings) && $mappings[$item_ref_id]) {
438 $target_item_ref_id = $mappings[$item_ref_id];
441 if (!$target_item_ref_id || !$target_item_obj_id) {
442 $this->logger->info(
'No mapping found for: ' . $item_ref_id);
445 $new_grouping->assign($target_item_ref_id, $target_item_obj_id);
455 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
458 $tmp_condh->enableAutomaticValidation(
false);
460 $tmp_condh->setTargetRefId($a_target_ref_id);
461 $tmp_condh->setTargetObjId($a_target_obj_id);
463 $tmp_condh->setTriggerRefId(0);
464 $tmp_condh->setTriggerObjId($this->
getId());
465 $tmp_condh->setTriggerType(
'crsg');
466 $tmp_condh->setOperator(
'not_member');
469 if (!$tmp_condh->checkExists()) {
470 $tmp_condh->storeCondition();
482 $ilDB = $DIC[
'ilDB'];
486 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
489 $condh->deleteByObjId($grouping_id);
492 $query =
"DELETE FROM crs_groupings " .
493 "WHERE crs_id = " .
$ilDB->quote($a_course_id,
'integer') .
" ";
507 $ilDB = $DIC[
'ilDB'];
509 $query =
"SELECT * FROM crs_groupings " .
510 "WHERE crs_id = " .
$ilDB->quote($a_course_id,
'integer') .
" ";
514 $groupings[] =
$row->crs_grp_id;
516 return $groupings ? $groupings : array();
519 public static function _checkCondition($trigger_obj_id, $operator, $value, $a_usr_id = 0)
537 $tree = $DIC[
'tree'];
539 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
543 if ($condition[
'trigger_type'] ==
'crsg') {
545 if (
$tree->isDeleted($target_condition[
'target_ref_id'])) {
548 $course_ids[] = array(
'id' => $target_condition[
'target_obj_id'],
549 'unique' => $target_condition[
'value']);
553 return $course_ids ? $course_ids : array();
563 return self::$assignedObjects ? self::$assignedObjects : array();
572 $tree = $DIC[
'tree'];
574 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
576 $user_id = is_null($a_user_id) ?
$ilUser->getId() : $a_user_id;
579 $trigger_ids = array();
581 $container_obj->getRefId(),
582 $container_obj->getId(),
583 $container_obj->getType()
585 if ($condition[
'operator'] ==
'not_member') {
586 $trigger_ids[] = $condition[
'trigger_obj_id'];
590 if (!count($trigger_ids)) {
593 $matriculation_message = $assigned_message =
'';
594 self::$assignedObjects = array();
595 foreach ($trigger_ids as $trigger_id) {
598 if (
$tree->isDeleted($condition[
'target_ref_id'])) {
601 if ($condition[
'operator'] ==
'not_member') {
602 switch ($condition[
'value']) {
603 case 'matriculation':
605 if (!$matriculation_message) {
606 $matriculation_message =
$lng->txt(
'crs_grp_matriculation_required');
610 if ($container_obj->getType() ==
'crs') {
611 include_once(
'Modules/Course/classes/class.ilCourseParticipants.php');
613 if ($members->isGroupingMember($user_id, $condition[
'value'])) {
614 if (!$assigned_message) {
615 self::$assignedObjects[] = $condition[
'target_obj_id'];
616 $assigned_message =
$lng->txt(
'crs_grp_already_assigned');
619 } elseif ($container_obj->getType() ==
'grp') {
620 include_once(
'Modules/Group/classes/class.ilGroupParticipants.php');
622 if ($members->isGroupingMember($user_id, $condition[
'value'])) {
623 if (!$assigned_message) {
624 self::$assignedObjects[] = $condition[
'target_obj_id'];
625 $assigned_message =
$lng->txt(
'grp_grp_already_assigned');
630 if (!$assigned_message) {
631 self::$assignedObjects[] = $condition[
'target_obj_id'];
632 $assigned_message =
$lng->txt(
'crs_grp_already_assigned');
639 if ($matriculation_message) {
640 $container_obj->appendMessage($matriculation_message);
642 } elseif ($assigned_message) {
643 $container_obj->appendMessage($assigned_message);
660 $tree = $DIC[
'tree'];
661 $ilObjDataCache = $DIC[
'ilObjDataCache'];
662 $ilAccess = $DIC[
'ilAccess'];
663 $tree = $DIC[
'tree'];
665 include_once
'./Services/Conditions/classes/class.ilConditionHandler.php';
667 $trigger_ids = array();
669 $container_obj->getRefId(),
670 $container_obj->getId(),
671 $container_obj->getType()
673 if ($condition[
'operator'] ==
'not_member') {
674 $trigger_ids[] = $condition[
'trigger_obj_id'];
677 if (!count($trigger_ids)) {
680 $hash_table = array();
681 foreach ($trigger_ids as $trigger_id) {
684 if (
$tree->isDeleted($condition[
'target_ref_id'])) {
688 if ($condition[
'operator'] ==
'not_member') {
689 if (!$hash_table[$condition[
'target_ref_id']]) {
690 $items[] = $condition[
'target_ref_id'];
692 $hash_table[$condition[
'target_ref_id']] =
true;
696 return $items ? $items : array();
static _getPersistedConditionsOfTrigger($a_trigger_obj_type, $a_trigger_id)
Get all persisted conditions of trigger object Note: This only gets persisted conditions NOT (dynamic...
static lookupMatriculation($a_usr_id)
Lookup matriculation.
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
if(!array_key_exists('StateId', $_REQUEST)) $id
static getAssignedObjects()
Alway call checkGroupingDependencies before.
static _getVisibleGroupings($a_obj_id)
_checkAccess($grouping_id)
__construct($a_id=0)
Constructor public.
assign($a_crs_ref_id, $a_course_id)
static _checkCondition($trigger_obj_id, $operator, $value, $a_usr_id=0)
static _deleteAll($a_course_id)
static _getInstance($a_copy_id)
Get instance of copy wizard options.
foreach($_POST as $key=> $value) $res
static _getGroupingCourseIds($a_course_ref_id, $a_course_id)
Get all ids of courses that are grouped with another course static.
__addCondition($a_target_ref_id, $a_target_obj_id)
static _lookupObjId($a_id)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _checkGroupingDependencies(&$container_obj, $a_user_id=null)
setContainerObjId($a_obj_id)
INTERNAL CLASS: Please do not use in consumer code.
setContainerRefId($a_ref_id)
static _getGroupingItems($container_obj)
Get courses/groups that are assigned to the same membership limitation.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getPersistedConditionsOfTarget($a_target_ref_id, $a_target_obj_id, $a_target_type="")
get all persisted conditions of target object
static _getGroupings($a_course_id)
create($a_course_ref_id, $a_course_id)
_isMember($a_user_id, $a_ref_id, $a_field='')
cloneGrouping($a_target_id, $a_copy_id)
setContainerType($a_type)
deassign($a_crs_ref_id, $a_course_id)