ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilUserRoleStartingPointTableGUI.php
Go to the documentation of this file.
1 <?php
2 
24 {
25  public const TABLE_POSITION_USER_CHOOSES = -1;
26  public const TABLE_POSITION_DEFAULT = 9999;
27 
28  protected ilLogger $log;
30 
31  public function __construct(object $a_parent_obj)
32  {
33  global $DIC;
34 
35  $ilCtrl = $DIC['ilCtrl'];
36  $lng = $DIC['lng'];
37  $this->rbacreview = $DIC->rbac()->review();
38 
39  $this->log = ilLoggerFactory::getLogger("user");
40 
41  $this->parent_obj = $a_parent_obj;
42 
43  $this->setId("usrrolesp");
44 
45  parent::__construct($a_parent_obj);
46 
47  $this->getItems();
48 
49  $this->setLimit(9999);
50  $this->setTitle($lng->txt("user_role_starting_point"));
51 
52  $this->addColumn($lng->txt("user_order"));
53  $this->addColumn($lng->txt("criteria"));
54  $this->addColumn($lng->txt("starting_page"));
55  $this->addColumn($lng->txt("actions"));
56  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
57  $this->setRowTemplate("tpl.user_role_starting_point_row.html", "Services/User");
58  $this->addCommandButton("saveOrder", $lng->txt("save_order"));
59 
60  $this->setExternalSorting(true);
61  }
62 
66  public function getItems(): void
67  {
68  global $DIC;
69 
70  $lng = $DIC['lng'];
71 
72  $dc = new ilObjectDataCache();
73 
74  $valid_points = ilUserUtil::getPossibleStartingPoints();
75 
76  $status = (ilUserUtil::hasPersonalStartingPoint() ? $lng->txt("yes") : $lng->txt("no"));
77 
78  $result = [];
79  $result[] = array(
80  "id" => "user",
81  "criteria" => $lng->txt("user_chooses_starting_page"),
82  "starting_page" => $status,
83  "starting_position" => self::TABLE_POSITION_USER_CHOOSES
84  );
85 
87 
88  foreach ($points as $point) {
89  $starting_point = $point['starting_point'];
90  $position = $point['position'];
91  $sp_text = $valid_points[$starting_point] ?? "";
92 
93  if ($starting_point == ilUserUtil::START_REPOSITORY_OBJ && $point['starting_object']) {
94  $object_id = ilObject::_lookupObjId($point['starting_object']);
95  $type = $dc->lookupType($object_id);
96  $title = $dc->lookupTitle($object_id);
97  $sp_text = $this->lng->txt("obj_" . $type) . " <i>\"" . $title . "\"</i> [" . $point['starting_object'] . "]";
98  }
99 
100  if ($point['rule_type'] == ilStartingPoint::ROLE_BASED) {
101  $options = unserialize($point['rule_options'], ['allowed_classes' => false]);
102 
103  $role_obj = ilObjectFactory::getInstanceByObjId($options['role_id'], false);
104  if (!($role_obj instanceof \ilObjRole)) {
105  continue;
106  }
107 
108  $result[] = array(
109  "id" => $point['id'],
110  "criteria" => $role_obj->getTitle(),
111  "starting_page" => $sp_text,
112  "starting_position" => (int) $position,
113  "role_id" => $role_obj->getId()
114  );
115  }
116  }
117 
118  $default_sp = ilUserUtil::getStartingPoint();
119  $starting_point = $valid_points[$default_sp];
120  if ($default_sp == ilUserUtil::START_REPOSITORY_OBJ) {
121  $reference_id = ilUserUtil::getStartingObject();
122 
123  $object_id = ilObject::_lookupObjId($reference_id);
124  $type = $dc->lookupType($object_id);
125  $title = $dc->lookupTitle($object_id);
126  $starting_point = $this->lng->txt("obj_" . $type) . " " . "<i>\"" . $title . "\" ($reference_id)</i>";
127  }
128 
129  $result[] = array(
130  "id" => "default",
131  "criteria" => $lng->txt("default"),
132  "starting_page" => $starting_point,
133  "starting_position" => self::TABLE_POSITION_DEFAULT
134  );
135 
136  $result = ilArrayUtil::sortArray($result, "starting_position", "asc", true);
137 
138  $result = ilStartingPoint::reArrangePositions($result);
139 
140  $this->setData($result);
141  }
142 
143  protected function fillRow(array $a_set): void // Missing array type.
144  {
145  global $DIC;
146 
147  $lng = $DIC['lng'];
148  $ilCtrl = $DIC['ilCtrl'];
149 
150  $list = new ilAdvancedSelectionListGUI();
151  $list->setListTitle($lng->txt("actions"));
152 
153  $ilCtrl->setParameter($this->getParentObject(), "spid", $a_set['id']);
154 
155 
156  if ($a_set['id'] > 0 && $a_set['id'] != 'default' && $a_set['id'] != 'user') {
158  $ilCtrl->setParameter($this->getParentObject(), "rolid", $a_set["role_id"]);
159  }
160 
161  $list->setId($a_set["id"]);
162 
163  $edit_url = $ilCtrl->getLinkTarget($this->getParentObject(), "initRoleStartingPointForm");
164  $list->addItem($lng->txt("edit"), "", $edit_url);
165  $delete_url = $ilCtrl->getLinkTarget($this->getParentObject(), "confirmDeleteStartingPoint");
166  $list->addItem($lng->txt("delete"), "", $delete_url);
167  $this->tpl->setVariable("VAL_ID", "position[" . $a_set['id'] . "]");
168  $this->tpl->setVariable("VAL_POS", $a_set["starting_position"]);
169 
170  $parent_title = "";
171  if (ilObject::_lookupType($a_set["role_id"]) == "role") {
172  $ref_id = $this->rbacreview->getObjectReferenceOfRole($a_set["role_id"]);
173  if ($ref_id != ROLE_FOLDER_ID) {
174  $parent_title = " (" . ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)) . ")";
175  }
176  }
177  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("has_role") . ": " .
178  ilObjRole::_getTranslation($a_set["criteria"]) . $parent_title);
179  } else {
180  if ($a_set['id'] == "default") {
181  $ilCtrl->setParameter($this->getParentObject(), "rolid", "default");
182  $edit_url = $ilCtrl->getLinkTarget($this->getParentObject(), "initRoleStartingPointForm");
183  } else {
184  $ilCtrl->setParameter($this->getParentObject(), "rolid", "user");
185  $edit_url = $ilCtrl->getLinkTarget($this->getParentObject(), "initUserStartingPointForm");
186  }
187 
188  $list->addItem($lng->txt("edit"), "", $edit_url);
189 
190  $this->tpl->setVariable("HIDDEN", "hidden");
191 
192  $this->tpl->setVariable("TXT_TITLE", $a_set["criteria"]);
193  }
194 
195  $this->tpl->setVariable("TXT_PAGE", $a_set["starting_page"]);
196 
197  $this->tpl->setVariable("ACTION", $list->getHTML());
198  }
199 }
Class ilObjRole.
setData(array $a_data)
static getLogger(string $a_component_id)
Get component logger.
static getStartingPoints()
Get all the starting points in database.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
$type
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static reArrangePositions(array $a_items)
static getStartingPoint()
Get current starting point setting.
ilLanguage $lng
setId(string $a_val)
static hasPersonalStartingPoint()
Can starting point be personalized?
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
setExternalSorting(bool $a_val)
static getPossibleStartingPoints(bool $a_force_all=false)
Get all valid starting points.
$ref_id
Definition: ltiauth.php:67
static _lookupTitle(int $obj_id)
static _getTranslation(string $a_role_title)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
static getStartingObject()
Get ref id of starting object.
const ROLE_FOLDER_ID
Definition: constants.php:34
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
const START_REPOSITORY_OBJ
static _lookupType(int $id, bool $reference=false)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)