ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailTemplateTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
29 {
31  protected array $contexts = [];
32  protected bool $readOnly = false;
33  protected Factory $uiFactory;
34  protected Renderer $uiRenderer;
36  protected array $uiComponents = [];
37 
38  public function __construct(
39  ilMailTemplateGUI $a_parent_obj,
40  string $a_parent_cmd,
41  Factory $uiFactory,
42  Renderer $uiRenderer,
43  bool $readOnly = false
44  ) {
45  $this->uiFactory = $uiFactory;
46  $this->uiRenderer = $uiRenderer;
47  $this->readOnly = $readOnly;
48 
49  $this->setId('mail_man_tpl');
50  parent::__construct($a_parent_obj, $a_parent_cmd);
51 
52  $this->setTitle($this->lng->txt('mail_templates'));
53  $this->setDefaultOrderDirection('ASC');
54  $this->setDefaultOrderField('title');
55 
56  if (!$this->readOnly) {
57  $this->addColumn('', '', '1%', true);
58  $this->setSelectAllCheckbox('tpl_id');
59  $this->addMultiCommand('confirmDeleteTemplate', $this->lng->txt('delete'));
60  }
61 
62  $this->addColumn($this->lng->txt('title'), 'title', '30%');
63  $this->addColumn($this->lng->txt('mail_template_context'), 'context', '20%');
64  $this->addColumn($this->lng->txt('action'), '', '10%');
65 
66  $this->setRowTemplate('tpl.mail_template_row.html', 'Services/Mail');
67  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
68 
70  }
71 
72  protected function formatCellValue(string $column, array $row): string
73  {
74  if ('tpl_id' === $column) {
75  return ilLegacyFormElementsUtil::formCheckbox(false, 'tpl_id[]', (string) $row[$column]);
76  }
77  if ('lang' === $column) {
78  return $this->lng->txt('meta_l_' . $row[$column]);
79  }
80  if ($column === 'context') {
81  if (isset($this->contexts[$row[$column]])) {
82  $isDefaultSuffix = '';
83  if ($row['is_default']) {
84  $isDefaultSuffix = $this->lng->txt('mail_template_default');
85  }
86 
87  return implode('', [
88  $this->contexts[$row[$column]]->getTitle(),
89  $isDefaultSuffix,
90  ]);
91  }
92 
93  return $this->lng->txt('mail_template_orphaned_context');
94  }
95 
96  return (string) $row[$column];
97  }
98 
99  protected function fillRow(array $a_set): void
100  {
101  foreach ($a_set as $column => $value) {
102  if ($column === 'tpl_id' && $this->readOnly) {
103  continue;
104  }
105 
106  $value = $this->formatCellValue($column, $a_set);
107  $this->tpl->setVariable('VAL_' . strtoupper($column), $value);
108  }
109 
110  $this->tpl->setVariable('VAL_ACTION', $this->formatActionsDropDown($a_set));
111  }
112 
113  protected function formatActionsDropDown(array $row): string
114  {
115  $this->ctrl->setParameter($this->getParentObject(), 'tpl_id', $row['tpl_id']);
116 
117  $buttons = [];
118 
119  if (count($this->contexts) > 0) {
120  if (!$this->readOnly) {
121  $buttons[] = $this->uiFactory
122  ->button()
123  ->shy(
124  $this->lng->txt('edit'),
125  $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditTemplateForm')
126  );
127  } else {
128  $buttons[] = $this->uiFactory
129  ->button()
130  ->shy(
131  $this->lng->txt('view'),
132  $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditTemplateForm')
133  );
134  }
135  }
136 
137  if (!$this->readOnly) {
138  $deleteModal = $this->uiFactory
139  ->modal()
140  ->interruptive(
141  $this->lng->txt('delete'),
142  $this->lng->txt('mail_tpl_sure_delete_entry'),
143  $this->ctrl->getFormAction($this->getParentObject(), 'deleteTemplate')
144  )->withActionButtonLabel(
145  'deleteTemplate'
146  );
147 
148  $this->uiComponents[] = $deleteModal;
149 
150  $buttons[] = $this->uiFactory
151  ->button()
152  ->shy(
153  $this->lng->txt('delete'),
154  $this->ctrl->getLinkTarget($this->getParentObject(), 'confirmDeleteTemplate')
155  )->withOnClick($deleteModal->getShowSignal());
156 
157  if ($row['is_default']) {
158  $buttons[] = $this->uiFactory
159  ->button()
160  ->shy(
161  $this->lng->txt('mail_template_unset_as_default'),
162  $this->ctrl->getLinkTarget($this->getParentObject(), 'unsetAsContextDefault')
163  );
164  } else {
165  $buttons[] = $this->uiFactory
166  ->button()
167  ->shy(
168  $this->lng->txt('mail_template_set_as_default'),
169  $this->ctrl->getLinkTarget($this->getParentObject(), 'setAsContextDefault')
170  );
171  }
172  }
173 
174  $this->ctrl->setParameter($this->getParentObject(), 'tpl_id', null);
175 
176  $dropDown = $this->uiFactory
177  ->dropdown()
178  ->standard($buttons)
179  ->withLabel($this->lng->txt('actions'));
180 
181  return $this->uiRenderer->render([$dropDown]);
182  }
183 
184  public function getHTML(): string
185  {
186  return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
187  }
188 }
An entity that renders components to a string output.
Definition: Renderer.php:30
__construct(ilMailTemplateGUI $a_parent_obj, string $a_parent_cmd, Factory $uiFactory, Renderer $uiRenderer, bool $readOnly=false)
setFormAction(string $a_form_action, bool $a_multipart=false)
Class ilMailTemplateGUI.
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setId(string $a_val)
Class ilMailTemplateTableGUI.
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
setDefaultOrderField(string $a_defaultorderfield)
formatCellValue(string $column, array $row)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(Container $dic, ilPlugin $plugin)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
addMultiCommand(string $a_cmd, string $a_text)