ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilECSServerTableGUI.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
24 {
26 
27  private \ILIAS\UI\Factory $ui_factory;
28  private \ILIAS\UI\Renderer $ui_renderer;
29 
30  public function __construct(object $a_parent_obj, string $a_parent_cmd = "")
31  {
32  global $DIC;
33 
34  parent::__construct($a_parent_obj, $a_parent_cmd);
35  $this->setId('ecs_server_list');
36 
37  $this->access = $DIC->access();
38  $this->ui_factory = $DIC->ui()->factory();
39  $this->ui_renderer = $DIC->ui()->renderer();
40  }
41 
45  public function initTable(): void
46  {
47  $this->setTitle($this->lng->txt('ecs_available_ecs'));
48  $this->setRowTemplate('tpl.ecs_server_row.html', 'Services/WebServices/ECS');
49 
50  $this->addColumn($this->lng->txt('ecs_tbl_active'), '', '1%');
51  $this->addColumn($this->lng->txt('title'), '', '80%');
52 
53  if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
54  $this->addColumn($this->lng->txt('actions'), '', '19%');
55  }
56  }
57 
62  protected function fillRow(array $a_set): void
63  {
64  $this->ctrl->setParameter($this->getParentObject(), 'server_id', $a_set['server_id']);
65  $this->ctrl->setParameterByClass('ilecsmappingsettingsgui', 'server_id', $a_set['server_id']);
66 
67  if ($a_set['active']) {
68  $this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('standard/icon_ok.svg'));
69  $this->tpl->setVariable('TXT_OK', $this->lng->txt('ecs_activated'));
70  } else {
71  $this->tpl->setVariable('IMAGE_OK', ilUtil::getImagePath('standard/icon_not_ok.svg'));
72  $this->tpl->setVariable('TXT_OK', $this->lng->txt('ecs_inactivated'));
73  }
74 
75 
76  $this->tpl->setVariable('VAL_TITLE', ilECSSetting::getInstanceByServerId($a_set['server_id'])->getTitle());
77  $this->tpl->setVariable('LINK_EDIT', $this->ctrl->getLinkTarget($this->getParentObject(), 'edit'));
78  $this->tpl->setVariable('TXT_SRV_ADDR', $this->lng->txt('ecs_server_addr'));
79 
80  if (ilECSSetting::getInstanceByServerId($a_set['server_id'])->getServer()) {
81  $this->tpl->setVariable('VAL_DESC', ilECSSetting::getInstanceByServerId($a_set['server_id'])->getServer());
82  } else {
83  $this->tpl->setVariable('VAL_DESC', $this->lng->txt('ecs_not_configured'));
84  }
85 
86  $dt = ilECSSetting::getInstanceByServerId($a_set['server_id'])->fetchCertificateExpiration();
87  if ($dt !== null) {
88  $this->tpl->setVariable('TXT_CERT_VALID', $this->lng->txt('ecs_cert_valid_until'));
89 
90  $now = new ilDateTime(time(), IL_CAL_UNIX);
91  $now->increment(IL_CAL_MONTH, 2);
92 
93  if (ilDateTime::_before($dt, $now)) {
94  $this->tpl->setCurrentBlock('invalid');
95  $this->tpl->setVariable('VAL_ICERT', ilDatePresentation::formatDate($dt));
96  } else {
97  $this->tpl->setCurrentBlock('valid');
98  $this->tpl->setVariable('VAL_VCERT', ilDatePresentation::formatDate($dt));
99  }
100  $this->tpl->parseCurrentBlock();
101  }
102 
103  if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
104  // Actions
105  $items = [];
106 
107  if (ilECSSetting::getInstanceByServerId($a_set['server_id'])->isEnabled()) {
108  $items[] = [$this->lng->txt('ecs_deactivate'), $this->ctrl->getLinkTarget($this->getParentObject(), 'deactivate')];
109  } else {
110  $items[] = [$this->lng->txt('ecs_activate'), $this->ctrl->getLinkTarget($this->getParentObject(), 'activate')];
111  }
112 
113  $items[] = [$this->lng->txt('edit'), $this->ctrl->getLinkTarget($this->getParentObject(), 'edit')];
114  $items[] = [$this->lng->txt('copy'), $this->ctrl->getLinkTarget($this->getParentObject(), 'cp')];
115  $items[] = [$this->lng->txt('delete'), $this->ctrl->getLinkTarget($this->getParentObject(), 'delete')];
116 
117  $this->tpl->setCurrentBlock("actions");
118  $render_items = [];
119  foreach ($items as $item) {
120  $render_items[] = $this->ui_factory->button()->shy(...$item);
121  }
122  $this->tpl->setVariable(
123  'ACTIONS',
124  $this->ui_renderer->render($this->ui_factory->dropdown()->standard($render_items)->withLabel($this->lng->txt('actions')))
125  );
126  $this->tpl->parseCurrentBlock();
127  }
128  $this->ctrl->clearParameters($this->getParentObject());
129  }
130 
134  public function parse(ilECSServerSettings $servers): void
135  {
136  $rows = [];
137  foreach ($servers->getServers(ilECSServerSettings::ALL_SERVER) as $server) {
138  $tmp['server_id'] = $server->getServerId();
139  $tmp['active'] = $server->isEnabled();
140 
141  $rows[] = $tmp;
142  }
143  $this->setData($rows);
144  }
145 }
setData(array $a_data)
__construct(object $a_parent_obj, string $a_parent_cmd="")
static _before(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
parse(ilECSServerSettings $servers)
Parse available servers.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_MONTH
const IL_CAL_UNIX
setId(string $a_val)
global $DIC
Definition: feed.php:28
fillRow(array $a_set)
Fill row.
__construct(VocabulariesInterface $vocabularies)
Collection of ECS settings.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
getServers(int $server_type)
Get servers The function must be called with ALL_SERVER, ACTIVE_SERVER or INACTIVE_SERVER.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
$server
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)