ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Renderer.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
17 {
18 
22  public function render(Component\Component $popover, RendererInterface $default_renderer)
23  {
24  $this->checkComponent($popover);
25  $tpl = $this->getTemplate('tpl.popover.html', true, true);
26  $tpl->setVariable('FORCE_RENDERING', '');
29  $replacement = array(
30  '"' => '\"',
31  "\n" => "",
32  "\t" => "",
33  "\r" => "",
34  );
35 
36  $options = array(
37  'title' => $this->escape($popover->getTitle()),
38  'placement' => $popover->getPosition(),
39  'multi' => true,
40  'template' => str_replace(array_keys($replacement), array_values($replacement), $tpl->get()),
41  );
42 
43  if ($popover->isFixedPosition()) {
44  $options['style'] = "fixed";
45  }
46 
47  $is_async = $popover->getAsyncContentUrl();
48  if ($is_async) {
49  $options['type'] = 'async';
50  $options['url'] = $popover->getAsyncContentUrl();
51  }
52 
53  $show = $popover->getShowSignal();
54  $replace = $popover->getReplaceContentSignal();
55 
56  $popover = $popover->withAdditionalOnLoadCode(function ($id) use ($options, $show, $replace, $is_async) {
57  if (!$is_async) {
58  $options["url"] = "#{$id}";
59  }
60  $options = json_encode($options);
61 
62  return
63  "$(document).on('{$show}', function(event, signalData) {
64  il.UI.popover.showFromSignal(signalData, JSON.parse('{$options}'));
65  });" .
66  "$(document).on('{$replace}', function(event, signalData) {
67  il.UI.popover.replaceContentFromSignal('{$show}', signalData);
68  });";
69  });
70 
71  $id = $this->bindJavaScript($popover);
72 
73  if ($popover->getAsyncContentUrl()) {
74  return '';
75  }
76 
77  if ($popover instanceof Component\Popover\Standard) {
78  return $this->renderStandardPopover($popover, $default_renderer, $id);
79  } else {
80  if ($popover instanceof Component\Popover\Listing) {
81  return $this->renderListingPopover($popover, $default_renderer, $id);
82  }
83  }
84 
85  return '';
86  }
87 
88 
92  public function registerResources(ResourceRegistry $registry)
93  {
94  parent::registerResources($registry);
95  $registry->register('./libs/bower/bower_components/webui-popover/dist/jquery.webui-popover.js');
96  $registry->register('./src/UI/templates/js/Popover/popover.js');
97  }
98 
99 
107  protected function renderStandardPopover(Component\Popover\Standard $popover, RendererInterface $default_renderer, $id)
108  {
109  $tpl = $this->getTemplate('tpl.standard-popover-content.html', true, true);
110  $tpl->setVariable('ID', $id);
111  $tpl->setVariable('CONTENT', $default_renderer->render($popover->getContent()));
112 
113  return $tpl->get();
114  }
115 
116 
124  protected function renderListingPopover(Component\Popover\Listing $popover, RendererInterface $default_renderer, $id)
125  {
126  $tpl = $this->getTemplate('tpl.listing-popover-content.html', true, true);
127  $tpl->setVariable('ID', $id);
128  foreach ($popover->getItems() as $item) {
129  $tpl->setCurrentBlock('item');
130  $tpl->setVariable('ITEM', $default_renderer->render($item));
131  $tpl->parseCurrentBlock();
132  }
133 
134  return $tpl->get();
135  }
136 
137 
143  protected function escape($str)
144  {
145  return strip_tags(htmlentities($str, ENT_QUOTES, 'UTF-8'));
146  }
147 
148 
152  protected function getComponentInterfaceName()
153  {
154  return array( Component\Popover\Standard::class, Component\Popover\Listing::class );
155  }
156 }
Registry for resources required by rendered output like Javascript or CSS.
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
$tpl
Definition: ilias.php:10
if(!array_key_exists('StateId', $_REQUEST)) $id
renderListingPopover(Component\Popover\Listing $popover, RendererInterface $default_renderer, $id)
Definition: Renderer.php:124
renderStandardPopover(Component\Popover\Standard $popover, RendererInterface $default_renderer, $id)
Definition: Renderer.php:107
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.null
Definition: Renderer.php:92
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.