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
5include_once './Services/SystemCheck/classes/class.ilSCTask.php';
6
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}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
Defines a system check task.
const STATUS_COMPLETED
const STATUS_FAILED
Description of class.
read()
read groups
static getInstanceByGroupId($a_group_id)
Get singleton instance.
getTasks()
Get groups.
static lookupFailed($a_grp_id)
@global type $ilDB
static $instances
static lookupCompleted($a_grp_id)
@global type $ilDB
static lookupGroupId($a_task_id)
Lookup group id by task id @global type $ilDB.
static lookupLastUpdate($a_grp_id)
Lookup last update of group tasks @global type $ilDB.
__construct($a_grp_id)
Singleton constructor.
updateFromComponentDefinition($a_identifier)
Update from module/service reader.
$query
foreach($_POST as $key=> $value) $res
global $ilDB