ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 static function lookupIdentifierForTask($a_task_id)
50 {
51 global $DIC;
52
53 $db = $DIC->database();
54 $query = 'select identifier from sysc_tasks ' .
55 'where id = ' . $db->quote($a_task_id, 'integer');
56 $res = $db->query($query);
57 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
58 return $row->identifier;
59 }
60 return '';
61 }
62
63
69 public function updateFromComponentDefinition($a_identifier)
70 {
71 foreach ($this->getTasks() as $task) {
72 if ($task->getIdentifier() == $a_identifier) {
73 return true;
74 }
75 }
76
77 $task = new ilSCTask();
78 $task->setGroupId($this->getGroupId());
79 $task->setIdentifier($a_identifier);
80 $task->create();
81
82 return $task->getId();
83 }
84
85
86
93 public static function lookupGroupId($a_task_id)
94 {
95 global $DIC;
96
97 $ilDB = $DIC['ilDB'];
98
99 $query = 'SELECT grp_id FROM sysc_tasks ' .
100 'WHERE id = ' . $ilDB->quote($a_task_id, 'integer');
101 $res = $ilDB->query($query);
102 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
103 return $row->grp_id;
104 }
105 return 0;
106 }
107
110 public static function lookupCompleted($a_grp_id)
111 {
113
114 $num_completed = 0;
115 foreach ($tasks->getTasks() as $task) {
116 if (!$task->isActive()) {
117 continue;
118 }
119 if ($task->getStatus() == ilSCTask::STATUS_COMPLETED) {
120 $num_completed++;
121 }
122 }
123 return $num_completed;
124 }
125
128 public static function lookupFailed($a_grp_id)
129 {
131
132 $num_failed = 0;
133 foreach ($tasks->getTasks() as $task) {
134 if (!$task->isActive()) {
135 continue;
136 }
137
138 if ($task->getStatus() == ilSCTask::STATUS_FAILED) {
139 $num_failed++;
140 }
141 }
142 return $num_failed;
143 }
144
151 public static function lookupLastUpdate($a_grp_id)
152 {
153 global $DIC;
154
155 $ilDB = $DIC['ilDB'];
156
157 $query = 'SELECT MAX(last_update) last_update FROM sysc_tasks ' .
158 'WHERE status = ' . $ilDB->quote(ilSCTask::STATUS_FAILED, 'integer') . ' ' .
159 'AND grp_id = ' . $ilDB->quote($a_grp_id, 'integer');
160 $res = $ilDB->query($query);
161
162 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163 return new ilDateTime($row->last_update, IL_CAL_DATETIME, ilTimeZone::UTC);
164 }
165 return new ilDateTime(time(), IL_CAL_UNIX);
166 }
167
168 public function getGroupId()
169 {
170 return $this->grp_id;
171 }
172
177 public function getTasks()
178 {
179 return (array) $this->tasks;
180 }
181
185 protected function read()
186 {
187 global $DIC;
188
189 $ilDB = $DIC['ilDB'];
190
191 $query = 'SELECT id, grp_id FROM sysc_tasks ' .
192 'ORDER BY id ';
193 $res = $ilDB->query($query);
194
195 $this->tasks = array();
196 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
197 $this->tasks[] = ilSCComponentTaskFactory::getTask($row->grp_id, $row->id);
198 }
199 }
200}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
static getTask($a_group_id, $a_task_id)
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)
static $instances
static lookupCompleted($a_grp_id)
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.
static lookupIdentifierForTask($a_task_id)
__construct($a_grp_id)
Singleton constructor.
updateFromComponentDefinition($a_identifier)
Update from module/service reader.
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB