ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjAssessmentFolder.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 require_once "./Services/Object/classes/class.ilObject.php";
35 
37 {
38  var $setting;
39 
46  function ilObjAssessmentFolder($a_id = 0,$a_call_by_reference = true)
47  {
48  include_once "./Services/Administration/classes/class.ilSetting.php";
49  $this->setting = new ilSetting("assessment");
50  $this->type = "assf";
51  $this->ilObject($a_id,$a_call_by_reference);
52  }
53 
60  function update()
61  {
62  if (!parent::update())
63  {
64  return false;
65  }
66 
67  // put here object specific stuff
68 
69  return true;
70  }
71 
72 
79  function delete()
80  {
81  // always call parent delete function first!!
82  if (!parent::delete())
83  {
84  return false;
85  }
86 
87  //put here your module specific stuff
88 
89  return true;
90  }
91 
101  function initDefaultRoles()
102  {
103  global $rbacadmin;
104  return array();
105  }
106 
120  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
121  {
122  global $tree;
123 
124  switch ($a_event)
125  {
126  case "link":
127 
128  //var_dump("<pre>",$a_params,"</pre>");
129  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
130  //exit;
131  break;
132 
133  case "cut":
134 
135  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
136  //exit;
137  break;
138 
139  case "copy":
140 
141  //var_dump("<pre>",$a_params,"</pre>");
142  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
143  //exit;
144  break;
145 
146  case "paste":
147 
148  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
149  //exit;
150  break;
151 
152  case "new":
153 
154  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
155  //exit;
156  break;
157  }
158 
159  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
160  if ($a_node_id==$_GET["ref_id"])
161  {
162  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
163  $parent_type = $parent_obj->getType();
164  if($parent_type == $this->getType())
165  {
166  $a_node_id = (int) $tree->getParentId($a_node_id);
167  }
168  }
169 
170  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
171  }
172 
176  function _enableAssessmentLogging($a_enable)
177  {
178  $setting = new ilSetting("assessment");
179 
180  if ($a_enable)
181  {
182  $setting->set("assessment_logging", 1);
183  }
184  else
185  {
186  $setting->set("assessment_logging", 0);
187  }
188  }
189 
193  function _setLogLanguage($a_language)
194  {
195  $setting = new ilSetting("assessment");
196 
197  $setting->set("assessment_log_language", $a_language);
198  }
199 
204  {
205  $setting = new ilSetting("assessment");
206 
207  return (boolean) $setting->get("assessment_logging");
208  }
209 
214  {
215  $setting = new ilSetting("assessment");
216  $types = $setting->get("forbidden_questiontypes");
217  $result = array();
218  if (strlen(trim($types)) == 0)
219  {
220  $result = array();
221  }
222  else
223  {
224  $result = unserialize($types);
225  }
226  return $result;
227  }
228 
234  function _setForbiddenQuestionTypes($a_types)
235  {
236  $setting = new ilSetting("assessment");
237  $types = "";
238  if (is_array($a_types) && (count($a_types) > 0))
239  {
240  $types = serialize($a_types);
241  }
242  $setting->set("forbidden_questiontypes", $types);
243  }
244 
248  function _getLogLanguage()
249  {
250  $setting = new ilSetting("assessment");
251 
252  $lang = $setting->get("assessment_log_language");
253  if (strlen($lang) == 0)
254  {
255  $lang = "en";
256  }
257  return $lang;
258  }
259 
270  {
271  if( count(self::_getManualScoring()) > 0 )
272  {
273  return true;
274  }
275 
276  return false;
277  }
278 
282  function _getManualScoring()
283  {
284  $setting = new ilSetting("assessment");
285 
286  $types = $setting->get("assessment_manual_scoring");
287  return explode(",", $types);
288  }
289 
294  {
295  global $ilDB;
296 
297  $result = $ilDB->query("SELECT * FROM qpl_qst_type");
298  $dbtypes = array();
299  while ($row = $ilDB->fetchAssoc($result))
300  {
301  $dbtypes[$row["question_type_id"]] = $row["type_tag"];
302  }
303  $setting = new ilSetting("assessment");
304  $types = $setting->get("assessment_manual_scoring");
305  $ids = explode(",", $types);
306  foreach ($ids as $key => $value)
307  {
308  $ids[$key] = $dbtypes[$value];
309  }
310  return $ids;
311  }
312 
318  function _setManualScoring($type_ids)
319  {
320  $setting = new ilSetting("assessment");
321  if ((!is_array($type_ids)) || (count($type_ids) == 0))
322  {
323  $setting->delete("assessment_manual_scoring");
324  }
325  else
326  {
327  $setting->set("assessment_manual_scoring", implode($type_ids, ","));
328  }
329  }
330 
341  function _addLog($user_id, $object_id, $logtext, $question_id = "", $original_id = "", $test_only = FALSE, $test_ref_id = NULL)
342  {
343  global $ilUser, $ilDB;
344  if (strlen($question_id) == 0) $question_id = NULL;
345  if (strlen($original_id) == 0) $original_id = NULL;
346  if (strlen($test_ref_id) == 0) $test_ref_id = NULL;
347  $only = ($test_only == TRUE) ? 1 : 0;
348  $next_id = $ilDB->nextId('ass_log');
349  $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)",
350  array('integer', 'integer', 'integer', 'text', 'integer', 'integer', 'text', 'integer', 'integer'),
351  array(
352  $next_id,
353  $user_id,
354  $object_id,
355  $logtext,
356  $question_id,
357  $original_id,
358  $only,
359  $test_ref_id,
360  time()
361  )
362  );
363  }
364 
373  function &getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
374  {
375  global $ilDB;
376 
377  $log = array();
378  if ($test_only == TRUE)
379  {
380  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
381  array('integer','integer','integer','text'),
382  array(
383  $test_id,
384  $ts_from,
385  $ts_to,
386  1
387  )
388  );
389  }
390  else
391  {
392  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
393  array('integer','integer','integer'),
394  array(
395  $test_id,
396  $ts_from,
397  $ts_to
398  )
399  );
400  }
401  while ($row = $ilDB->fetchAssoc($result))
402  {
403  if (!array_key_exists($row["tstamp"], $log))
404  {
405  $log[$row["tstamp"]] = array();
406  }
407  array_push($log[$row["tstamp"]], $row);
408  }
409  krsort($log);
410  // flatten array
411  $log_array = array();
412  foreach ($log as $key => $value)
413  {
414  foreach ($value as $index => $row)
415  {
416  array_push($log_array, $row);
417  }
418  }
419  return $log_array;
420  }
421 
430  function &_getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
431  {
432  global $ilDB;
433 
434  $log = array();
435  if ($test_only == TRUE)
436  {
437  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
438  array('integer', 'integer', 'integer', 'text'),
439  array($test_id, $ts_from, $ts_to, 1)
440  );
441  }
442  else
443  {
444  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
445  array('integer', 'integer', 'integer'),
446  array($test_id, $ts_from, $ts_to)
447  );
448  }
449  while ($row = $ilDB->fetchAssoc($result))
450  {
451  if (!array_key_exists($row["tstamp"], $log))
452  {
453  $log[$row["tstamp"]] = array();
454  }
455  $type_href = "";
456  if (array_key_exists("ref_id", $row))
457  {
458  if ($row["ref_id"] > 0)
459  {
460  $type = ilObject::_lookupType($row['ref_id'], true);
461  switch ($type)
462  {
463  case "tst":
464  $type_href = sprintf("goto.php?target=tst_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
465  break;
466  case "cat":
467  $type_href = sprintf("goto.php?target=cat_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
468  break;
469  }
470  }
471  }
472  $row["href"] = $type_href;
473  array_push($log[$row["tstamp"]], $row);
474  }
475  krsort($log);
476  // flatten array
477  $log_array = array();
478  foreach ($log as $key => $value)
479  {
480  foreach ($value as $index => $row)
481  {
482  array_push($log_array, $row);
483  }
484  }
485  return $log_array;
486  }
487 
494  function getNrOfLogEntries($test_obj_id)
495  {
496  global $ilDB;
497  $result = $ilDB->queryF("SELECT COUNT(obj_fi) logcount FROM ass_log WHERE obj_fi = %s",
498  array('integer'),
499  array($test_obj_id)
500  );
501  if ($result->numRows())
502  {
503  $row = $ilDB->fetchAssoc($result);
504  return $row["logcount"];
505  }
506  else
507  {
508  return 0;
509  }
510  }
511 
519  {
520  global $tree;
521  $path = $tree->getPathFull($ref_id);
522  $pathelements = array();
523  foreach ($path as $id => $data)
524  {
525  if ($id == 0)
526  {
527  array_push($pathelements, ilUtil::prepareFormOutput($this->lng->txt("repository")));
528  }
529  else
530  {
531  array_push($pathelements, "<a href=\"./goto.php?target=" . $data["type"] . "_" . $data["ref_id"] . "&amp;client=" . CLIENT_ID . "\">" .
532  ilUtil::prepareFormOutput($data["title"]) . "</a>");
533  }
534  }
535  return implode("&nbsp;&gt;&nbsp;", $pathelements);
536  }
537 
543  function deleteLogEntries($a_array)
544  {
545  global $ilDB;
546  global $ilUser;
547 
548  foreach ($a_array as $object_id)
549  {
550  $affectedRows = $ilDB->manipulateF("DELETE FROM ass_log WHERE obj_fi = %s",
551  array('integer'),
552  array($object_id)
553  );
554  $this->_addLog($ilUser->getId(), $object_id, $this->lng->txt("assessment_log_deleted"));
555  }
556  }
557 } // END class.ilObjAssessmentFolder
558 ?>