ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilWebResourceLinkTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
30  protected bool $editable = false;
31 
32  protected int $link_sort_mode;
33  protected bool $link_sort_enabled = false;
34 
37 
40 
44  public function __construct(
45  ?object $a_parent_obj,
46  string $a_parent_cmd,
47  bool $a_sorting = false
48  ) {
49  global $DIC;
50 
51  parent::__construct($a_parent_obj, $a_parent_cmd);
52 
53  $this->renderer = $DIC->ui()->renderer();
54  $this->uiFactory = $DIC->ui()->factory();
55 
56  $this->access = $DIC->access();
57  $this->web_link_repo = new ilWebLinkDatabaseRepository(
58  $this->getParentObject()->getObject()->getId()
59  );
60 
61  // Initialize
62  if ($this->access->checkAccess(
63  'write',
64  '',
65  $this->getParentObject()->getObject()->getRefId()
66  )) {
67  $this->editable = true;
68  }
69 
70  $this->enableLinkSorting($a_sorting);
71 
72  $this->setTitle($this->lng->txt('web_resources'));
73 
74  if ($this->isEditable()) {
75  if ($this->isLinkSortingEnabled()) {
76  $this->setLimit(9999);
77  $this->addColumn($this->lng->txt('position'), '', '10px');
78  $this->addColumn($this->lng->txt('title'), '', '90%');
79  $this->addColumn('', '', '10%');
80 
81  $this->addMultiCommand(
82  'saveSorting',
83  $this->lng->txt('sorting_save')
84  );
85  } else {
86  $this->addColumn($this->lng->txt('title'), '', '90%');
87  $this->addColumn('', '', '10%');
88  }
89  } else {
90  $this->addColumn($this->lng->txt('title'), '', '100%');
91  }
92 
93  $this->setEnableHeader(true);
94  $this->setFormAction(
95  $this->ctrl->getFormAction($this->getParentObject())
96  );
97  $this->setRowTemplate("tpl.webr_link_row.html", 'components/ILIAS/WebResource');
98  $this->setEnableTitle(true);
99  $this->setEnableNumInfo(false);
100  }
101 
102  public function enableLinkSorting(bool $a_status): void
103  {
104  $this->link_sort_enabled = $a_status;
105  }
106 
107  public function isLinkSortingEnabled(): bool
108  {
110  }
111 
112  public function parse(): void
113  {
114  $rows = [];
115 
116  $items = $this->web_link_repo->getAllItemsAsContainer(true)
117  ->sort()
118  ->getItems();
119 
120  $counter = 1;
121  foreach ($items as $item) {
122  $tmp['position'] = ($counter++) * 10;
123  $tmp['title'] = $item->getTitle();
124  $tmp['description'] = $item->getDescription();
125  $tmp['target'] = $item->getTarget();
126  $tmp['link_id'] = $item->getLinkId();
127  $tmp['internal'] = $item->isInternal();
128 
129  $rows[] = $tmp;
130  }
131  $this->setData($rows);
132  }
133 
134  protected function fillRow(array $a_set): void
135  {
136  $this->ctrl->setParameterByClass(
137  get_class($this->getParentObject()),
138  'link_id',
139  $a_set['link_id']
140  );
141 
142  $this->tpl->setVariable('TITLE', $a_set['title']);
143  if ($a_set['description']) {
144  $this->tpl->setVariable('DESCRIPTION', $a_set['description']);
145  }
146  // $this->tpl->setVariable('TARGET',$a_set['target']);
147  $this->tpl->setVariable(
148  'TARGET',
149  $this->ctrl->getLinkTarget($this->parent_obj, "callLink")
150  );
151 
152  if (!$a_set['internal']) {
153  $this->tpl->setVariable('FRAME', ' target="_blank"');
154  $this->tpl->touchBlock('noopener');
155  }
156 
157  if (!$this->isEditable()) {
158  return;
159  }
160 
161  if ($this->isLinkSortingEnabled()) {
162  $this->tpl->setVariable('VAL_POS', $a_set['position']);
163  $this->tpl->setVariable('VAL_ITEM', $a_set['link_id']);
164  }
165 
166  $dropDownItems = array(
167  $this->uiFactory->button()->shy(
168  $this->lng->txt('edit'),
169  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'editLink')
170  ),
171  $this->uiFactory->button()->shy(
172  $this->lng->txt('webr_deactivate'),
173  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'deactivateLink')
174  ),
175  $this->uiFactory->button()->shy(
176  $this->lng->txt('delete'),
177  $this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()), 'confirmDeleteLink')
178  )
179  );
180  $dropDown = $this->uiFactory->dropdown()->standard($dropDownItems)
181  ->withLabel($this->lng->txt('actions'));
182  $this->tpl->setVariable('ACTION_HTML', $this->renderer->render($dropDown));
183  }
184 
185  protected function isEditable(): bool
186  {
187  return $this->editable;
188  }
189 }
setData(array $a_data)
TableGUI class for search results.
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
__construct(?object $a_parent_obj, string $a_parent_cmd, bool $a_sorting=false)
TODO Move most of this stuff to an init method.
renderer()
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
global $DIC
Definition: shib_login.php:26
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
__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)
addMultiCommand(string $a_cmd, string $a_text)
setEnableHeader(bool $a_enableheader)