ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjectOwnershipManagementTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
28  protected ilTree $tree;
32 
33  protected int $user_id;
34 
35  public function __construct(?object $parent_obj, string $parent_cmd, int $user_id)
36  {
37  global $DIC;
38 
39  $this->ctrl = $DIC['ilCtrl'];
40  $this->lng = $DIC['lng'];
41  $this->access = $DIC['ilAccess'];
42  $this->tree = $DIC['tree'];
43  $this->obj_definition = $DIC['objDefinition'];
44  $this->ui_factory = $DIC['ui.factory'];
45  $this->ui_renderer = $DIC['ui.renderer'];
46 
47  $this->user_id = $user_id;
48  $this->setId('objownmgmt'); // #16373
49 
50  parent::__construct($parent_obj, $parent_cmd);
51 
52  $this->addColumn($this->lng->txt('title'), 'title');
53  $this->addColumn($this->lng->txt('path'), 'path');
54  $this->addColumn($this->lng->txt('action'));
55 
56  $this->setFormAction($this->ctrl->getFormAction($parent_obj, $parent_cmd));
57  $this->setRowTemplate('tpl.obj_ownership_row.html', 'Services/Object');
58  $this->setDisableFilterHiding();
59 
60  $this->setDefaultOrderField('title');
61  $this->setDefaultOrderDirection('asc');
62  }
63 
64  public function initItems(array $data): void
65  {
66  $process_arr = [];
67  $is_admin = false;
68  $a_type = '';
69  if ($data === []) {
70  return;
71  }
72 
73  if (!$this->user_id) {
74  $is_admin = $this->access->checkAccess('visible', '', SYSTEM_FOLDER_ID);
75  }
76 
77  foreach ($data as $id => $item) {
78  // workspace objects won't have references
80  if ($refs) {
81  foreach ($refs as $ref_id) {
82  // objects in trash are hidden
83  if (!$this->tree->isDeleted($ref_id)) {
84  if ($this->user_id) {
85  $readable = $this->access->checkAccessOfUser(
86  $this->user_id,
87  'read',
88  '',
89  $ref_id,
90  $a_type
91  );
92  } else {
93  $readable = $is_admin;
94  }
95 
96  $process_arr[$ref_id] = [
97  'obj_id' => $id,
98  'ref_id' => $ref_id,
99  'type' => ilObject::_lookupType($id),
100  'title' => $item,
101  'path' => $this->buildPath($ref_id),
102  'readable' => $readable
103  ];
104  }
105  }
106  }
107  }
108 
109  $this->setData($process_arr);
110  }
111 
112  protected function fillRow(array $set): void
113  {
114  $icon = $this->ui_factory->symbol()->icon()->standard($set['type'], $set['title'], Standard::MEDIUM);
115  $this->tpl->setVariable('ICON', $this->ui_renderer->render($icon));
116 
117  $this->tpl->setVariable('TITLE', strip_tags($set['title'], ilObjectGUI::ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION));
118  $this->tpl->setVariable('PATH', $set['path']);
119 
120  if ($set['readable'] && !$this->isParentReadOnly()) {
121  $this->tpl->setCurrentBlock('actions');
122  $this->tpl->setVariable('ACTIONS', $this->buildActions($set['ref_id'], $set['type']));
123  $this->tpl->parseCurrentBlock();
124  }
125  }
126 
127  protected function buildActions(int $ref_id, string $type): string
128  {
129  $this->ctrl->setParameter($this->parent_obj, 'ownid', $ref_id);
130 
131  $actions = [];
132  $actions[] = $this->ui_factory->link()->standard(
133  $this->lng->txt('show'),
134  ilLink::_getLink($ref_id, $type)
135  )->withOpenInNewViewport(true);
136 
137  $actions[] = $this->ui_factory->link()->standard(
138  $this->lng->txt('move'),
139  $this->ctrl->getLinkTargetByClass(get_class($this->parent_obj), 'move')
140  );
141 
142  $actions[] = $this->ui_factory->link()->standard(
143  $this->lng->txt('change_owner'),
144  $this->ctrl->getLinkTargetByClass(get_class($this->parent_obj), 'changeOwner')
145  );
146 
147  if (!in_array($type, ['crsr', 'catr', 'grpr']) && $this->obj_definition->allowExport($type)) {
148  $actions[] = $this->ui_factory->link()->standard(
149  $this->lng->txt('export'),
150  $this->ctrl->getLinkTargetByClass(get_class($this->parent_obj), 'export')
151  );
152  }
153 
154  $actions[] = $this->ui_factory->link()->standard(
155  $this->lng->txt('delete'),
156  $this->ctrl->getLinkTargetByClass(get_class($this->parent_obj), 'delete')
157  );
158 
159  $actions_dropdown = $this->ui_factory->dropdown()->standard($actions)
160  ->withLabel($this->lng->txt('actions'));
161 
162  $this->ctrl->setParameter($this->parent_obj, 'ownid', '');
163 
164  return $this->ui_renderer->render($actions_dropdown);
165  }
166 
167  protected function buildPath(int $ref_id): string
168  {
169  $path = '...';
170  $counter = 0;
171  $path_full = $this->tree->getPathFull($ref_id);
172  foreach ($path_full as $data) {
173  if (++$counter < (count($path_full) - 2)) {
174  continue;
175  }
176  if ($ref_id != $data['ref_id']) {
177  $path .= ' &raquo; ' . $data['title'];
178  }
179  }
180 
181  return $path;
182  }
183 
184  protected function isParentReadOnly(): bool
185  {
186  if (!method_exists($this->parent_obj, 'isReadOnly')) {
187  return false;
188  }
189  return $this->parent_obj->isReadOnly();
190  }
191 }
setData(array $a_data)
An entity that renders components to a string output.
Definition: Renderer.php:30
__construct(?object $parent_obj, string $parent_cmd, int $user_id)
setFormAction(string $a_form_action, bool $a_multipart=false)
static _getAllReferences(int $id)
get all reference ids for object ID
setDisableFilterHiding(bool $a_val=true)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
setId(string $a_val)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
const ALLOWED_TAGS_IN_TITLE_AND_DESCRIPTION
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
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)
static _lookupType(int $id, bool $reference=false)