ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilStudyProgrammeIndividualPlanTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private const SEL_COLUMN_COMPLETION_DATE = "completion_date";
24  private const SEL_COLUMN_DEADLINE = "prg_deadline";
25  private const SEL_COLUMN_ASSIGNMENT_DATE = "assignment_date";
26 
27  protected ilDBInterface $db;
28 
30  protected string $possible_image;
31  protected string $not_possible_image;
32 
33  public function __construct(
35  ilPRGAssignment $ass
36  ) {
37  $this->setId("manage_indiv");
38 
39  parent::__construct($parent_obj, 'manage');
40 
41  global $DIC;
42  $this->ctrl = $DIC['ilCtrl'];
43  $this->lng = $DIC['lng'];
44  $this->db = $DIC['ilDB'];
45 
46  $this->assignment = $ass;
47 
48  $this->setEnableTitle(true);
49  $this->setTopCommands(false);
50  $this->setEnableHeader(true);
51  // TODO: switch this to internal sorting/segmentation
52  $this->setExternalSorting(false);
53  $this->setExternalSegmentation(false);
54  $this->setRowTemplate("tpl.individual_plan_table_row.html", "Modules/StudyProgramme");
55  $this->setDefaultOrderDirection("asc");
56 
57  $this->getParentObject()->appendIndividualPlanActions($this);
58 
59  $columns = [
60  "status",
61  "title",
62  "prg_points_current",
63  "prg_points_required",
64  "prg_manual_status",
65  "prg_possible",
66  "prg_changed_by",
67  "prg_completion_by"
68  ];
69 
70  foreach ($this->getSelectedColumns() as $column) {
71  $columns[] = $column;
72  }
73 
74  foreach ($columns as $lng_var) {
75  $this->addColumn($this->lng->txt($lng_var));
76  }
77 
78  $plan = $this->fetchData();
79 
80  $this->setMaxCount(count($plan));
81  $this->setData($plan);
82 
83  $this->determineLimit();
84  $this->determineOffsetAndOrder();
85 
86  $ui_factory = $DIC['ui.factory'];
87  $ui_renderer = $DIC['ui.renderer'];
88  $this->possible_image = $ui_renderer->render(
89  $ui_factory->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_ok.svg"), 'ok')->withSize('small')
90  );
91  $this->not_possible_image = $ui_renderer->render(
92  $ui_factory->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_not_ok.svg"), 'not ok')->withSize('small')
93  );
94  }
95 
96  protected function fillRow(array $a_set): void
97  {
98  $this->tpl->setVariable("STATUS", $a_set['status_repr']);
99 
100  $title = $a_set["title"];
101  if ((int) $a_set["program_status"] === ilStudyProgrammeSettings::STATUS_DRAFT) {
102  $title .= " (" . $this->lng->txt("prg_status_draft") . ")";
103  } elseif ((int) $a_set["program_status"] === ilStudyProgrammeSettings::STATUS_OUTDATED) {
104  $title .= " (" . $this->lng->txt("prg_status_outdated") . ")";
105  }
106 
107  $this->tpl->setVariable("TITLE", $title);
108  $this->tpl->setVariable("POINTS_CURRENT", $a_set["points_current"]);
109  $this->tpl->setVariable(
110  "POINTS_REQUIRED",
111  $this->getRequiredPointsInput($a_set["progress_id"], $a_set["status"], (string)$a_set["points_required"])
112  );
113  $this->tpl->setVariable("MANUAL_STATUS", $this->getManualStatusSelect(
114  $a_set["progress_id"],
115  (int) $a_set["status"]
116  ));
117  $this->tpl->setVariable("POSSIBLE", $a_set["possible"] ? $this->possible_image : $this->not_possible_image);
118  $this->tpl->setVariable("CHANGED_BY", $a_set["changed_by"]);
119  $this->tpl->setVariable("COMPLETION_BY", $a_set["completion_by"]);
120 
121  foreach ($this->getSelectedColumns() as $column) {
122  switch ($column) {
123  case self::SEL_COLUMN_ASSIGNMENT_DATE:
124  $this->tpl->setCurrentBlock("assignment_date");
125  $this->tpl->setVariable("ASSIGNMENT_DATE", $a_set["assignment_date"]);
126  $this->tpl->parseCurrentBlock("assignment_date");
127  break;
128  case self::SEL_COLUMN_DEADLINE:
129  $this->tpl->setCurrentBlock("deadline");
130  $this->tpl->setVariable("DEADLINE", $this->getDeadlineInput($a_set["progress_id"], $a_set["deadline"]));
131  $this->tpl->parseCurrentBlock("deadline");
132  break;
133  case self::SEL_COLUMN_COMPLETION_DATE:
134  $this->tpl->setCurrentBlock("completion_date");
135  $this->tpl->setVariable("COMPLETION_DATE", $a_set["completion_date"]);
136  $this->tpl->parseCurrentBlock("completion_date");
137  break;
138  }
139  }
140  }
141 
142  public function getSelectableColumns(): array
143  {
144  $cols = array();
145 
146  $cols[self::SEL_COLUMN_ASSIGNMENT_DATE] = array(
147  "txt" => $this->lng->txt("assignment_date"));
148  $cols[self::SEL_COLUMN_DEADLINE] = array(
149  "txt" => $this->lng->txt("prg_deadline"));
150  $cols[self::SEL_COLUMN_COMPLETION_DATE] = array(
151  "txt" => $this->lng->txt("completion_date"));
152  return $cols;
153  }
154 
155  protected function fetchData(): array
156  {
157  $prg_id = $this->assignment->getRootId();
159 
160  $ass_id = $this->assignment->getId();
161  $usr_id = $this->assignment->getUserId();
162  $plan = array();
163 
164  $prg->applyToSubTreeNodes(
165  function ($node) use ($prg_id, $ass_id, $usr_id, &$plan, $prg) {
166  $progress = $this->assignment->getProgressForNode($node->getId());
167  $completion_by = $progress->getCompletionBy();
168 
169  if ($completion_by === ilPRGProgress::COMPLETED_BY_SUBNODES) {
170  $successful_subnodes = array_filter(
171  $progress->getSubnodes(),
172  static fn(ilPRGProgress $pgs): bool => $pgs->isSuccessful()
173  );
174  $successful_subnode_ids = array_map(
175  static fn(ilPRGProgress $pgs): int => $pgs->getNodeId(),
176  $successful_subnodes
177  );
178  $out = array_map(
179  fn(int $node_obj_id): string => ilStudyProgrammeUserTable::lookupTitle($node_obj_id),
180  $successful_subnode_ids
181  );
182  $completion_by = implode(', ', $out);
183  } else {
184  $completion_by = $progress->isSuccessful() ? ilStudyProgrammeUserTable::lookupTitle($completion_by) : '';
185  }
186 
187  $programme = ilObjStudyProgramme::getInstanceByObjId($progress->getNodeId());
188  $plan[] = [
189  "status" => $progress->getStatus(),
190  "status_repr" => $programme->statusToRepr($progress->getStatus()),
191  "title" => $node->getTitle(),
192  "points_current" => $progress->getCurrentAmountOfPoints(),
193  "points_required" => $progress->getAmountOfPoints(),
194  "possible" => $progress->isSuccessful() || $programme->canBeCompleted($progress) || !$progress->isRelevant(),
195  "changed_by" => ilObjUser::_lookupLogin($progress->getLastChangeBy()),
196  "completion_by" => $completion_by,
197  "progress_id" => $progress->getId(),
198  //draft/active/outdated
199  "program_status" => $programme->getStatus(),
200  "assignment_date" => $progress->getAssignmentDate()->format('d.m.Y'),
201  "deadline" => $progress->isSuccessful() ? null : $progress->getDeadline(),
202  "completion_date" => $progress->getCompletionDate() ? $progress->getCompletionDate()->format('d.m.Y') : ''
203  ];
204  },
205  true
206  );
207  return $plan;
208  }
209 
210  protected function getManualStatusSelect(string $progress_id, int $status): string
211  {
212  $parent = $this->getParentObject();
213  $options = [
214  $parent::MANUAL_STATUS_NONE => '-',
215  ilPRGProgress::STATUS_IN_PROGRESS => $this->lng->txt("prg_status_in_progress"),
216  ilPRGProgress::STATUS_ACCREDITED => $this->lng->txt("prg_status_accredited"),
217  ilPRGProgress::STATUS_NOT_RELEVANT => $this->lng->txt("prg_status_not_relevant")
218  //COMPLETED/FAILED are not to be set manually.
219  ];
220 
221  $allowed = ilPRGProgress::getAllowedTargetStatusFor($status);
222 
223  $options = array_filter(
224  $options,
225  static function ($o) use ($allowed, $parent): bool {
226  return in_array($o, $allowed) || $o === $parent::MANUAL_STATUS_NONE;
227  },
228  ARRAY_FILTER_USE_KEY
229  );
230 
231  $select = new ilSelectInputGUI("", $parent::POST_VAR_STATUS . "[$progress_id]");
232  $select->setOptions($options);
233  $select->setValue($parent::MANUAL_STATUS_NONE);
234 
235  return $select->render();
236  }
237 
238  protected function getRequiredPointsInput(string $progress_id, int $status, string $points_required): string
239  {
240  if ($status != ilPRGProgress::STATUS_IN_PROGRESS) {
241  return $points_required;
242  }
243 
244  $parent = $this->getParentObject();
245  $input = new ilNumberInputGUI("", $parent::POST_VAR_REQUIRED_POINTS . "[$progress_id]");
246  $input->setValue($points_required);
247  $input->setSize(5);
248  return $input->render();
249  }
250 
251  protected function getDeadlineInput(string $progress_id, $deadline): string
252  {
253  $parent = $this->getParentObject();
254  $gui = new ilDateTimeInputGUI("", $parent::POST_VAR_DEADLINE . "[$progress_id]");
255  $gui->setDate($deadline ? new ilDateTime($deadline->format('Y-m-d H:i:s'), IL_CAL_DATETIME) : null);
256  return $gui->render();
257  }
258 }
setData(array $a_data)
setTopCommands(bool $a_val)
const IL_CAL_DATETIME
This class represents a selection list property in a property form.
setEnableTitle(bool $a_enabletitle)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
__construct(ilObjStudyProgrammeIndividualPlanGUI $parent_obj, ilPRGAssignment $ass)
getRequiredPointsInput(string $progress_id, int $status, string $points_required)
setId(string $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a date/time property in a property form.
global $DIC
Definition: feed.php:28
A Progress is the status of a user on a single node of an assignment; it is unique by assignment_id:u...
setExternalSorting(bool $a_val)
__construct(VocabulariesInterface $vocabularies)
static getAllowedTargetStatusFor(int $status_from)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
$out
Definition: buildRTE.php:24
setDefaultOrderDirection(string $a_defaultorderdirection)
static getInstanceByObjId(int $obj_id)
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)
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableHeader(bool $a_enableheader)
setMaxCount(int $a_max_count)
set max.
setExternalSegmentation(bool $a_val)
static _lookupLogin(int $a_user_id)