ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestLearningObjectivesStatusGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  private \ILIAS\Test\InternalRequestService $testrequest;
31  protected $lng = null;
32 
36  private $crsObjId = null;
37 
41  private $usrId = null;
42 
43  public function __construct(ilLanguage $lng)
44  {
45  global $DIC;
46  $this->testrequest = $DIC->test()->internal()->request();
47  $this->lng = $lng;
48  }
49 
53  public function getCrsObjId(): ?int
54  {
55  return $this->crsObjId;
56  }
57 
61  public function setCrsObjId($crsObjId)
62  {
63  $this->crsObjId = $crsObjId;
64  }
65 
69  public function getUsrId(): ?int
70  {
71  return $this->usrId;
72  }
73 
77  public function setUsrId($usrId)
78  {
79  $this->usrId = $usrId;
80  }
81 
82  public function getHTML($objectiveId = null): string
83  {
84  $this->lng->loadLanguageModule('crs');
85 
86  $tpl = new ilTemplate('tpl.tst_lo_status.html', true, true, 'Modules/Test');
87 
88  $tpl->setCurrentBlock('objectives_progress_header');
89  $tpl->setVariable('OBJECTIVES_PROGRESS_HEADER', $this->lng->txt($this->getHeaderLangVar($objectiveId)));
90  $tpl->parseCurrentBlock();
91 
92  $this->renderStatus($tpl, $objectiveId, $this->getUsersObjectivesStatus(
93  $this->getCrsObjId(),
94  $this->getUsrId()
95  ));
96 
97  return $tpl->get();
98  }
99 
100  private function getHeaderLangVar($objectiveId): string
101  {
102  if ($objectiveId) {
103  return 'tst_objective_progress_header';
104  }
105 
106  return 'tst_objectives_progress_header';
107  }
108 
109  private function renderStatus($tpl, $objectiveId, $loStatusData)
110  {
111  $loc_settings = ilLOSettings::getInstanceByObjId($this->getCrsObjId());
112  $has_initial_test = (bool) $loc_settings->getInitialTest();
113 
114  foreach ($loStatusData as $objtv) {
115  if ($objectiveId && $objtv['id'] != $objectiveId) {
116  continue;
117  }
118 
119  $tpl->setCurrentBlock("objective_nolink_bl");
120  $tpl->setVariable("OBJECTIVE_NOLINK_TITLE", $objtv["title"]);
121  $tpl->parseCurrentBlock();
122 
123  $objtv_icon = ilObject::_getIcon($objtv["id"], "small", "lobj");
124 
125  $tpl->setCurrentBlock("objective_bl");
126  $tpl->setVariable("OBJTV_ICON_URL", $objtv_icon);
127  $tpl->setVariable("OBJTV_ICON_ALT", $this->lng->txt("crs_objectives"));
128 
129  if ($objtv["type"]) {
130  $tpl->setVariable(
131  "LP_OBJTV_PROGRESS",
132  ilContainerObjectiveGUI::buildObjectiveProgressBar($has_initial_test, $objtv["id"], $objtv, true)
133  );
134 
135  // since ilContainerObjectiveGUI::buildObjectiveProgressBar() "sets an empty ref_id" for ilObjTestGUI,
136  // after creating links for different test refs, the "saved ref_id param" for ilObjTestGUI gets overwritten.
137  // (!) we need to set an explicit ref_id param for ilObjTestGUI again to keep the things running (!)
138 
139  global $DIC; /* @var \ILIAS\DI\Container $DIC */
140  $DIC->ctrl()->setParameterByClass('ilObjTestGUI', 'ref_id', $this->testrequest->getRefId());
141  }
142 
143  $tpl->parseCurrentBlock();
144  }
145 
146  $tpl->setCurrentBlock("objectives_bl");
147  $tpl->setVariable("OBJTV_LIST_CRS_ID", $this->getCrsObjId());
148  $tpl->parseCurrentBlock();
149  }
150 
151  private function getUsersObjectivesStatus($crsObjId, $usrId): array
152  {
153  $res = array();
154 
156  $coll_objtv = $coll_objtv->getItems();
157  if ($coll_objtv) {
158  // #13373
159  $lo_results = $this->getUsersObjectivesResults($crsObjId, $usrId);
161 
162  $tmp = array();
163  foreach ($coll_objtv as $objective_id) {
164  $title = ilCourseObjective::lookupObjectiveTitle($objective_id, true);
165 
166  $tmp[$objective_id] = array(
167  "id" => $objective_id,
168  "title" => $title["title"],
169  "desc" => $title["description"],
170  "itest" => $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL),
171  "qtest" => $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED)
172  );
173 
174  // patch optes end
175 
176  if (array_key_exists($objective_id, $lo_results)) {
177  $lo_result = $lo_results[$objective_id];
178  $tmp[$objective_id]["user_id"] = $lo_result["user_id"];
179  $tmp[$objective_id]["result_perc"] = $lo_result["result_perc"];
180  $tmp[$objective_id]["limit_perc"] = $lo_result["limit_perc"];
181  $tmp[$objective_id]["status"] = $lo_result["status"];
182  $tmp[$objective_id]["type"] = $lo_result["type"];
183  $tmp[$objective_id]["initial"] = $lo_result["initial"] ?? null;
184  }
185  }
186 
187  // order
188  foreach ($coll_objtv as $objtv_id) {
189  $res[] = $tmp[$objtv_id];
190  }
191  }
192 
193  return $res;
194  }
195 
196  private function getUsersObjectivesResults($crsObjId, $usrId): array
197  {
198  $res = array();
199  $initial_status = null;
200  $lur = new ilLOUserResults($crsObjId, $usrId);
201 
202  foreach ($lur->getCourseResultsForUserPresentation() as $objective_id => $types) {
203  // show either initial or qualified for objective
204  if (isset($types[ilLOUserResults::TYPE_INITIAL])) {
205  $initial_status = $types[ilLOUserResults::TYPE_INITIAL]["status"];
206  }
207 
208  // qualified test has priority
209  if (isset($types[ilLOUserResults::TYPE_QUALIFIED])) {
210  $result = $types[ilLOUserResults::TYPE_QUALIFIED];
211  $result["type"] = ilLOUserResults::TYPE_QUALIFIED;
212  $result["initial"] = $types[ilLOUserResults::TYPE_INITIAL] ?? null;
213  } else {
214  $result = $types[ilLOUserResults::TYPE_INITIAL];
215  $result["type"] = ilLOUserResults::TYPE_INITIAL;
216  }
217 
218  $result["initial_status"] = $initial_status;
219 
220  $res[$objective_id] = $result;
221  }
222 
223  return $res;
224  }
225 }
$res
Definition: ltiservices.php:69
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static buildObjectiveProgressBar(bool $a_has_initial_test, int $a_objective_id, array $a_lo_result, bool $a_list_mode=false, bool $a_sub=false, string $a_tt_suffix=null)
Render progressbar(s) for given objective and result data.
global $DIC
Definition: feed.php:28
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static getInstanceByObjId(int $a_obj_id)
static getInstance(int $a_container_id)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41