ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCalendarAppointmentPresentationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
31 {
32  protected const MODE_MODAL = "modal";
33  protected const MODE_LIST_ITEM = "list_item";
34 
35  protected ilDate $seed;
37  protected array $appointment = [];
38 
39  protected string $mode = self::MODE_MODAL;
40 
43  protected ilLanguage $lng;
46  protected HttpServices $http;
48 
49 
50  protected ?Item $list_item = null;
51 
52  protected function __construct(ilDate $seed, array $a_app)
53  {
54  global $DIC;
55 
56  $this->http = $DIC->http();
57  $this->refinery = $DIC->refinery();
58  $this->lng = $DIC->language();
59  $this->ctrl = $DIC->ctrl();
60 
62 
63  $this->seed = $seed;
64  $this->appointment = $a_app;
65 
66  $this->tpl = $DIC->ui()->mainTemplate();
67  $this->info_screen = new ilInfoScreenGUI($this);
68  $this->toolbar = new ilToolbarGUI();
69  }
70 
74  public function setListItemMode(Item $a_val)
75  {
76  $this->list_item = $a_val;
77  $this->mode = self::MODE_LIST_ITEM;
78  }
79 
80  public function getListItem(): Item
81  {
82  return $this->list_item;
83  }
84 
88  public static function _getInstance(ilDate $seed, array $a_app): self
89  {
90  return new static($seed, $a_app);
91  }
92 
93  public function executeCommand(): void
94  {
95  $next_class = $this->ctrl->getNextClass($this);
96  $cmd = $this->ctrl->getCmd("getHTML");
97 
98  switch ($next_class) {
99  case 'ilcalendarappointmentgui':
100  $app_id = 0;
101  if ($this->http->wrapper()->query()->has('app_id')) {
102  $app_id = $this->http->wrapper()->query()->retrieve(
103  'app_id',
104  $this->refinery->kindlyTo()->int()
105  );
106  }
107  $app = new ilCalendarAppointmentGUI($this->seed, $this->seed, $app_id);
108  $this->ctrl->forwardCommand($app);
109  break;
110 
111  default:
112  if ($next_class != '') {
113  // get the path and include
114  $class_path = $this->ctrl->lookupClassPath($next_class);
115 
116  // check if the class implements our interface
117  $class_name = $this->ctrl->getClassForClasspath($class_path);
118  if (in_array("ilCalendarAppointmentPresentation", class_implements($class_name))) {
119  // forward command to class
120  $gui_class = new $class_name($this->appointment, $this->info_screen, $this->toolbar, null);
121  $this->ctrl->forwardCommand($gui_class);
122  }
123  }
124  break;
125  }
126  }
127 
131  public function getSeed(): ilDate
132  {
133  return $this->seed;
134  }
135 
136  public function getHTML(): string
137  {
138  if ($this->mode == self::MODE_MODAL) {
139  return $this->getModalHTML();
140  }
141  if ($this->mode == self::MODE_LIST_ITEM) {
142  return $this->modifyListItem();
143  }
144  return "";
145  }
146 
147  public function getModalHTML(): string
148  {
149  $tpl = new ilTemplate('tpl.appointment_presentation.html', true, true, 'components/ILIAS/Calendar');
150 
151  $info_screen = $this->info_screen;
152  $info_screen->setFormAction($this->ctrl->getFormAction($this));
153 
154  #21529 create new toolbar with unique id using the entry id for this purpose
155  $toolbar = new ilToolbarGUI();
156  $toolbar->setId((string) $this->appointment['event']->getEntryId());
157 
158  $f = ilAppointmentPresentationFactory::getInstance($this->appointment, $info_screen, $toolbar, null);
159 
160  $this->ctrl->getHTML($f);
161  $content = $info_screen->getHTML();
162 
163  //because #21529
164  $plugin_results = $this->getContentByPlugins($content, $toolbar);
165  $content = $plugin_results['content'];
166  $toolbar = $plugin_results['toolbar'];
167 
168  // show toolbar
169  $tpl->setCurrentBlock("toolbar");
170  $tpl->setVariable("TOOLBAR", $toolbar->getHTML());
171  $tpl->parseCurrentBlock();
172 
173  // show infoscreen
174  $tpl->setVariable("CONTENT", $content);
175 
176  return $tpl->get();
177  }
178 
182  public function modifyListItem(): string
183  {
184  $li = $this->getListItem();
185  $f = ilAppointmentPresentationFactory::getInstance($this->appointment, null, null, $li);
186  $this->ctrl->getHTML($f);
187  $this->list_item = $f->getListItem();
188  return '';
189  }
190 
191  protected function getActivePlugins(): Iterator
192  {
193  global $DIC;
194 
195  $component_factory = $DIC['component.factory'];
196  return $component_factory->getActivePluginsInSlot("capm");
197  }
198 
199  protected function getContentByPlugins($a_content, $a_toolbar): array
200  {
201  $content = $a_content;
202  $toolbar = $a_toolbar;
203  foreach ($this->getActivePlugins() as $plugin) {
204  //pass only the appointment stuff
205  $plugin->setAppointment($this->appointment['event'], new ilDateTime($this->appointment['dstart']));
206  if ($new_infoscreen = $plugin->infoscreenAddContent($this->info_screen)) {
207  $this->info_screen = $new_infoscreen;
208  }
209  $content = $this->info_screen->getHTML();
210  $extra_content = $plugin->addExtraContent();
211  if ($extra_content != '') {
212  $content .= $extra_content;
213  }
214 
215  if ($new_content = $plugin->replaceContent()) {
216  $content = $new_content;
217  }
218 
219  if ($new_toolbar = $plugin->toolbarAddItems($toolbar)) {
220  $toolbar = $new_toolbar;
221  }
222 
223  if ($new_toolbar = $plugin->toolbarReplaceContent()) {
224  $new_toolbar->setId((string) $a_toolbar->getId());
225  $toolbar = $new_toolbar;
226  }
227  }
228  return array(
229  'content' => $content,
230  'toolbar' => $toolbar
231  );
232  }
233 }
static _getInstance(ilDate $seed, array $a_app)
get singleton instance
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
static getInstance(array $a_appointment, ?ilInfoScreenGUI $a_info_screen, ?ilToolbarGUI $a_toolbar, ?Item $a_list_item)
setFormAction(string $a_form_action)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setId(string $a_val)
static http()
Fetches the global http state from ILIAS.
Common interface to all items.
Definition: Item.php:31
global $DIC
Definition: shib_login.php:22
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
Administrate calendar appointments.