ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAsyncContainerSelectionExplorer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
32 {
36  protected array $js_conf;
37 
41  protected static array $js_on_load_added = [];
42 
44 
48  public function __construct(string $target, Factory $refinery, ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper)
49  {
50  parent::__construct($target);
51 
52  $this->addJsConf('save_explorer_url', $target);
53 
54  $this->request_wrapper = $request_wrapper;
55  $this->refinery = $refinery;
56  }
57 
61  public static function addJavascript(): void
62  {
63  global $DIC;
64  $tpl = $DIC['tpl'];
65 
66  $tpl->addJavaScript("./Services/UIComponent/Explorer/js/ilExplorer.js");
67  }
68 
72  public function buildOnClick($node_id, string $type, string $title): string
73  {
74  $result = "";
75  $ref_id = $this->request_wrapper->retrieve("ref_id", $this->refinery->kindlyTo()->int());
76  if ($ref_id) {
77  $result =
78  "$('body').trigger('async_explorer-add_reference', {target_id: '" .
79  $node_id .
80  "', type: '" .
81  $type .
82  "', parent_id: '" .
83  $ref_id .
84  "'});";
85  }
86  return $result;
87  }
88 
92  public function buildLinkTarget($node_id, string $type): string
93  {
94  return "javascript:void(0);";
95  }
96 
100  public function getOutput(): string
101  {
102  $this->initJs();
103 
104  return parent::getOutput();
105  }
106 
107  /*
108  * Initializes the js
109  * Adds the on load code for the async explorer
110  */
111  public function initJs(): void
112  {
113  $this->addOnLoadCode(
114  'explorer',
115  '$("#' . $this->getId() . '").study_programme_async_explorer(' . json_encode(
116  $this->js_conf,
117  JSON_THROW_ON_ERROR
118  ) . ');'
119  );
120  }
121 
125  protected function addOnLoadCode(string $id, string $content): void
126  {
127  if (!isset(self::$js_on_load_added[$id])) {
128  $this->tpl->addOnLoadCode($content);
129  self::$js_on_load_added[$id] = $content;
130  }
131  }
132 
136  public function addJsConf(string $key, string $value): void
137  {
138  $this->js_conf[$key] = $value;
139  }
140 
144  public function getJsConf(string $key): string
145  {
146  return $this->js_conf[$key];
147  }
148 }
buildLinkTarget($node_id, string $type)
Sets the href-value to a void js call.
getJsConf(string $key)
Returns a certain setting of the additional configuration.
$type
Class ChatMainBarProvider .
ilGlobalTemplateInterface $tpl
ILIAS Refinery Factory $refinery
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
getOutput()
Returns the explorer html and adds the javascript to the template.
addJsConf(string $key, string $value)
Adds additional js to the onload code of the async explorer.
__construct(string $target, Factory $refinery, ILIAS\HTTP\Wrapper\RequestWrapper $request_wrapper)
string $key
Consumer key/client ID value.
Definition: System.php:193
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
static addJavascript()
Adds the javascript to template.
__construct(Container $dic, ilPlugin $plugin)
Class ilAsyncContainerSelectionExplorer A class for async ilContainerSelectionExplorer which triggers...
buildOnClick($node_id, string $type, string $title)
Creates the onclick function call.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addOnLoadCode(string $id, string $content)
Adds onload code to the template.