ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMarkSchemaTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Table/classes/class.ilTable2GUI.php';
5require_once 'Services/Form/classes/class.ilTextInputGUI.php';
6require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
7
14{
18 protected $ctrl;
19
23 protected $object;
24
28 protected $is_editable = true;
29
34 public function __construct($parent, $cmd, $template_context = '', ilMarkSchemaAware $object = null)
35 {
39 global $DIC;
40 $ilCtrl = $DIC['ilCtrl'];
41
42 $this->object = $object;
43 $this->ctrl = $ilCtrl;
44 $this->is_editable = $this->object->canEditMarks();
45
46 $this->setId('mark_schema_gui_' . $this->object->getMarkSchemaForeignId());
47 parent::__construct($parent, $cmd);
48
49 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject(), $cmd));
50 $this->setFormName('form_' . $this->getId());
51
52 $this->setRowTemplate('tpl.il_as_tst_mark_schema_row.html', 'Modules/Test');
53
54 $this->setNoEntriesText($this->lng->txt('tst_no_marks_defined'));
55
56 if ($this->object->canEditMarks()) {
57 $this->addCommandButton('saveMarks', $this->lng->txt('save'));
58 $this->addMultiCommand('deleteMarkSteps', $this->lng->txt('delete'));
59
60 $this->setSelectAllCheckbox('marks[]');
61 } else {
62 $this->disable('select_all');
63 }
64
65 $this->setLimit(PHP_INT_MAX);
66
67 $this->initColumns();
68 $this->initData();
69
70 $this->initJS($DIC->ui()->mainTemplate());
71 }
72
76 protected function initColumns()
77 {
78 $this->addColumn('', '', '1', true);
79 $this->addColumn($this->lng->txt('tst_mark_short_form'), '');
80 $this->addColumn($this->lng->txt('tst_mark_official_form'), '');
81 $this->addColumn($this->lng->txt('tst_mark_minimum_level'), '');
82 $this->addColumn($this->lng->txt('tst_mark_passed'), '', '1');
83 }
84
88 protected function initData()
89 {
90 $this->object->getMarkSchema()->sort();
91
92 $data = [];
93
94 $marks = $this->object->getMarkSchema()->getMarkSteps();
95 foreach ($marks as $key => $value) {
96 $data[] = [
97 'mark_id' => $key,
98 'mark_short' => $value->getShortName(),
99 'mark_official' => $value->getOfficialName(),
100 'mark_percentage' => $value->getMinimumLevel(),
101 'mark_passed' => $value->getPassed()
102 ];
103 }
104
105 $this->setData($data);
106 }
107
109 {
110 $tpl->addOnloadCode("
111 let form = document.querySelector('form[name=\"{$this->getFormName()}\"]');
112 let button = form.querySelector('input[name=\"cmd[saveMarks]\"]');
113 if (form && button) {
114 form.addEventListener('keydown', function (e) {
115 if (e.key === 'Enter') {
116 e.preventDefault();
117 form.requestSubmit(button);
118 }
119 })
120 }
121 ");
122 }
123
127 public function fillRow($row)
128 {
129 $short_name = new ilTextInputGUI('', 'mark_short_' . $row['mark_id']);
130 $short_name->setValue($row['mark_short']);
131 $short_name->setDisabled(!$this->is_editable);
132 $short_name->setMaxLength(15);
133 $short_name->setSize(10);
134
135 $official_name = new ilTextInputGUI('', 'mark_official_' . $row['mark_id']);
136 $official_name->setSize(20);
137 $official_name->setDisabled(!$this->object->canEditMarks());
138 $official_name->setMaxLength(50);
139 $official_name->setValue($row['mark_official']);
140
141 $percentage = new ilNumberInputGUI('', 'mark_percentage_' . $row['mark_id']);
142 $percentage->allowDecimals(true);
143 $percentage->setValue($row['mark_percentage']);
144 $percentage->setSize(10);
145 $percentage->setDisabled(!$this->is_editable);
146 $percentage->setMinValue(0);
147 $percentage->setMaxValue(100);
148
149 $this->tpl->setVariable('VAL_MARK_ID', $row['mark_id']);
150 $this->tpl->setVariable('VAL_CHECKBOX', ilUtil::formCheckbox(false, 'marks[]', $row['mark_id'], !$this->is_editable));
151 $this->tpl->setVariable('VAL_SHORT_NAME', $short_name->render());
152 $this->tpl->setVariable('VAL_OFFICIAL_NAME', $official_name->render());
153 $this->tpl->setVariable('VAL_PERCENTAGE', $percentage->render());
154 $this->tpl->setVariable('VAL_PASSED_CHECKBOX', ilUtil::formCheckbox((bool) $row['mark_passed'], 'passed_' . $row['mark_id'], '1', !$this->is_editable));
155 }
156}
An exception for terminatinating execution or to throw for unit testing.
initJS(ilGlobalTemplateInterface $tpl)
This class represents a number property in a property form.
Class ilTable2GUI.
setNoEntriesText($a_text)
Set text for an empty table.
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.
getId()
Get element id.
setData($a_data)
set table data @access public
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
ilTable2GUI constructor.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setLimit($a_limit=0, $a_default_limit=0)
set max.
addMultiCommand($a_cmd, $a_text)
Add Command button.
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.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
disable($a_module_name)
diesables particular modules of table
This class represents a text property in a property form.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? @access public
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc