ILIAS  Release_4_1_x_branch Revision 61804
 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  return array();
104  }
105 
119  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
120  {
121  global $tree;
122 
123  switch ($a_event)
124  {
125  case "link":
126 
127  //var_dump("<pre>",$a_params,"</pre>");
128  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
129  //exit;
130  break;
131 
132  case "cut":
133 
134  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
135  //exit;
136  break;
137 
138  case "copy":
139 
140  //var_dump("<pre>",$a_params,"</pre>");
141  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
142  //exit;
143  break;
144 
145  case "paste":
146 
147  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
148  //exit;
149  break;
150 
151  case "new":
152 
153  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
154  //exit;
155  break;
156  }
157 
158  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
159  if ($a_node_id==$_GET["ref_id"])
160  {
161  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
162  $parent_type = $parent_obj->getType();
163  if($parent_type == $this->getType())
164  {
165  $a_node_id = (int) $tree->getParentId($a_node_id);
166  }
167  }
168 
169  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
170  }
171 
175  function _enableAssessmentLogging($a_enable)
176  {
177  $setting = new ilSetting("assessment");
178 
179  if ($a_enable)
180  {
181  $setting->set("assessment_logging", 1);
182  }
183  else
184  {
185  $setting->set("assessment_logging", 0);
186  }
187  }
188 
192  function _setLogLanguage($a_language)
193  {
194  $setting = new ilSetting("assessment");
195 
196  $setting->set("assessment_log_language", $a_language);
197  }
198 
203  {
204  $setting = new ilSetting("assessment");
205 
206  return (boolean) $setting->get("assessment_logging");
207  }
208 
213  {
214  $setting = new ilSetting("assessment");
215  $types = $setting->get("forbidden_questiontypes");
216  $result = array();
217  if (strlen(trim($types)) == 0)
218  {
219  $result = array();
220  }
221  else
222  {
223  $result = unserialize($types);
224  }
225  return $result;
226  }
227 
233  function _setForbiddenQuestionTypes($a_types)
234  {
235  $setting = new ilSetting("assessment");
236  $types = "";
237  if (is_array($a_types) && (count($a_types) > 0))
238  {
239  $types = serialize($a_types);
240  }
241  $setting->set("forbidden_questiontypes", $types);
242  }
243 
247  function _getLogLanguage()
248  {
249  $setting = new ilSetting("assessment");
250 
251  $lang = $setting->get("assessment_log_language");
252  if (strlen($lang) == 0)
253  {
254  $lang = "en";
255  }
256  return $lang;
257  }
258 
262  function _getManualScoring()
263  {
264  $setting = new ilSetting("assessment");
265 
266  $types = $setting->get("assessment_manual_scoring");
267  return explode(",", $types);
268  }
269 
274  {
275  global $ilDB;
276 
277  $result = $ilDB->query("SELECT * FROM qpl_qst_type");
278  $dbtypes = array();
279  while ($row = $ilDB->fetchAssoc($result))
280  {
281  $dbtypes[$row["question_type_id"]] = $row["type_tag"];
282  }
283  $setting = new ilSetting("assessment");
284  $types = $setting->get("assessment_manual_scoring");
285  $ids = explode(",", $types);
286  foreach ($ids as $key => $value)
287  {
288  $ids[$key] = $dbtypes[$value];
289  }
290  return $ids;
291  }
292 
298  function _setManualScoring($type_ids)
299  {
300  $setting = new ilSetting("assessment");
301  if ((!is_array($type_ids)) || (count($type_ids) == 0))
302  {
303  $setting->delete("assessment_manual_scoring");
304  }
305  else
306  {
307  $setting->set("assessment_manual_scoring", implode($type_ids, ","));
308  }
309  }
310 
321  function _addLog($user_id, $object_id, $logtext, $question_id = "", $original_id = "", $test_only = FALSE, $test_ref_id = NULL)
322  {
323  global $ilUser, $ilDB;
324  if (strlen($question_id) == 0) $question_id = NULL;
325  if (strlen($original_id) == 0) $original_id = NULL;
326  if (strlen($test_ref_id) == 0) $test_ref_id = NULL;
327  $only = ($test_only == TRUE) ? 1 : 0;
328  $next_id = $ilDB->nextId('ass_log');
329  $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)",
330  array('integer', 'integer', 'integer', 'text', 'integer', 'integer', 'text', 'integer', 'integer'),
331  array(
332  $next_id,
333  $user_id,
334  $object_id,
335  $logtext,
336  $question_id,
337  $original_id,
338  $only,
339  $test_ref_id,
340  time()
341  )
342  );
343  }
344 
353  function &getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
354  {
355  global $ilDB;
356 
357  $log = array();
358  if ($test_only == TRUE)
359  {
360  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
361  array('integer','integer','integer','text'),
362  array(
363  $test_id,
364  $ts_from,
365  $ts_to,
366  1
367  )
368  );
369  }
370  else
371  {
372  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
373  array('integer','integer','integer'),
374  array(
375  $test_id,
376  $ts_from,
377  $ts_to
378  )
379  );
380  }
381  while ($row = $ilDB->fetchAssoc($result))
382  {
383  if (!array_key_exists($row["tstamp"], $log))
384  {
385  $log[$row["tstamp"]] = array();
386  }
387  array_push($log[$row["tstamp"]], $row);
388  }
389  krsort($log);
390  // flatten array
391  $log_array = array();
392  foreach ($log as $key => $value)
393  {
394  foreach ($value as $index => $row)
395  {
396  array_push($log_array, $row);
397  }
398  }
399  return $log_array;
400  }
401 
410  function &_getLog($ts_from, $ts_to, $test_id, $test_only = FALSE)
411  {
412  global $ilDB;
413 
414  $log = array();
415  if ($test_only == TRUE)
416  {
417  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s AND test_only = %s ORDER BY tstamp",
418  array('integer', 'integer', 'integer', 'text'),
419  array($test_id, $ts_from, $ts_to, 1)
420  );
421  }
422  else
423  {
424  $result = $ilDB->queryF("SELECT * FROM ass_log WHERE obj_fi = %s AND tstamp > %s AND tstamp < %s ORDER BY tstamp",
425  array('integer', 'integer', 'integer'),
426  array($test_id, $ts_from, $ts_to)
427  );
428  }
429  while ($row = $ilDB->fetchAssoc($result))
430  {
431  if (!array_key_exists($row["tstamp"], $log))
432  {
433  $log[$row["tstamp"]] = array();
434  }
435  $type_href = "";
436  if (array_key_exists("ref_id", $row))
437  {
438  if ($row["ref_id"] > 0)
439  {
440  include_once "./classes/class.ilObject.php";
441  $type = ilObject::_lookupType($row['ref_id'], true);
442  switch ($type)
443  {
444  case "tst":
445  $type_href = sprintf("goto.php?target=tst_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
446  break;
447  case "cat":
448  $type_href = sprintf("goto.php?target=cat_%s&amp;client_id=" . CLIENT_ID, $row["ref_id"]);
449  break;
450  }
451  }
452  }
453  $row["href"] = $type_href;
454  array_push($log[$row["tstamp"]], $row);
455  }
456  krsort($log);
457  // flatten array
458  $log_array = array();
459  foreach ($log as $key => $value)
460  {
461  foreach ($value as $index => $row)
462  {
463  array_push($log_array, $row);
464  }
465  }
466  return $log_array;
467  }
468 
475  function getNrOfLogEntries($test_obj_id)
476  {
477  global $ilDB;
478  $result = $ilDB->queryF("SELECT COUNT(obj_fi) logcount FROM ass_log WHERE obj_fi = %s",
479  array('integer'),
480  array($test_obj_id)
481  );
482  if ($result->numRows())
483  {
484  $row = $ilDB->fetchAssoc($result);
485  return $row["logcount"];
486  }
487  else
488  {
489  return 0;
490  }
491  }
492 
500  {
501  global $tree;
502  $path = $tree->getPathFull($ref_id);
503  $pathelements = array();
504  foreach ($path as $id => $data)
505  {
506  if ($id == 0)
507  {
508  array_push($pathelements, ilUtil::prepareFormOutput($this->lng->txt("repository")));
509  }
510  else
511  {
512  array_push($pathelements, "<a href=\"./goto.php?target=" . $data["type"] . "_" . $data["ref_id"] . "&amp;client=" . CLIENT_ID . "\">" .
513  ilUtil::prepareFormOutput($data["title"]) . "</a>");
514  }
515  }
516  return implode("&nbsp;&gt;&nbsp;", $pathelements);
517  }
518 
524  function deleteLogEntries($a_array)
525  {
526  global $ilDB;
527  global $ilUser;
528 
529  foreach ($a_array as $object_id)
530  {
531  $affectedRows = $ilDB->manipulateF("DELETE FROM ass_log WHERE obj_fi = %s",
532  array('integer'),
533  array($object_id)
534  );
535  $this->_addLog($ilUser->getId(), $object_id, $this->lng->txt("assessment_log_deleted"));
536  }
537  }
538 } // END class.ilObjAssessmentFolder
539 ?>