ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilSCTasks.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/SystemCheck/classes/class.ilSCTask.php';
6 
12 class ilSCTasks
13 {
14 
18  private static $instances = array();
19 
20  private $grp_id = 0;
21  private $tasks = array();
22 
26  private function __construct($a_grp_id)
27  {
28  $this->grp_id = $a_grp_id;
29  $this->read();
30  }
31 
36  public static function getInstanceByGroupId($a_group_id)
37  {
38  if(!array_key_exists($a_group_id, self::$instances))
39  {
40  return self::$instances[$a_group_id] = new self($a_group_id);
41  }
42  return self::$instances[$a_group_id];
43  }
44 
50  public function updateFromComponentDefinition($a_identifier)
51  {
52  foreach($this->getTasks() as $task)
53  {
54  if($task->getIdentifier() == $a_identifier)
55  {
56  return TRUE;
57  }
58  }
59 
60  $task = new ilSCTask();
61  $task->setGroupId($this->getGroupId());
62  $task->setIdentifier($a_identifier);
63  $task->create();
64 
65  return $task->getId();
66  }
67 
68 
69 
76  public static function lookupGroupId($a_task_id)
77  {
78  global $ilDB;
79 
80  $query = 'SELECT grp_id FROM sysc_tasks '.
81  'WHERE id = '.$ilDB->quote($a_task_id,'integer');
82  $res = $ilDB->query($query);
83  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
84  {
85  return $row->grp_id;
86  }
87  return 0;
88  }
89 
94  public static function lookupCompleted($a_grp_id)
95  {
96  global $ilDB;
97 
98  $query = 'SELECT count(id) num FROM sysc_tasks '.
99  'WHERE status = '.$ilDB->quote(ilSCTask::STATUS_COMPLETED,'integer').' '.
100  'AND grp_id = '.$ilDB->quote($a_grp_id,'integer');
101  $res = $ilDB->query($query);
102  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
103  {
104  return $row->num;
105  }
106  return 0;
107  }
108 
113  public static function lookupFailed($a_grp_id)
114  {
115  global $ilDB;
116 
117  $query = 'SELECT count(id) num FROM sysc_tasks '.
118  'WHERE status = '.$ilDB->quote(ilSCTask::STATUS_FAILED,'integer').' '.
119  'AND grp_id = '.$ilDB->quote($a_grp_id,'integer');
120  $res = $ilDB->query($query);
121  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
122  {
123  return $row->num;
124  }
125  return 0;
126  }
127 
134  public static function lookupLastUpdate($a_grp_id)
135  {
136  global $ilDB;
137 
138  $query = 'SELECT MAX(last_update) last_update FROM sysc_tasks '.
139  'WHERE status = '.$ilDB->quote(ilSCTask::STATUS_FAILED,'integer').' '.
140  'AND grp_id = '.$ilDB->quote($a_grp_id,'integer');
141  $res = $ilDB->query($query);
142 
143  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
144  {
145  return new ilDateTime($row->last_update,IL_CAL_DATETIME,'UTC');
146  }
147  return new ilDateTime(time(),IL_CAL_UNIX);
148  }
149 
150  public function getGroupId()
151  {
152  return $this->grp_id;
153  }
154 
159  public function getTasks()
160  {
161  return (array) $this->tasks;
162  }
163 
167  protected function read()
168  {
169  global $ilDB;
170 
171  $query = 'SELECT id FROM sysc_tasks '.
172  'ORDER BY id ';
173  $res = $ilDB->query($query);
174 
175  $this->tasks = array();
176  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
177  {
178  $this->tasks[] = new ilSCTask($row->id);
179  }
180  }
181 }
182 ?>
Defines a system check task.
const IL_CAL_DATETIME
Description of class.
const STATUS_FAILED
getTasks()
Get groups.
__construct($a_grp_id)
Singleton constructor.
const IL_CAL_UNIX
read()
read groups
updateFromComponentDefinition($a_identifier)
Update from module/service reader.
static lookupFailed($a_grp_id)
type $ilDB
static lookupLastUpdate($a_grp_id)
Lookup last update of group tasks type $ilDB.
Date and time handling
static getInstanceByGroupId($a_group_id)
Get singleton instance.
Create styles array
The data for the language used.
static lookupGroupId($a_task_id)
Lookup group id by task id type $ilDB.
const STATUS_COMPLETED
static $instances
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static lookupCompleted($a_grp_id)
type $ilDB