ILIAS  Release_4_4_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 
89  function initDefaultRoles()
90  {
91  global $rbacadmin;
92  return array();
93  }
94 
108  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
109  {
110  global $tree;
111 
112  switch ($a_event)
113  {
114  case "link":
115 
116  //var_dump("<pre>",$a_params,"</pre>");
117  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
118  //exit;
119  break;
120 
121  case "cut":
122 
123  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
124  //exit;
125  break;
126 
127  case "copy":
128 
129  //var_dump("<pre>",$a_params,"</pre>");
130  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
131  //exit;
132  break;
133 
134  case "paste":
135 
136  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
137  //exit;
138  break;
139 
140  case "new":
141 
142  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
143  //exit;
144  break;
145  }
146 
147  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
148  if ($a_node_id==$_GET["ref_id"])
149  {
150  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
151  $parent_type = $parent_obj->getType();
152  if($parent_type == $this->getType())
153  {
154  $a_node_id = (int) $tree->getParentId($a_node_id);
155  }
156  }
157 
158  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
159  }
160 
164  function _enableAssessmentLogging($a_enable)
165  {
166  $setting = new ilSetting("assessment");
167 
168  if ($a_enable)
169  {
170  $setting->set("assessment_logging", 1);
171  }
172  else
173  {
174  $setting->set("assessment_logging", 0);
175  }
176  }
177 
181  function _setLogLanguage($a_language)
182  {
183  $setting = new ilSetting("assessment");
184 
185  $setting->set("assessment_log_language", $a_language);
186  }
187 
192  {
193  $setting = new ilSetting("assessment");
194 
195  return (boolean) $setting->get("assessment_logging");
196  }
197 
202  {
203  $setting = new ilSetting("assessment");
204  $types = $setting->get("forbidden_questiontypes");
205  $result = array();
206  if (strlen(trim($types)) == 0)
207  {
208  $result = array();
209  }
210  else
211  {
212  $result = unserialize($types);
213  }
214  return $result;
215  }
216 
222  function _setForbiddenQuestionTypes($a_types)
223  {
224  $setting = new ilSetting("assessment");
225  $types = "";
226  if (is_array($a_types) && (count($a_types) > 0))
227  {
228  $types = serialize($a_types);
229  }
230  $setting->set("forbidden_questiontypes", $types);
231  }
232 
236  function _getLogLanguage()
237  {
238  $setting = new ilSetting("assessment");
239 
240  $lang = $setting->get("assessment_log_language");
241  if (strlen($lang) == 0)
242  {
243  $lang = "en";
244  }
245  return $lang;
246  }
247 
258  {
259  if( count(self::_getManualScoring()) > 0 )
260  {
261  return true;
262  }
263 
264  return false;
265  }
266 
270  function _getManualScoring()
271  {
272  $setting = new ilSetting("assessment");
273 
274  $types = $setting->get("assessment_manual_scoring");
275  return explode(",", $types);
276  }
277 
282  {
283  global $ilDB;
284 
285  $result = $ilDB->query("SELECT * FROM qpl_qst_type");
286  $dbtypes = array();
287  while ($row = $ilDB->fetchAssoc($result))
288  {
289  $dbtypes[$row["question_type_id"]] = $row["type_tag"];
290  }
291  $setting = new ilSetting("assessment");
292  $types = $setting->get("assessment_manual_scoring");
293  $ids = explode(",", $types);
294  foreach ($ids as $key => $value)
295  {
296  $ids[$key] = $dbtypes[$value];
297  }
298  return $ids;
299  }
300 
306  function _setManualScoring($type_ids)
307  {
308  $setting = new ilSetting("assessment");
309  if ((!is_array($type_ids)) || (count($type_ids) == 0))
310  {
311  $setting->delete("assessment_manual_scoring");
312  }
313  else
314  {
315  $setting->set("assessment_manual_scoring", implode($type_ids, ","));
316  }
317  }
318 
319  public static function getScoringAdjustableQuestions()
320  {
321  $setting = new ilSetting("assessment");
322 
323  $types = $setting->get("assessment_scoring_adjustment");
324  return explode(",", $types);
325  }
326 
327  public static function setScoringAdjustableQuestions($type_ids)
328  {
329  $setting = new ilSetting("assessment");
330  if ((!is_array($type_ids)) || (count($type_ids) == 0))
331  {
332  $setting->delete("assessment_scoring_adjustment");
333  }
334  else
335  {
336  $setting->set("assessment_scoring_adjustment", implode($type_ids, ","));
337  }
338  }
339 
340  public static function getScoringAdjustmentEnabled()
341  {
342  $setting = new ilSetting("assessment");
343  return $setting->get('assessment_adjustments_enabled');
344  }
345 
346  public static function setScoringAdjustmentEnabled($active)
347  {
348  $setting = new ilSetting('assessment');
349  $setting->set('assessment_adjustments_enabled', (bool) $active);
350  }
351 
362  function _addLog($user_id, $object_id, $logtext, $question_id = "", $original_id = "", $test_only = FALSE, $test_ref_id = NULL)
363  {
364  global $ilUser, $ilDB;
365  if (strlen($question_id) == 0) $question_id = NULL;
366  if (strlen($original_id) == 0) $original_id = NULL;
367  if (strlen($test_ref_id) == 0) $test_ref_id = NULL;
368  $only = ($test_only == TRUE) ? 1 : 0;
369  $next_id = $ilDB->nextId('ass_log');
370  $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)",
371  array('integer', 'integer', 'integer', 'text', 'integer', 'integer', 'text', 'integer', 'integer'),
372  array(
373  $next_id,
374  $user_id,
375  $object_id,
376  $logtext,
377  $question_id,
378  $original_id,
379  $only,
380  $test_ref_id,
381  time()
382  )
383  );
384  }
385 
394  function &getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
395  {
396  global $ilDB;
397 
398  $log = array();
399  if ($test_only == TRUE)
400  {
401  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
402  array('integer','integer','integer','text'),
403  array(
404  $test_id,
405  $ts_from,
406  $ts_to,
407  1
408  )
409  );
410  }
411  else
412  {
413  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
414  array('integer','integer','integer'),
415  array(
416  $test_id,
417  $ts_from,
418  $ts_to
419  )
420  );
421  }
422  while ($row = $ilDB->fetchAssoc($result))
423  {
424  if (!array_key_exists($row["tstamp"], $log))
425  {
426  $log[$row["tstamp"]] = array();
427  }
428  array_push($log[$row["tstamp"]], $row);
429  }
430  krsort($log);
431  // flatten array
432  $log_array = array();
433  foreach ($log as $key => $value)
434  {
435  foreach ($value as $index => $row)
436  {
437  array_push($log_array, $row);
438  }
439  }
440  return $log_array;
441  }
442 
451  function &_getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
452  {
453  global $ilDB;
454 
455  $log = array();
456  if ($test_only == TRUE)
457  {
458  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
459  array('integer', 'integer', 'integer', 'text'),
460  array($test_id, $ts_from, $ts_to, 1)
461  );
462  }
463  else
464  {
465  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
466  array('integer', 'integer', 'integer'),
467  array($test_id, $ts_from, $ts_to)
468  );
469  }
470  while ($row = $ilDB->fetchAssoc($result))
471  {
472  if (!array_key_exists($row["tstamp"], $log))
473  {
474  $log[$row["tstamp"]] = array();
475  }
476  $type_href = "";
477  if (array_key_exists("ref_id", $row))
478  {
479  if ($row["ref_id"] > 0)
480  {
481  $type = ilObject::_lookupType($row['ref_id'], true);
482  switch ($type)
483  {
484  case "tst":
485  $type_href = sprintf("goto.php?target=tst_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
486  break;
487  case "cat":
488  $type_href = sprintf("goto.php?target=cat_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
489  break;
490  }
491  }
492  }
493  $row["href"] = $type_href;
494  array_push($log[$row["tstamp"]], $row);
495  }
496  krsort($log);
497  // flatten array
498  $log_array = array();
499  foreach ($log as $key => $value)
500  {
501  foreach ($value as $index => $row)
502  {
503  array_push($log_array, $row);
504  }
505  }
506  return $log_array;
507  }
508 
515  function getNrOfLogEntries($test_obj_id)
516  {
517  global $ilDB;
518  $result = $ilDB->queryF("SELECT COUNT(obj_fi) logcount FROM ass_log WHERE obj_fi = %s",
519  array('integer'),
520  array($test_obj_id)
521  );
522  if ($result->numRows())
523  {
524  $row = $ilDB->fetchAssoc($result);
525  return $row["logcount"];
526  }
527  else
528  {
529  return 0;
530  }
531  }
532 
540  {
541  global $tree;
542  $path = $tree->getPathFull($ref_id);
543  $pathelements = array();
544  foreach ($path as $id => $data)
545  {
546  if ($id == 0)
547  {
548  array_push($pathelements, ilUtil::prepareFormOutput($this->lng->txt("repository")));
549  }
550  else
551  {
552  array_push($pathelements, "<a href=\"./goto.php?target=" . $data["type"] . "_" . $data["ref_id"] . "&amp;client=" . CLIENT_ID . "\">" .
553  ilUtil::prepareFormOutput($data["title"]) . "</a>");
554  }
555  }
556  return implode("&nbsp;&gt;&nbsp;", $pathelements);
557  }
558 
564  function deleteLogEntries($a_array)
565  {
566  global $ilDB;
567  global $ilUser;
568 
569  foreach ($a_array as $object_id)
570  {
571  $affectedRows = $ilDB->manipulateF("DELETE FROM ass_log WHERE obj_fi = %s",
572  array('integer'),
573  array($object_id)
574  );
575  $this->_addLog($ilUser->getId(), $object_id, $this->lng->txt("assessment_log_deleted"));
576  }
577  }
578 
586  {
587  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
588 
589  global $ilSetting;
590 
591  $isPageEditorEnabled = $ilSetting->get(
592  'enable_tst_page_edit', self::ADDITIONAL_QUESTION_CONTENT_EDITING_MODE_PAGE_OBJECT_DISABLED
593  );
594 
595  return $isPageEditorEnabled;
596  }
597 
599  {
600  return $this->setting->get('ass_process_lock_mode', self::ASS_PROC_LOCK_MODE_NONE);
601  }
602 
603  public function setAssessmentProcessLockMode($lockMode)
604  {
605  $this->setting->set('ass_process_lock_mode', $lockMode);
606  }
607 
608  public static function getValidAssessmentProcessLockModes()
609  {
610  return array(self::ASS_PROC_LOCK_MODE_NONE, self::ASS_PROC_LOCK_MODE_FILE, self::ASS_PROC_LOCK_MODE_DB);
611  }
612 }