ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilECSNodeMappingCmsExplorer.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
26 {
27  public const SEL_TYPE_CHECK = 1;
28  public const SEL_TYPE_RADIO = 2;
29 
30  private int $server_id;
31  private int $mid;
32  private int $tree_id;
33 
34  private array $checked_items = array();
35  private string $post_var = '';
36  private array $form_items = array();
37  private int $type;
38 
39  public function __construct(string $a_target, int $a_server_id, int $a_mid, int $a_tree_id)
40  {
41  parent::__construct($a_target);
42 
43  $this->type = self::SEL_TYPE_CHECK;
44  $this->setOrderColumn('title');
45  $this->setTitleLength(1024);
46 
47  // reset filter
48  $this->filter = array();
49  $this->addFormItemForType('');
50 
51  $this->server_id = $a_server_id;
52  $this->mid = $a_mid;
53  $this->tree_id = $a_tree_id;
54  }
55 
59  public function setTree(ilECSCmsTree $tree): void
60  {
61  $this->tree = $tree;
62  }
63 
67  public function isClickable(string $type, int $ref_id = 0): bool
68  {
69  return false;
70  }
71 
75  public function addFormItemForType($type): void
76  {
77  $this->form_items[$type] = true;
78  }
79 
80  public function removeFormItemForType($type): void
81  {
82  $this->form_items[$type] = false;
83  }
84 
85  public function setCheckedItems($a_checked_items = array()): void
86  {
87  $this->checked_items = $a_checked_items;
88  }
89 
90  public function isItemChecked($a_id): bool
91  {
92  return in_array($a_id, $this->checked_items, true) ? true : false;
93  }
94 
95  public function setPostVar($a_post_var): void
96  {
97  $this->post_var = $a_post_var;
98  }
99  public function getPostVar(): string
100  {
101  return $this->post_var;
102  }
103 
104  public function buildFormItem($a_node_id, $a_type): string
105  {
106  if (!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) {
107  return '';
108  }
109 
111  $this->server_id,
112  $this->mid,
113  $this->tree_id,
114  $a_node_id
115  );
116 
117  if ($status === ilECSCmsData::MAPPING_DELETED) {
119  $this->isItemChecked($a_node_id),
120  $this->post_var,
121  $a_node_id,
122  true
123  );
124  }
125  switch ($this->type) {
126  case self::SEL_TYPE_CHECK:
128  $this->isItemChecked($a_node_id),
129  $this->post_var,
130  $a_node_id
131  );
132  break;
133 
134  case self::SEL_TYPE_RADIO:
136  $this->isItemChecked($a_node_id),
137  $this->post_var,
138  $a_node_id
139  );
140  break;
141  }
142 
143  return '';
144  }
145 
146  public function formatObject($tpl, $a_node_id, $a_option, $a_obj_id = 0): void
147  {
148  global $DIC;
149  if (!isset($a_node_id) || !is_array($a_option)) {
150  $this->error->raiseError(get_class($this) . "::formatObject(): Missing parameter or wrong datatype! " .
151  "node_id: " . $a_node_id . " options:" . print_r($a_option, true), $this->error->WARNING);
152  }
153 
154  $pic = false;
155  foreach ($a_option["tab"] as $picture) {
156  if ($picture === 'plus') {
157  $tpl->setCurrentBlock("expander");
158  $tpl->setVariable("EXP_DESC", $this->lng->txt("expand"));
159  $target = $this->createTarget('+', $a_node_id);
160  $tpl->setVariable("LINK_NAME", $a_node_id);
161  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
162  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
164  $pic = true;
165  }
166 
167  if ($picture === 'minus' && $this->show_minus) {
168  $tpl->setCurrentBlock("expander");
169  $tpl->setVariable("EXP_DESC", $this->lng->txt("collapse"));
170  $target = $this->createTarget('-', $a_node_id);
171  $tpl->setVariable("LINK_NAME", $a_node_id);
172  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
173  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
175  $pic = true;
176  }
177  }
178 
179  if (!$pic) {
180  $tpl->setCurrentBlock("blank");
181  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
183  }
184 
185  if ($this->output_icons) {
186  $tpl->setCurrentBlock("icon");
187  $tpl->setVariable("ICON_IMAGE", $this->getImage("icon_cat.svg", $a_option["type"], $a_obj_id));
188 
189  $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
190  $this->iconList[] = "iconid_" . $a_node_id;
191  $tpl->setVariable("TXT_ALT_IMG", $this->lng->txt($a_option["desc"]));
193  }
194 
195  if ($formItem = ($this->buildFormItem($a_node_id, $a_option['type']) !== '')) {
196  $tpl->setCurrentBlock('check');
197  $tpl->setVariable('OBJ_CHECK', $formItem);
199  }
200 
201  if ($this->isClickable($a_option["type"], $a_node_id)) { // output link
202  $tpl->setCurrentBlock("link");
203  //$target = (strpos($this->target, "?") === false) ?
204  // $this->target."?" : $this->target."&";
205  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
206  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
207 
208  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
209 
210  if ($style_class !== "") {
211  $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
212  }
213 
214  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) !== "") {
215  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
216  }
217 
218  $tpl->setVariable("LINK_NAME", $a_node_id);
219  $tpl->setVariable(
220  "TITLE",
222  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
223  $this->textwidth,
224  true
225  )
226  );
227  $tpl->setVariable(
228  "DESC",
230  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]),
231  $this->textwidth,
232  true
233  )
234  );
235  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
236  if ($frame_target !== "") {
237  $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
238  }
239  } else { // output text only
240  $tpl->setCurrentBlock("text");
241  $tpl->setVariable(
242  "OBJ_TITLE",
244  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
245  $this->textwidth,
246  true
247  )
248  );
249  $tpl->setVariable(
250  "OBJ_DESC",
252  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
253  $this->textwidth,
254  true
255  )
256  );
257  }
259 
260  $tpl->setCurrentBlock("list_item");
262  $tpl->touchBlock("element");
263  }
264 
265 
266 
267  /*
268  * overwritten method from base class
269  * @access public
270  * @param integer obj_id
271  * @param integer array options
272  * @return string
273  */
274  public function formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option): void
275  {
276  // custom icons
277  $path = ilObject::_getIcon((int) $a_obj_id, "tiny", "root");
278 
279 
280  $tpl->setCurrentBlock("icon");
281  $nd = $this->tree->getNodeData($this->getRoot());
282 
283  $title = $nd["title"];
284 
285  $tpl->setVariable("ICON_IMAGE", $path);
286  $tpl->setVariable("TXT_ALT_IMG", $title);
287  $tpl->parseCurrentBlock();
288 
289  if ($formItem = ($this->buildFormItem($a_obj_id, $a_option['type']) !== '')) {
290  $tpl->setCurrentBlock('check');
291  $tpl->setVariable('OBJ_CHECK', $formItem);
292  $tpl->parseCurrentBlock();
293  }
294 
295  $tpl->setVariable('OBJ_TITLE', $this->buildTitle($title, $a_obj_id, ''));
296  }
297 
298  public function buildTitle(string $a_title, $a_id, string $a_type): string
299  {
301  $this->server_id,
302  $this->mid,
303  $this->tree_id,
304  $a_id
305  );
306 
307 
308 
309  switch ($status) {
311  return '<font style="font-weight: bold">' . $a_title . '</font>';
312 
314  return '<font style="font-weight: bold;font-style: italic">' . $a_title . '</font>';
315 
317  return '<font style="font-style: italic">' . $a_title . '</font>';
318 
320  return '<font class="warning">' . $a_title . '</font>';
321 
323  default:
324  return $a_title;
325  }
326  }
327 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
const MAPPING_PENDING_DISCONNECTABLE
formatObject($tpl, $a_node_id, $a_option, $a_obj_id=0)
buildDescription(string $a_desc, $a_id, string $a_type)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
buildTitle(string $a_title, $a_id, string $a_type)
touchBlock(string $block)
overwrites ITX::touchBlock.
ilGlobalTemplateInterface $tpl
formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
static lookupStatusByObjId(int $a_server_id, int $a_mid, int $a_tree_id, int $obj_id)
Lookup status.
setTitleLength(int $a_length)
$ref_id
Definition: ltiauth.php:67
$nd
Definition: error.php:12
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setOrderColumn(string $a_column)
static formRadioButton(bool $checked, string $varname, string $value, string $onclick=null, bool $disabled=false)
string $frame_target
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
class for explorer view in admin frame
buildFrameTarget(string $a_type, $a_child=0, $a_obj_id=0)
getNodeStyleClass( $a_id, string $a_type)
getImage(string $a_name, string $a_type="", $a_obj_id="")
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
createTarget(string $a_type, $a_node_id, bool $a_highlighted_subtree=false, bool $a_append_anch=true)
buildLinkTarget( $a_node_id, string $a_type)
isClickable(string $type, int $ref_id=0)
no item is clickable
buildOnClick( $a_node_id, string $a_type, string $a_title)
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
const MAPPING_PENDING_NOT_DISCONNECTABLE
__construct(string $a_target, int $a_server_id, int $a_mid, int $a_tree_id)
setTree(ilECSCmsTree $tree)
Set cms tree.