ILIAS  release_8 Revision v8.23
class.ilObjAssessmentFolder.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
28 {
31 
32  public const ASS_PROC_LOCK_MODE_NONE = 'none';
33  public const ASS_PROC_LOCK_MODE_FILE = 'file';
34  public const ASS_PROC_LOCK_MODE_DB = 'db';
35 
36  private const SETTINGS_KEY_SKL_TRIG_NUM_ANSWERS_BARRIER = 'ass_skl_trig_num_answ_barrier';
38 
40 
41  public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
42  {
43  $this->setting = new ilSetting('assessment');
44  $this->type = 'assf';
45  parent::__construct($a_id, $a_call_by_reference);
46  }
47 
48  public static function getSkillTriggerAnswerNumberBarrier(): int
49  {
50  $assSettings = new ilSetting('assessment');
51 
52  return (int) $assSettings->get(
53  self::SETTINGS_KEY_SKL_TRIG_NUM_ANSWERS_BARRIER,
54  (string) self::DEFAULT_SKL_TRIG_NUM_ANSWERS_BARRIER
55  );
56  }
57 
58  public function _enableAssessmentLogging(bool $a_enable): void
59  {
60  $setting = new ilSetting('assessment');
61 
62  $setting->set('assessment_logging', (string) ((int) $a_enable));
63  }
64 
65  public function _setLogLanguage(string $a_language): void
66  {
67  $setting = new ilSetting('assessment');
68 
69  $setting->set('assessment_log_language', $a_language);
70  }
71 
72  public static function _enabledAssessmentLogging(): bool
73  {
74  $setting = new ilSetting('assessment');
75 
76  return (bool) $setting->get('assessment_logging', '0');
77  }
78 
83  public static function _getForbiddenQuestionTypes(): array
84  {
85  $setting = new ilSetting('assessment');
86  $types = $setting->get('forbidden_questiontypes', '');
87  $result = [];
88 
89  if ($types === '') {
90  $result = [];
91  } else {
92  $result = unserialize($types, ['allowed_classes' => false]);
93  }
94 
95  return array_filter(array_map('intval', $result));
96  }
97 
102  public function _setForbiddenQuestionTypes(array $typeIds): void
103  {
104  $setting = new ilSetting('assessment');
105 
106  $types = '';
107  if ($typeIds !== []) {
108  $types = serialize(array_map('intval', $typeIds));
109  }
110 
111  $setting->set('forbidden_questiontypes', $types);
112  }
113 
114  public static function _getLogLanguage(): string
115  {
116  $setting = new ilSetting('assessment');
117 
118  $lang = $setting->get('assessment_log_language', '');
119  if ($lang === '') {
120  $lang = 'en';
121  }
122 
123  return $lang;
124  }
125 
130  public static function _mananuallyScoreableQuestionTypesExists(): bool
131  {
132  return count(self::_getManualScoring()) > 0;
133  }
134 
139  public static function _getManualScoring(): array
140  {
141  $setting = new ilSetting('assessment');
142 
143  $types = $setting->get('assessment_manual_scoring', '');
144  return array_filter(array_map('intval', explode(',', $types)));
145  }
146 
151  public static function _getManualScoringTypes(): array
152  {
153  global $DIC;
154  $ilDB = $DIC['ilDB'];
155 
156  $setting = new ilSetting('assessment');
157  $typeIds = array_filter(array_map('intval', explode(',', $setting->get('assessment_manual_scoring', ''))));
158  $manualScoringTypes = [];
159 
160  $result = $ilDB->query('SELECT question_type_id, type_tag FROM qpl_qst_type');
161  while ($row = $ilDB->fetchAssoc($result)) {
162  if (in_array((int) $row['question_type_id'], $typeIds, true)) {
163  $manualScoringTypes[] = $row['type_tag'];
164  }
165  }
166  return array_filter($manualScoringTypes);
167  }
168 
173  public function _setManualScoring(array $type_ids): void
174  {
175  $setting = new ilSetting('assessment');
176  if ($type_ids === []) {
177  $setting->delete('assessment_manual_scoring');
178  } else {
179  $setting->set('assessment_manual_scoring', implode(',', $type_ids));
180  }
181  }
182 
186  public static function getScoringAdjustableQuestions(): array
187  {
188  $setting = new ilSetting('assessment');
189 
190  $types = $setting->get('assessment_scoring_adjustment', '');
191  return array_filter(array_map('intval', explode(',', $types)));
192  }
193 
198  public static function setScoringAdjustableQuestions(array $type_ids): void
199  {
200  $setting = new ilSetting('assessment');
201  if ($type_ids === []) {
202  $setting->delete('assessment_scoring_adjustment');
203  } else {
204  $setting->set('assessment_scoring_adjustment', implode(',', $type_ids));
205  }
206  }
207 
208  public static function getScoringAdjustmentEnabled(): bool
209  {
210  $setting = new ilSetting('assessment');
211  return (bool) $setting->get('assessment_adjustments_enabled', '0');
212  }
213 
214  public static function setScoringAdjustmentEnabled(bool $active): void
215  {
216  $setting = new ilSetting('assessment');
217  $setting->set('assessment_adjustments_enabled', (string) ((int) $active));
218  }
219 
230  public static function _addLog(
231  $user_id,
232  $object_id,
233  $logtext,
234  $question_id = 0,
235  $original_id = 0,
236  $test_only = false,
237  $test_ref_id = 0
238  ): void {
239  global $DIC;
240  $ilUser = $DIC['ilUser'];
241  $ilDB = $DIC['ilDB'];
242 
243  $db_question_id = 0;
244  if (is_numeric($question_id)) {
245  $db_question_id = (int) $question_id;
246  }
247 
248  $db_original_id = 0;
249  if (is_numeric($original_id)) {
250  $db_original_id = (int) $original_id;
251  }
252 
253  $db_test_ref_id = 0;
254  if (is_numeric($test_ref_id)) {
255  $db_test_ref_id = (int) $test_ref_id;
256  }
257 
258  $only = ($test_only === true) ? 1 : 0;
259  $next_id = $ilDB->nextId('ass_log');
260  $affectedRows = $ilDB->manipulateF(
261  "INSERT INTO ass_log (ass_log_id, user_fi, obj_fi, logtext, question_fi, original_fi, test_only, ref_id, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
262  ['integer', 'integer', 'integer', 'text', 'integer', 'integer', 'text', 'integer', 'integer'],
263  [
264  $next_id,
265  $user_id,
266  $object_id,
267  $logtext,
268  $db_question_id,
269  $db_original_id,
270  $only,
271  $db_test_ref_id,
272  time()
273  ]
274  );
275  }
276 
284  public static function getLog(int $ts_from, int $ts_to, int $test_id, bool $test_only = false): array
285  {
286  global $DIC;
287  $ilDB = $DIC['ilDB'];
288 
289  $log = [];
290  if ($test_only === true) {
291  $result = $ilDB->queryF(
292  "SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
293  ['integer', 'integer', 'integer', 'text'],
294  [
295  $test_id,
296  $ts_from,
297  $ts_to,
298  1
299  ]
300  );
301  } else {
302  $result = $ilDB->queryF(
303  "SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
304  ['integer', 'integer', 'integer'],
305  [
306  $test_id,
307  $ts_from,
308  $ts_to
309  ]
310  );
311  }
312  while ($row = $ilDB->fetchAssoc($result)) {
313  if (!array_key_exists($row["tstamp"], $log)) {
314  $log[$row["tstamp"]] = [];
315  }
316  $log[$row["tstamp"]][] = $row;
317  }
318  krsort($log);
319  // flatten array
320  $log_array = [];
321  foreach ($log as $key => $value) {
322  foreach ($value as $index => $row) {
323  $log_array[] = $row;
324  }
325  }
326  return $log_array;
327  }
328 
336  public static function _getLog(int $ts_from, int $ts_to, int $test_id, bool $test_only = false): array
337  {
338  global $DIC;
339  $ilDB = $DIC['ilDB'];
340 
341  $log = [];
342  if ($test_only === true) {
343  $result = $ilDB->queryF(
344  "SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
345  ['integer', 'integer', 'integer', 'text'],
346  [$test_id, $ts_from, $ts_to, 1]
347  );
348  } else {
349  $result = $ilDB->queryF(
350  "SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
351  ['integer', 'integer', 'integer'],
352  [$test_id, $ts_from, $ts_to]
353  );
354  }
355  while ($row = $ilDB->fetchAssoc($result)) {
356  if (!array_key_exists($row["tstamp"], $log)) {
357  $log[$row["tstamp"]] = [];
358  }
359  $type_href = "";
360  if (array_key_exists("ref_id", $row) && $row["ref_id"] > 0) {
361  $type = ilObject::_lookupType((int) $row['ref_id'], true);
362  switch ($type) {
363  case "tst":
364  $type_href = sprintf("goto.php?target=tst_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
365  break;
366  case "cat":
367  $type_href = sprintf("goto.php?target=cat_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
368  break;
369  }
370  }
371  $row["href"] = $type_href;
372  $log[$row["tstamp"]][] = $row;
373  }
374  krsort($log);
375  // flatten array
376  $log_array = [];
377  foreach ($log as $key => $value) {
378  foreach ($value as $index => $row) {
379  $log_array[] = $row;
380  }
381  }
382  return $log_array;
383  }
384 
390  public function getNrOfLogEntries(int $test_obj_id): int
391  {
392  global $DIC;
393  $ilDB = $DIC->database();
394 
395  $result = $ilDB->queryF(
396  "SELECT COUNT(obj_fi) logcount FROM ass_log WHERE obj_fi = %s",
397  ['integer'],
398  [$test_obj_id]
399  );
400  if ($result->numRows()) {
401  $row = $ilDB->fetchAssoc($result);
402  return (int) $row["logcount"];
403  }
404 
405  return 0;
406  }
407 
412  public function deleteLogEntries(array $a_array): void
413  {
414  global $DIC;
415  $ilDB = $DIC->database();
416  $ilUser = $DIC->user();
417 
418  foreach ($a_array as $object_id) {
419  $affectedRows = $ilDB->manipulateF(
420  "DELETE FROM ass_log WHERE obj_fi = %s",
421  ['integer'],
422  [$object_id]
423  );
424  self::_addLog($ilUser->getId(), $object_id, $this->lng->txt("assessment_log_deleted"));
425  }
426  }
427 
432  {
433  global $DIC;
434  $ilSetting = $DIC->settings();
435 
436  $isPageEditorEnabled = $ilSetting->get(
437  'enable_tst_page_edit',
438  (string) self::ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
439  );
440 
441  return (bool) $isPageEditorEnabled;
442  }
443 
444  public function getAssessmentProcessLockMode(): string
445  {
446  return $this->setting->get('ass_process_lock_mode', self::ASS_PROC_LOCK_MODE_NONE);
447  }
448 
449  public function setAssessmentProcessLockMode(string $lockMode): void
450  {
451  $this->setting->set('ass_process_lock_mode', $lockMode);
452  }
453 
457  public static function getValidAssessmentProcessLockModes(): array
458  {
459  return [
460  self::ASS_PROC_LOCK_MODE_NONE,
461  self::ASS_PROC_LOCK_MODE_FILE,
462  self::ASS_PROC_LOCK_MODE_DB
463  ];
464  }
465 
466  public function getSkillTriggeringNumAnswersBarrier(): string
467  {
468  return $this->setting->get(
469  'ass_skl_trig_num_answ_barrier',
470  (string) self::DEFAULT_SKL_TRIG_NUM_ANSWERS_BARRIER
471  );
472  }
473 
474  public function setSkillTriggeringNumAnswersBarrier(int $skillTriggeringNumAnswersBarrier): void
475  {
476  $this->setting->set('ass_skl_trig_num_answ_barrier', (string) $skillTriggeringNumAnswersBarrier);
477  }
478 
479  public function setExportEssayQuestionsWithHtml(bool $value): void
480  {
481  $this->setting->set('export_essay_qst_with_html', (string) ((int) $value));
482  }
483 
484  public function getExportEssayQuestionsWithHtml(): bool
485  {
486  return (bool) $this->setting->get('export_essay_qst_with_html', '0');
487  }
488 
494  public function fetchScoringAdjustableTypes(array $allQuestionTypes): array
495  {
496  $scoringAdjustableQuestionTypes = [];
497 
498  foreach ($allQuestionTypes as $type => $typeData) {
499  $questionGui = assQuestionGUI::_getQuestionGUI($typeData['type_tag']);
500 
501  if ($this->questionSupportsScoringAdjustment($questionGui)) {
502  $scoringAdjustableQuestionTypes[$type] = $typeData;
503  }
504  }
505 
506  return $scoringAdjustableQuestionTypes;
507  }
508 
509  private function questionSupportsScoringAdjustment(assQuestionGUI $question_object): bool
510  {
511  return (
512  $question_object instanceof ilGuiQuestionScoringAdjustable ||
513  $question_object instanceof ilGuiAnswerScoringAdjustable
514  ) && (
515  $question_object->object instanceof ilObjQuestionScoringAdjustable ||
516  $question_object->object instanceof ilObjAnswerScoringAdjustable
517  );
518  }
519 }
delete(string $a_keyword)
static _getManualScoringTypes()
Retrieve the manual scoring settings as type strings.
setSkillTriggeringNumAnswersBarrier(int $skillTriggeringNumAnswersBarrier)
string $type
static _addLog( $user_id, $object_id, $logtext, $question_id=0, $original_id=0, $test_only=false, $test_ref_id=0)
Add an assessment log entry.
get(string $a_keyword, ?string $a_default_value=null)
get setting
deleteLogEntries(array $a_array)
Deletes the log entries for a given array of test object IDs.
static _getLog(int $ts_from, int $ts_to, int $test_id, bool $test_only=false)
Retrieve assessment log datasets from the database.
questionSupportsScoringAdjustment(assQuestionGUI $question_object)
static getLog(int $ts_from, int $ts_to, int $test_id, bool $test_only=false)
Retrieve assessment log datasets from the database.
set(string $a_key, string $a_val)
_setManualScoring(array $type_ids)
Set the manual scoring settings.
static _getQuestionGUI(string $question_type='', int $question_id=-1)
Creates a question gui representation and returns the alias to the question gui.
$index
Definition: metadata.php:145
global $DIC
Definition: feed.php:28
getNrOfLogEntries(int $test_obj_id)
Returns the number of log entries for a given test id.
const ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
static _mananuallyScoreableQuestionTypesExists()
Returns the fact wether manually scoreable question types exist or not.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getForbiddenQuestionTypes()
Returns the forbidden questiontypes for ILIAS.
const CLIENT_ID
Definition: constants.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setScoringAdjustableQuestions(array $type_ids)
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lang
Definition: xapiexit.php:26
_setForbiddenQuestionTypes(array $typeIds)
Sets the forbidden questiontypes for ILIAS.
fetchScoringAdjustableTypes(array $allQuestionTypes)
setAssessmentProcessLockMode(string $lockMode)
static _getManualScoring()
Retrieve the manual scoring settings.
global $ilSetting
Definition: privfeed.php:17
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:34
static isAdditionalQuestionContentEditingModePageObjectEnabled()
Returns the fact wether content editing with ilias page editor is enabled for questions or not...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLogger $log
static setScoringAdjustmentEnabled(bool $active)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
__construct(int $a_id=0, bool $a_call_by_reference=true)
const ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_ENABLED