ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMarkSchemaTableGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
27 
28  protected bool $is_editable = true;
29 
30  public function __construct($parent, $cmd, $template_context = '', ilMarkSchemaAware $object = null)
31  {
35  global $DIC;
36  $ilCtrl = $DIC['ilCtrl'];
37 
38  $this->object = $object;
39  $this->ctrl = $ilCtrl;
40  $this->is_editable = $this->object->canEditMarks();
41 
42  $this->setId('mark_schema_gui_' . $this->object->getMarkSchemaForeignId());
43  parent::__construct($parent, $cmd);
44 
45  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $cmd));
46  $this->setFormName('form_' . $this->getId());
47 
48  $this->setRowTemplate('tpl.il_as_tst_mark_schema_row.html', 'Modules/Test');
49 
50  $this->setNoEntriesText($this->lng->txt('tst_no_marks_defined'));
51 
52  if ($this->object->canEditMarks()) {
53  $this->addCommandButton('saveMarks', $this->lng->txt('save'));
54  $this->addMultiCommand('deleteMarkSteps', $this->lng->txt('delete'));
55 
56  $this->setSelectAllCheckbox('marks[]');
57  } else {
58  $this->disable('select_all');
59  }
60 
61  $this->setLimit(PHP_INT_MAX);
62 
63  $this->initColumns();
64  $this->initData();
65 
66  $this->initJS($DIC->ui()->mainTemplate());
67  }
68 
69  protected function initColumns(): void
70  {
71  $this->addColumn('', '', '1', true);
72  $this->addColumn($this->lng->txt('tst_mark_short_form'), '');
73  $this->addColumn($this->lng->txt('tst_mark_official_form'), '');
74  $this->addColumn($this->lng->txt('tst_mark_minimum_level'), '');
75  $this->addColumn($this->lng->txt('tst_mark_passed'), '', '1');
76  }
77 
78  protected function initData(): void
79  {
80  $this->object->getMarkSchema()->sort();
81 
82  $data = [];
83 
84  $marks = $this->object->getMarkSchema()->getMarkSteps();
85  foreach ($marks as $key => $value) {
86  $data[] = [
87  'mark_id' => $key,
88  'mark_short' => $value->getShortName(),
89  'mark_official' => $value->getOfficialName(),
90  'mark_percentage' => $value->getMinimumLevel(),
91  'mark_passed' => $value->getPassed()
92  ];
93  }
94 
95  $this->setData($data);
96  }
97 
99  {
100  $tpl->addOnloadCode("
101  let form = document.querySelector('form[name=\"{$this->getFormName()}\"]');
102  let button = form.querySelector('input[name=\"cmd[saveMarks]\"]');
103  if (form && button) {
104  form.addEventListener('keydown', function (e) {
105  if (e.key === 'Enter') {
106  e.preventDefault();
107  form.requestSubmit(button);
108  }
109  })
110  }
111  ");
112  }
113 
117  public function fillRow(array $a_set): void
118  {
119  $short_name = new ilTextInputGUI('', 'mark_short_' . $a_set['mark_id']);
120  $short_name->setValue($a_set['mark_short']);
121  $short_name->setDisabled(!$this->is_editable);
122  $short_name->setMaxLength(15);
123  $short_name->setSize(10);
124 
125  $official_name = new ilTextInputGUI('', 'mark_official_' . $a_set['mark_id']);
126  $official_name->setSize(20);
127  $official_name->setDisabled(!$this->object->canEditMarks());
128  $official_name->setMaxLength(50);
129  $official_name->setValue($a_set['mark_official']);
130 
131  $percentage = new ilNumberInputGUI('', 'mark_percentage_' . $a_set['mark_id']);
132  $percentage->allowDecimals(true);
133  $percentage->setValue($a_set['mark_percentage']);
134  $percentage->setSize(10);
135  $percentage->setDisabled(!$this->is_editable);
136  $percentage->setMinValue(0);
137  $percentage->setMaxValue(100);
138 
139  $this->tpl->setVariable('VAL_MARK_ID', $a_set['mark_id']);
140  $this->tpl->setVariable(
141  'VAL_CHECKBOX',
142  ilLegacyFormElementsUtil::formCheckbox(false, 'marks[]', $a_set['mark_id'], !$this->is_editable)
143  );
144  $this->tpl->setVariable('VAL_SHORT_NAME', $short_name->render());
145  $this->tpl->setVariable('VAL_OFFICIAL_NAME', $official_name->render());
146  $this->tpl->setVariable('VAL_PERCENTAGE', $percentage->render());
147  $this->tpl->setVariable(
148  'VAL_PASSED_CHECKBOX',
150  (bool) $a_set['mark_passed'],
151  'passed_' . $a_set['mark_id'],
152  '1',
153  !$this->is_editable
154  )
155  );
156  }
157 }
setNoEntriesText(string $a_text)
setData(array $a_data)
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setFormName(string $a_name="")
setId(string $a_val)
global $DIC
Definition: feed.php:28
This class represents a number property in a property form.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
string $key
Consumer key/client ID value.
Definition: System.php:193
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
__construct(Container $dic, ilPlugin $plugin)
setLimit(int $a_limit=0, int $a_default_limit=0)
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)
disable(string $a_module_name)
__construct(?object $a_parent_obj, string $a_parent_cmd="", string $a_template_context="")
addMultiCommand(string $a_cmd, string $a_text)
initJS(ilGlobalTemplateInterface $tpl)