ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  return self::$instances[$a_group_id] = new self($a_group_id);
40  }
41  return self::$instances[$a_group_id];
42  }
43 
49  public function updateFromComponentDefinition($a_identifier)
50  {
51  foreach ($this->getTasks() as $task) {
52  if ($task->getIdentifier() == $a_identifier) {
53  return true;
54  }
55  }
56 
57  $task = new ilSCTask();
58  $task->setGroupId($this->getGroupId());
59  $task->setIdentifier($a_identifier);
60  $task->create();
61 
62  return $task->getId();
63  }
64 
65 
66 
73  public static function lookupGroupId($a_task_id)
74  {
75  global $ilDB;
76 
77  $query = 'SELECT grp_id FROM sysc_tasks ' .
78  'WHERE id = ' . $ilDB->quote($a_task_id, 'integer');
79  $res = $ilDB->query($query);
80  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
81  return $row->grp_id;
82  }
83  return 0;
84  }
85 
90  public static function lookupCompleted($a_grp_id)
91  {
92  global $ilDB;
93 
94  $query = 'SELECT count(id) num FROM sysc_tasks ' .
95  'WHERE status = ' . $ilDB->quote(ilSCTask::STATUS_COMPLETED, 'integer') . ' ' .
96  'AND grp_id = ' . $ilDB->quote($a_grp_id, 'integer');
97  $res = $ilDB->query($query);
98  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
99  return $row->num;
100  }
101  return 0;
102  }
103 
108  public static function lookupFailed($a_grp_id)
109  {
110  global $ilDB;
111 
112  $query = 'SELECT count(id) num FROM sysc_tasks ' .
113  'WHERE status = ' . $ilDB->quote(ilSCTask::STATUS_FAILED, 'integer') . ' ' .
114  'AND grp_id = ' . $ilDB->quote($a_grp_id, 'integer');
115  $res = $ilDB->query($query);
116  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
117  return $row->num;
118  }
119  return 0;
120  }
121 
128  public static function lookupLastUpdate($a_grp_id)
129  {
130  global $ilDB;
131 
132  $query = 'SELECT MAX(last_update) last_update FROM sysc_tasks ' .
133  'WHERE status = ' . $ilDB->quote(ilSCTask::STATUS_FAILED, 'integer') . ' ' .
134  'AND grp_id = ' . $ilDB->quote($a_grp_id, 'integer');
135  $res = $ilDB->query($query);
136 
137  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
138  return new ilDateTime($row->last_update, IL_CAL_DATETIME, ilTimeZone::UTC);
139  }
140  return new ilDateTime(time(), IL_CAL_UNIX);
141  }
142 
143  public function getGroupId()
144  {
145  return $this->grp_id;
146  }
147 
152  public function getTasks()
153  {
154  return (array) $this->tasks;
155  }
156 
160  protected function read()
161  {
162  global $ilDB;
163 
164  $query = 'SELECT id FROM sysc_tasks ' .
165  'ORDER BY id ';
166  $res = $ilDB->query($query);
167 
168  $this->tasks = array();
169  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
170  $this->tasks[] = new ilSCTask($row->id);
171  }
172  }
173 }
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.
foreach($_POST as $key=> $value) $res
Date and time handling
$query
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