ILIAS  Release_3_10_x_branch Revision 61812
 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 
33 require_once "./classes/class.ilObject.php";
34 
36 {
37  var $setting;
38 
45  function ilObjAssessmentFolder($a_id = 0,$a_call_by_reference = true)
46  {
47  include_once "./Services/Administration/classes/class.ilSetting.php";
48  $this->setting = new ilSetting("assessment");
49  $this->type = "assf";
50  $this->ilObject($a_id,$a_call_by_reference);
51  }
52 
59  function update()
60  {
61  if (!parent::update())
62  {
63  return false;
64  }
65 
66  // put here object specific stuff
67 
68  return true;
69  }
70 
71 
78  function delete()
79  {
80  // always call parent delete function first!!
81  if (!parent::delete())
82  {
83  return false;
84  }
85 
86  //put here your module specific stuff
87 
88  return true;
89  }
90 
100  function initDefaultRoles()
101  {
102  global $rbacadmin;
103 
104  // create a local role folder
105  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
106 
107  // create moderator role and assign role to rolefolder...
108  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
109  //$roles[] = $roleObj->getId();
110 
111  //unset($rfoldObj);
112  //unset($roleObj);
113 
114  return $roles ? $roles : array();
115  }
116 
130  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
131  {
132  global $tree;
133 
134  switch ($a_event)
135  {
136  case "link":
137 
138  //var_dump("<pre>",$a_params,"</pre>");
139  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
140  //exit;
141  break;
142 
143  case "cut":
144 
145  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
146  //exit;
147  break;
148 
149  case "copy":
150 
151  //var_dump("<pre>",$a_params,"</pre>");
152  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
153  //exit;
154  break;
155 
156  case "paste":
157 
158  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
159  //exit;
160  break;
161 
162  case "new":
163 
164  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
165  //exit;
166  break;
167  }
168 
169  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
170  if ($a_node_id==$_GET["ref_id"])
171  {
172  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
173  $parent_type = $parent_obj->getType();
174  if($parent_type == $this->getType())
175  {
176  $a_node_id = (int) $tree->getParentId($a_node_id);
177  }
178  }
179 
180  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
181  }
182 
186  function _enableAssessmentLogging($a_enable)
187  {
188  $setting = new ilSetting("assessment");
189 
190  if ($a_enable)
191  {
192  $setting->set("assessment_logging", 1);
193  }
194  else
195  {
196  $setting->set("assessment_logging", 0);
197  }
198  }
199 
203  function _setLogLanguage($a_language)
204  {
205  $setting = new ilSetting("assessment");
206 
207  $setting->set("assessment_log_language", $a_language);
208  }
209 
214  {
215  $setting = new ilSetting("assessment");
216 
217  return (boolean) $setting->get("assessment_logging");
218  }
219 
224  {
225  $setting = new ilSetting("assessment");
226  $types = $setting->get("forbidden_questiontypes");
227  $result = array();
228  if (strlen(trim($types)) == 0)
229  {
230  $result = array();
231  }
232  else
233  {
234  $result = unserialize($types);
235  }
236  return $result;
237  }
238 
244  function _setForbiddenQuestionTypes($a_types)
245  {
246  $setting = new ilSetting("assessment");
247  $types = "";
248  if (is_array($a_types) && (count($a_types) > 0))
249  {
250  $types = serialize($a_types);
251  }
252  $setting->set("forbidden_questiontypes", $types);
253  }
254 
258  function _getLogLanguage()
259  {
260  $setting = new ilSetting("assessment");
261 
262  $lang = $setting->get("assessment_log_language");
263  if (strlen($lang) == 0)
264  {
265  $lang = "en";
266  }
267  return $lang;
268  }
269 
273  function _getManualScoring()
274  {
275  $setting = new ilSetting("assessment");
276 
277  $types = $setting->get("assessment_manual_scoring");
278  return explode(",", $types);
279  }
280 
285  {
286  global $ilDB;
287 
288  $query = "SELECT * FROM qpl_question_type";
289  $result = $ilDB->query($query);
290  $dbtypes = array();
291  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
292  {
293  $dbtypes[$row["question_type_id"]] = $row["type_tag"];
294  }
295  $setting = new ilSetting("assessment");
296  $types = $setting->get("assessment_manual_scoring");
297  $ids = explode(",", $types);
298  foreach ($ids as $key => $value)
299  {
300  $ids[$key] = $dbtypes[$value];
301  }
302  return $ids;
303  }
304 
310  function _setManualScoring($type_ids)
311  {
312  $setting = new ilSetting("assessment");
313  if ((!is_array($type_ids)) || (count($type_ids) == 0))
314  {
315  $setting->delete("assessment_manual_scoring");
316  }
317  else
318  {
319  $setting->set("assessment_manual_scoring", implode($type_ids, ","));
320  }
321  }
322 
335  function _addLog($user_id, $object_id, $logtext, $question_id = "", $original_id = "", $test_only = FALSE, $ref_id = NULL)
336  {
337  global $ilUser, $ilDB;
338  if (strlen($question_id) == 0)
339  {
340  $question_id = "NULL";
341  }
342  else
343  {
344  $question_id = $ilDB->quote($question_id . "");
345  }
346  if (strlen($original_id) == 0)
347  {
348  $original_id = "NULL";
349  }
350  else
351  {
352  $original_id = $ilDB->quote($original_id . "");
353  }
354  $only = "0";
355  if ($test_only == TRUE)
356  {
357  $only = "1";
358  }
359  $test_ref_id = "NULL";
360  if ($ref_id > 0)
361  {
362  $test_ref_id = $ilDB->quote($ref_id . "");
363  }
364  $query = sprintf("INSERT INTO ass_log (ass_log_id, user_fi, obj_fi, logtext, question_fi, original_fi, test_only, ref_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, NULL)",
365  $ilDB->quote($user_id . ""),
366  $ilDB->quote($object_id . ""),
367  $ilDB->quote($logtext . ""),
368  $question_id,
369  $original_id,
370  $ilDB->quote($only . ""),
371  $test_ref_id
372  );
373  $result = $ilDB->query($query);
374  }
375 
386  function &getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
387  {
388  $log = array();
389  if ($test_only == TRUE)
390  {
391  $query = sprintf("SELECT *, TIMESTAMP + 0 AS timestamp14 FROM ass_log WHERE obj_fi = %s AND TIMESTAMP + 0 > %s AND TIMESTAMP + 0 < %s AND test_only = %s ORDER BY timestamp14",
392  $this->ilias->db->quote($test_id . ""),
393  $this->ilias->db->quote($ts_from . ""),
394  $this->ilias->db->quote($ts_to . ""),
395  $this->ilias->db->quote("1")
396  );
397  }
398  else
399  {
400  $query = sprintf("SELECT *, TIMESTAMP + 0 AS timestamp14 FROM ass_log WHERE obj_fi = %s AND TIMESTAMP + 0 > %s AND TIMESTAMP + 0 < %s ORDER BY timestamp14",
401  $this->ilias->db->quote($test_id . ""),
402  $this->ilias->db->quote($ts_from . ""),
403  $this->ilias->db->quote($ts_to . "")
404  );
405  }
406  $result = $this->ilias->db->query($query);
407  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
408  {
409  if (!array_key_exists($row["timestamp14"], $log))
410  {
411  $log[$row["timestamp14"]] = array();
412  }
413  array_push($log[$row["timestamp14"]], $row);
414  }
415  krsort($log);
416  // flatten array
417  $log_array = array();
418  foreach ($log as $key => $value)
419  {
420  foreach ($value as $index => $row)
421  {
422  array_push($log_array, $row);
423  }
424  }
425  return $log_array;
426  }
427 
438  function &_getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
439  {
440  global $ilDB;
441 
442  $log = array();
443  if ($test_only == TRUE)
444  {
445  $query = sprintf("SELECT *, TIMESTAMP + 0 AS timestamp14 FROM ass_log WHERE obj_fi = %s AND TIMESTAMP + 0 > %s AND TIMESTAMP + 0 < %s AND test_only = %s ORDER BY timestamp14",
446  $ilDB->quote($test_id . ""),
447  $ilDB->quote($ts_from . ""),
448  $ilDB->quote($ts_to . ""),
449  $ilDB->quote("1")
450  );
451  }
452  else
453  {
454  $query = sprintf("SELECT *, TIMESTAMP + 0 AS timestamp14 FROM ass_log WHERE obj_fi = %s AND TIMESTAMP + 0 > %s AND TIMESTAMP + 0 < %s ORDER BY timestamp14",
455  $ilDB->quote($test_id . ""),
456  $ilDB->quote($ts_from . ""),
457  $ilDB->quote($ts_to . "")
458  );
459  }
460  $result = $ilDB->query($query);
461  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
462  {
463  if (!array_key_exists($row["timestamp14"], $log))
464  {
465  $log[$row["timestamp14"]] = array();
466  }
467  $type_href = "";
468  if (array_key_exists("ref_id", $row))
469  {
470  if ($row["ref_id"] > 0)
471  {
472  $typequery = sprintf("SELECT object_data.type FROM object_data, object_reference WHERE object_reference.ref_id = %s AND object_reference.obj_id = object_data.obj_id",
473  $ilDB->quote($row["ref_id"])
474  );
475  $typequeryresult = $ilDB->query($typequery);
476  if ($typequeryresult->numRows() == 1)
477  {
478  $typerow = $typequeryresult->fetchRow(DB_FETCHMODE_ASSOC);
479  switch ($typerow["type"])
480  {
481  case "tst":
482  $type_href = sprintf("goto.php?target=tst_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
483  break;
484  case "cat":
485  $type_href = sprintf("goto.php?target=cat_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
486  break;
487  }
488  }
489  }
490  }
491  $row["href"] = $type_href;
492  array_push($log[$row["timestamp14"]], $row);
493  }
494  krsort($log);
495  // flatten array
496  $log_array = array();
497  foreach ($log as $key => $value)
498  {
499  foreach ($value as $index => $row)
500  {
501  array_push($log_array, $row);
502  }
503  }
504  return $log_array;
505  }
506 
515  function getNrOfLogEntries($test_obj_id)
516  {
517  $query = sprintf("SELECT COUNT(obj_fi) AS logcount FROM ass_log WHERE obj_fi = %s",
518  $this->ilias->db->quote($test_obj_id . "")
519  );
520  $result = $this->ilias->db->query($query);
521  if ($result->numRows())
522  {
523  $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
524  return $row["logcount"];
525  }
526  else
527  {
528  return 0;
529  }
530  }
531 
541  {
542  global $tree;
543  $path = $tree->getPathFull($ref_id);
544  $pathelements = array();
545  foreach ($path as $id => $data)
546  {
547  if ($id == 0)
548  {
549  array_push($pathelements, ilUtil::prepareFormOutput($this->lng->txt("repository")));
550  }
551  else
552  {
553  array_push($pathelements, "<a href=\"./goto.php?target=" . $data["type"] . "_" . $data["ref_id"] . "&amp;client=" . CLIENT_ID . "\">" .
554  ilUtil::prepareFormOutput($data["title"]) . "</a>");
555  }
556  }
557  return implode("&nbsp;&gt;&nbsp;", $pathelements);
558  }
559 
567  function deleteLogEntries($a_array)
568  {
569  global $ilDB;
570  global $ilUser;
571 
572  foreach ($a_array as $object_id)
573  {
574  $query = sprintf("DELETE FROM ass_log WHERE obj_fi = %s",
575  $ilDB->quote($object_id . "")
576  );
577  $ilDB->query($query);
578  $this->_addLog($ilUser->getId(), $object_id, $this->lng->txt("assessment_log_deleted"));
579  }
580  }
581 } // END class.ilObjAssessmentFolder
582 ?>