ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjAssessmentFolder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "./Services/Object/classes/class.ilObject.php";
5 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionProcessLocker.php';
6 
18 {
21 
22  const ASS_PROC_LOCK_MODE_NONE = 'none';
23  const ASS_PROC_LOCK_MODE_FILE = 'file';
24  const ASS_PROC_LOCK_MODE_DB = 'db';
25 
26  var $setting;
27 
34  function ilObjAssessmentFolder($a_id = 0,$a_call_by_reference = true)
35  {
36  include_once "./Services/Administration/classes/class.ilSetting.php";
37  $this->setting = new ilSetting("assessment");
38  $this->type = "assf";
39  $this->ilObject($a_id,$a_call_by_reference);
40  }
41 
48  function update()
49  {
50  if (!parent::update())
51  {
52  return false;
53  }
54 
55  // put here object specific stuff
56 
57  return true;
58  }
59 
60 
67  function delete()
68  {
69  // always call parent delete function first!!
70  if (!parent::delete())
71  {
72  return false;
73  }
74 
75  //put here your module specific stuff
76 
77  return true;
78  }
79 
80 
94  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
95  {
96  global $tree;
97 
98  switch ($a_event)
99  {
100  case "link":
101 
102  //var_dump("<pre>",$a_params,"</pre>");
103  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
104  //exit;
105  break;
106 
107  case "cut":
108 
109  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
110  //exit;
111  break;
112 
113  case "copy":
114 
115  //var_dump("<pre>",$a_params,"</pre>");
116  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
117  //exit;
118  break;
119 
120  case "paste":
121 
122  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
123  //exit;
124  break;
125 
126  case "new":
127 
128  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
129  //exit;
130  break;
131  }
132 
133  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
134  if ($a_node_id==$_GET["ref_id"])
135  {
136  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
137  $parent_type = $parent_obj->getType();
138  if($parent_type == $this->getType())
139  {
140  $a_node_id = (int) $tree->getParentId($a_node_id);
141  }
142  }
143 
144  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
145  }
146 
150  function _enableAssessmentLogging($a_enable)
151  {
152  $setting = new ilSetting("assessment");
153 
154  if ($a_enable)
155  {
156  $setting->set("assessment_logging", 1);
157  }
158  else
159  {
160  $setting->set("assessment_logging", 0);
161  }
162  }
163 
167  function _setLogLanguage($a_language)
168  {
169  $setting = new ilSetting("assessment");
170 
171  $setting->set("assessment_log_language", $a_language);
172  }
173 
178  {
179  $setting = new ilSetting("assessment");
180 
181  return (boolean) $setting->get("assessment_logging");
182  }
183 
188  {
189  $setting = new ilSetting("assessment");
190  $types = $setting->get("forbidden_questiontypes");
191  $result = array();
192  if (strlen(trim($types)) == 0)
193  {
194  $result = array();
195  }
196  else
197  {
198  $result = unserialize($types);
199  }
200  return $result;
201  }
202 
208  function _setForbiddenQuestionTypes($a_types)
209  {
210  $setting = new ilSetting("assessment");
211  $types = "";
212  if (is_array($a_types) && (count($a_types) > 0))
213  {
214  $types = serialize($a_types);
215  }
216  $setting->set("forbidden_questiontypes", $types);
217  }
218 
222  function _getLogLanguage()
223  {
224  $setting = new ilSetting("assessment");
225 
226  $lang = $setting->get("assessment_log_language");
227  if (strlen($lang) == 0)
228  {
229  $lang = "en";
230  }
231  return $lang;
232  }
233 
244  {
245  if( count(self::_getManualScoring()) > 0 )
246  {
247  return true;
248  }
249 
250  return false;
251  }
252 
256  function _getManualScoring()
257  {
258  $setting = new ilSetting("assessment");
259 
260  $types = $setting->get("assessment_manual_scoring");
261  return explode(",", $types);
262  }
263 
268  {
269  global $ilDB;
270 
271  $result = $ilDB->query("SELECT * FROM qpl_qst_type");
272  $dbtypes = array();
273  while ($row = $ilDB->fetchAssoc($result))
274  {
275  $dbtypes[$row["question_type_id"]] = $row["type_tag"];
276  }
277  $setting = new ilSetting("assessment");
278  $types = $setting->get("assessment_manual_scoring");
279  $ids = explode(",", $types);
280  foreach ($ids as $key => $value)
281  {
282  $ids[$key] = $dbtypes[$value];
283  }
284  return $ids;
285  }
286 
292  function _setManualScoring($type_ids)
293  {
294  $setting = new ilSetting("assessment");
295  if ((!is_array($type_ids)) || (count($type_ids) == 0))
296  {
297  $setting->delete("assessment_manual_scoring");
298  }
299  else
300  {
301  $setting->set("assessment_manual_scoring", implode($type_ids, ","));
302  }
303  }
304 
305  public static function getScoringAdjustableQuestions()
306  {
307  $setting = new ilSetting("assessment");
308 
309  $types = $setting->get("assessment_scoring_adjustment");
310  return explode(",", $types);
311  }
312 
313  public static function setScoringAdjustableQuestions($type_ids)
314  {
315  $setting = new ilSetting("assessment");
316  if ((!is_array($type_ids)) || (count($type_ids) == 0))
317  {
318  $setting->delete("assessment_scoring_adjustment");
319  }
320  else
321  {
322  $setting->set("assessment_scoring_adjustment", implode($type_ids, ","));
323  }
324  }
325 
326  public static function getScoringAdjustmentEnabled()
327  {
328  $setting = new ilSetting("assessment");
329  return $setting->get('assessment_adjustments_enabled');
330  }
331 
332  public static function setScoringAdjustmentEnabled($active)
333  {
334  $setting = new ilSetting('assessment');
335  $setting->set('assessment_adjustments_enabled', (bool) $active);
336  }
337 
348  function _addLog($user_id, $object_id, $logtext, $question_id = "", $original_id = "", $test_only = FALSE, $test_ref_id = NULL)
349  {
350  global $ilUser, $ilDB;
351  if (strlen($question_id) == 0) $question_id = NULL;
352  if (strlen($original_id) == 0) $original_id = NULL;
353  if (strlen($test_ref_id) == 0) $test_ref_id = NULL;
354  $only = ($test_only == TRUE) ? 1 : 0;
355  $next_id = $ilDB->nextId('ass_log');
356  $affectedRows = $ilDB->manipulateF("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)",
357  array('integer', 'integer', 'integer', 'text', 'integer', 'integer', 'text', 'integer', 'integer'),
358  array(
359  $next_id,
360  $user_id,
361  $object_id,
362  $logtext,
363  $question_id,
364  $original_id,
365  $only,
366  $test_ref_id,
367  time()
368  )
369  );
370  }
371 
380  function &getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
381  {
382  global $ilDB;
383 
384  $log = array();
385  if ($test_only == TRUE)
386  {
387  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
388  array('integer','integer','integer','text'),
389  array(
390  $test_id,
391  $ts_from,
392  $ts_to,
393  1
394  )
395  );
396  }
397  else
398  {
399  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
400  array('integer','integer','integer'),
401  array(
402  $test_id,
403  $ts_from,
404  $ts_to
405  )
406  );
407  }
408  while ($row = $ilDB->fetchAssoc($result))
409  {
410  if (!array_key_exists($row["tstamp"], $log))
411  {
412  $log[$row["tstamp"]] = array();
413  }
414  array_push($log[$row["tstamp"]], $row);
415  }
416  krsort($log);
417  // flatten array
418  $log_array = array();
419  foreach ($log as $key => $value)
420  {
421  foreach ($value as $index => $row)
422  {
423  array_push($log_array, $row);
424  }
425  }
426  return $log_array;
427  }
428 
437  function &_getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
438  {
439  global $ilDB;
440 
441  $log = array();
442  if ($test_only == TRUE)
443  {
444  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
445  array('integer', 'integer', 'integer', 'text'),
446  array($test_id, $ts_from, $ts_to, 1)
447  );
448  }
449  else
450  {
451  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
452  array('integer', 'integer', 'integer'),
453  array($test_id, $ts_from, $ts_to)
454  );
455  }
456  while ($row = $ilDB->fetchAssoc($result))
457  {
458  if (!array_key_exists($row["tstamp"], $log))
459  {
460  $log[$row["tstamp"]] = array();
461  }
462  $type_href = "";
463  if (array_key_exists("ref_id", $row))
464  {
465  if ($row["ref_id"] > 0)
466  {
467  $type = ilObject::_lookupType($row['ref_id'], true);
468  switch ($type)
469  {
470  case "tst":
471  $type_href = sprintf("goto.php?target=tst_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
472  break;
473  case "cat":
474  $type_href = sprintf("goto.php?target=cat_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
475  break;
476  }
477  }
478  }
479  $row["href"] = $type_href;
480  array_push($log[$row["tstamp"]], $row);
481  }
482  krsort($log);
483  // flatten array
484  $log_array = array();
485  foreach ($log as $key => $value)
486  {
487  foreach ($value as $index => $row)
488  {
489  array_push($log_array, $row);
490  }
491  }
492  return $log_array;
493  }
494 
501  function getNrOfLogEntries($test_obj_id)
502  {
503  global $ilDB;
504  $result = $ilDB->queryF("SELECT COUNT(obj_fi) logcount FROM ass_log WHERE obj_fi = %s",
505  array('integer'),
506  array($test_obj_id)
507  );
508  if ($result->numRows())
509  {
510  $row = $ilDB->fetchAssoc($result);
511  return $row["logcount"];
512  }
513  else
514  {
515  return 0;
516  }
517  }
518 
526  {
527  global $tree;
528  $path = $tree->getPathFull($ref_id);
529  $pathelements = array();
530  foreach ($path as $id => $data)
531  {
532  if ($id == 0)
533  {
534  array_push($pathelements, ilUtil::prepareFormOutput($this->lng->txt("repository")));
535  }
536  else
537  {
538  array_push($pathelements, "<a href=\"./goto.php?target=" . $data["type"] . "_" . $data["ref_id"] . "&amp;client=" . CLIENT_ID . "\">" .
539  ilUtil::prepareFormOutput($data["title"]) . "</a>");
540  }
541  }
542  return implode("&nbsp;&gt;&nbsp;", $pathelements);
543  }
544 
550  function deleteLogEntries($a_array)
551  {
552  global $ilDB;
553  global $ilUser;
554 
555  foreach ($a_array as $object_id)
556  {
557  $affectedRows = $ilDB->manipulateF("DELETE FROM ass_log WHERE obj_fi = %s",
558  array('integer'),
559  array($object_id)
560  );
561  $this->_addLog($ilUser->getId(), $object_id, $this->lng->txt("assessment_log_deleted"));
562  }
563  }
564 
572  {
573  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
574 
575  global $ilSetting;
576 
577  $isPageEditorEnabled = $ilSetting->get(
578  'enable_tst_page_edit', self::ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
579  );
580 
581  return $isPageEditorEnabled;
582  }
583 
585  {
586  return $this->setting->get('ass_process_lock_mode', self::ASS_PROC_LOCK_MODE_NONE);
587  }
588 
589  public function setAssessmentProcessLockMode($lockMode)
590  {
591  $this->setting->set('ass_process_lock_mode', $lockMode);
592  }
593 
594  public static function getValidAssessmentProcessLockModes()
595  {
596  return array(self::ASS_PROC_LOCK_MODE_NONE, self::ASS_PROC_LOCK_MODE_FILE, self::ASS_PROC_LOCK_MODE_DB);
597  }
598 }