ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDclDetailedViewDefinitionGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
28  protected int $tableview_id;
31 
32  public function __construct(int $tableview_id)
33  {
34  global $DIC;
35 
36  $this->tableview_id = $tableview_id;
37  $this->http = $DIC->http();
38  $this->refinery = $DIC->refinery();
39  $this->locator = $DIC['ilLocator'];
40 
41  $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
42  $this->setStyleId($DIC->contentStyle()->domain()->styleForRefId($ref_id)->getEffectiveStyleId());
43 
44  // we always need a page object - create on demand
45  if (!ilPageObject::_exists('dclf', $tableview_id)) {
46  $viewdef = new ilDclDetailedViewDefinition();
47  $viewdef->setId($tableview_id);
48  $viewdef->setParentId(ilObject2::_lookupObjectId($ref_id));
49  $viewdef->setActive(false);
50  $viewdef->create();
51  }
52 
53  parent::__construct("dclf", $tableview_id);
54 
55  // content style (using system defaults)
56  $this->tpl->setCurrentBlock("SyntaxStyle");
57  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
58  $this->tpl->parseCurrentBlock();
59 
60  $this->tpl->setCurrentBlock("ContentStyle");
61  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
62  $this->tpl->parseCurrentBlock();
63  }
64 
68  public function executeCommand(): string
69  {
70  $next_class = $this->ctrl->getNextClass($this);
71 
72  $viewdef = $this->getPageObject();
73  $this->ctrl->setParameter($this, "dclv", $viewdef->getId());
74  $title = $this->lng->txt("dcl_view_viewdefinition");
75 
76  switch ($next_class) {
77  case "ilpageobjectgui":
78  throw new ilCOPageException("Deprecated. ilDclDetailedViewDefinitionGUI gui forwarding to ilpageobject");
79  default:
80  $this->setPresentationTitle($title);
81  $this->locator->addItem($title, $this->ctrl->getLinkTarget($this, "preview"));
82 
83  return parent::executeCommand();
84  }
85  }
86 
87  public function showPage(): string
88  {
89  if ($this->getOutputMode() == ilPageObjectGUI::EDIT) {
90  $delete_button = $this->ui->factory()->button()->standard(
91  $this->lng->txt('dcl_empty_detailed_view'),
92  $this->ctrl->getLinkTarget($this, 'confirmDelete')
93  );
94  $this->toolbar->addComponent($delete_button);
95 
96  if ($this->getPageObject()->getActive()) {
97  $activation_button = $this->ui->factory()->button()->standard(
98  $this->lng->txt('dcl_deactivate_view'),
99  $this->ctrl->getLinkTarget($this, 'deactivate')
100  );
101  } else {
102  $activation_button = $this->ui->factory()->button()->standard(
103  $this->lng->txt('dcl_activate_view'),
104  $this->ctrl->getLinkTarget($this, 'activate')
105  );
106  }
107 
108  $this->toolbar->addComponent($activation_button);
109 
110  $legend = $this->getPageObject()->getAvailablePlaceholders();
111  if (sizeof($legend)) {
112  $this->setPrependingHtml(
113  "<span class=\"small\">" . $this->lng->txt("dcl_legend_placeholders") . ": " . implode(" ", $legend)
114  . "</span>"
115  );
116  }
117  }
118 
119  return parent::showPage();
120  }
121 
122  protected function activate(): void
123  {
124  $page = $this->getPageObject();
125  $page->setActive(true);
126  $page->update();
127  $this->ctrl->redirect($this, 'edit');
128  }
129 
130  protected function deactivate(): void
131  {
132  $page = $this->getPageObject();
133  $page->setActive(false);
134  $page->update();
135  $this->ctrl->redirect($this, 'edit');
136  }
137 
138  public function confirmDelete(): void
139  {
140  $conf = new ilConfirmationGUI();
141  $conf->setFormAction($this->ctrl->getFormAction($this));
142  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_detailed_view_title'));
143 
144  $conf->addItem('tableview', (string) $this->tableview_id, $this->lng->txt('dcl_confirm_delete_detailed_view_text'));
145 
146  $conf->setConfirm($this->lng->txt('delete'), 'deleteView');
147  $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
148 
149  $this->tpl->setContent($conf->getHTML());
150  }
151 
152  public function cancelDelete(): void
153  {
154  $this->ctrl->redirect($this, "edit");
155  }
156 
157  public function deleteView(): void
158  {
159  if ($this->tableview_id && ilDclDetailedViewDefinition::exists($this->tableview_id)) {
160  $pageObject = new ilDclDetailedViewDefinition($this->tableview_id);
161  $pageObject->delete();
162  }
163 
164  $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_empty_detailed_view_success"), true);
165  $this->ctrl->redirectByClass(self::class, "edit");
166  }
167 
171  public function postOutputProcessing(string $a_output): string
172  {
173  // You can use this to parse placeholders and the like before outputting
174 
175  if ($this->getOutputMode() == ilPageObjectGUI::PREVIEW) {
176  //page preview is not being used inside DataCollections - if you are here, something's probably wrong
177 
178  //
179  // // :TODO: find a suitable presentation for matched placeholders
180  // $allp = ilDataCollectionRecordViewViewdefinition::getAvailablePlaceholders($this->table_id, true);
181  // foreach ($allp as $id => $item) {
182  // $parsed_item = new ilTextInputGUI("", "fields[" . $item->getId() . "]");
183  // $parsed_item = $parsed_item->getToolbarHTML();
184  //
185  // $a_output = str_replace($id, $item->getTitle() . ": " . $parsed_item, $a_output);
186  // }
187  } // editor
188  else {
189  if ($this->getOutputMode() == ilPageObjectGUI::EDIT) {
190  $allp = $this->getPageObject()->getAvailablePlaceholders();
191 
192  // :TODO: find a suitable markup for matched placeholders
193  foreach ($allp as $item) {
194  $a_output = str_replace($item, "<span style=\"color:green\">" . $item . "</span>", $a_output);
195  }
196  }
197  }
198 
199  return $a_output;
200  }
201 }
Class ilPageObjectGUI.
ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI, ilMediaPoolTargetSelector ilDcl...
setStyleId(int $a_styleid)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static _lookupObjectId(int $ref_id)
postOutputProcessing(string $a_output)
Finalizing output processing.
setPresentationTitle(string $a_title="")
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
setPrependingHtml(string $a_prependinghtml)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...