ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMailTemplateTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
6 
12 {
14  protected $contexts = [];
15 
17  protected $readOnly = false;
18 
20  protected $uiFactory;
21 
23  protected $uiRenderer;
24 
26  protected $uiComponents = [];
27 
35  public function __construct(
36  $a_parent_obj,
37  $a_parent_cmd,
40  $readOnly = false
41  ) {
42  $this->uiFactory = $uiFactory;
43  $this->uiRenderer = $uiRenderer;
44  $this->readOnly = $readOnly;
45 
46  $this->setId('mail_man_tpl');
47  parent::__construct($a_parent_obj, $a_parent_cmd);
48 
49  $this->setTitle($this->lng->txt('mail_templates'));
50  $this->setDefaultOrderDirection('ASC');
51  $this->setDefaultOrderField('title');
52 
53  if (!$this->readOnly) {
54  $this->addColumn('', '', '1%', true);
55  $this->setSelectAllCheckbox('tpl_id');
56  $this->addMultiCommand('confirmDeleteTemplate', $this->lng->txt('delete'));
57  }
58 
59  $this->addColumn($this->lng->txt('title'), 'title', '30%');
60  $this->addColumn($this->lng->txt('mail_template_context'), 'context', '20%');
61  $this->addColumn($this->lng->txt('action'), '', '10%');
62 
63  $this->setRowTemplate('tpl.mail_template_row.html', 'Services/Mail');
64  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
65 
67  }
68 
74  protected function formatCellValue($column, array $row)
75  {
76  if ('tpl_id' === $column) {
77  return \ilUtil::formCheckbox(false, 'tpl_id[]', $row[$column]);
78  } else {
79  if ('lang' === $column) {
80  return $this->lng->txt('meta_l_' . $row[$column]);
81  } else {
82  if ($column == 'context') {
83  if (isset($this->contexts[$row[$column]])) {
84  $isDefaultSuffix = '';
85  if ($row['is_default']) {
86  $isDefaultSuffix = $this->lng->txt('mail_template_default');
87  }
88 
89  return implode('', [
90  $this->contexts[$row[$column]]->getTitle(),
91  $isDefaultSuffix
92  ]);
93  } else {
94  return $this->lng->txt('mail_template_orphaned_context');
95  }
96  }
97  }
98  }
99 
100  return $row[$column];
101  }
102 
106  protected function fillRow($row)
107  {
108  foreach ($row as $column => $value) {
109  if ($column === 'tpl_id' && $this->readOnly) {
110  continue;
111  }
112 
113  $value = $this->formatCellValue($column, $row);
114  $this->tpl->setVariable('VAL_' . strtoupper($column), $value);
115  }
116 
117  $this->tpl->setVariable('VAL_ACTION', $this->formatActionsDropDown($row));
118  }
119 
124  protected function formatActionsDropDown(array $row) : string
125  {
126  $this->ctrl->setParameter($this->getParentObject(), 'tpl_id', $row['tpl_id']);
127 
128  $buttons = [];
129 
130  if (count($this->contexts) > 0) {
131  if (!$this->readOnly) {
132  $buttons[] = $this->uiFactory
133  ->button()
134  ->shy(
135  $this->lng->txt('edit'),
136  $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditTemplateForm')
137  );
138  } else {
139  $buttons[] = $this->uiFactory
140  ->button()
141  ->shy(
142  $this->lng->txt('view'),
143  $this->ctrl->getLinkTarget($this->getParentObject(), 'showEditTemplateForm')
144  );
145  }
146  }
147 
148  if (!$this->readOnly) {
149  $deleteModal = $this->uiFactory
150  ->modal()
151  ->interruptive(
152  $this->lng->txt('delete'),
153  $this->lng->txt('mail_tpl_sure_delete_entry'),
154  $this->ctrl->getFormAction($this->getParentObject(), 'deleteTemplate')
155  );
156 
157  $this->uiComponents[] = $deleteModal;
158 
159  $buttons[] = $this->uiFactory
160  ->button()
161  ->shy(
162  $this->lng->txt('delete'),
163  $this->ctrl->getLinkTarget($this->getParentObject(), 'confirmDeleteTemplate')
164  )->withOnClick($deleteModal->getShowSignal());
165 
166  if ($row['is_default']) {
167  $buttons[] = $this->uiFactory
168  ->button()
169  ->shy(
170  $this->lng->txt('mail_template_unset_as_default'),
171  $this->ctrl->getLinkTarget($this->getParentObject(), 'unsetAsContextDefault')
172  );
173  } else {
174  $buttons[] = $this->uiFactory
175  ->button()
176  ->shy(
177  $this->lng->txt('mail_template_set_as_default'),
178  $this->ctrl->getLinkTarget($this->getParentObject(), 'setAsContextDefault')
179  );
180  }
181  }
182 
183  $this->ctrl->setParameter($this->getParentObject(), 'tpl_id', null);
184 
185  $dropDown = $this->uiFactory
186  ->dropdown()
187  ->standard($buttons)
188  ->withLabel($this->lng->txt('actions'));
189 
190  return $this->uiRenderer->render([$dropDown]);
191  }
192 
196  public function getHTML()
197  {
198  return parent::getHTML() . $this->uiRenderer->render($this->uiComponents);
199  }
200 }
An entity that renders components to a string output.
Definition: Renderer.php:14
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
getParentObject()
Get parent object.
setId($a_val)
Set id.
Class ilMailTemplateTableGUI.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Class ilTable2GUI.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
This is how the factory for UI elements looks.
Definition: Factory.php:15
static getTemplateContexts($a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
addMultiCommand($a_cmd, $a_text)
Add Command button.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$row
__construct( $a_parent_obj, $a_parent_cmd, Factory $uiFactory, Renderer $uiRenderer, $readOnly=false)
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.