ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSCTask.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
25{
26 public const STATUS_NOT_ATTEMPTED = 0;
27 public const STATUS_IN_PROGRESS = 1;
28 public const STATUS_COMPLETED = 2;
29 public const STATUS_FAILED = 3;
30
31 private int $id = 0;
32 private int $grp_id = 0;
33 private ?ilDateTime $last_update = null;
34 private int $status = 0;
35 private string $identifier = '';
36
37 protected ilDBInterface $db;
38
39 public function __construct(int $a_id = 0)
40 {
41 global $DIC;
42
43 $this->db = $DIC->database();
44 $this->id = $a_id;
45 $this->read();
46 }
47
48 public function getId(): int
49 {
50 return $this->id;
51 }
52
53 public function setGroupId(int $a_id): void
54 {
55 $this->grp_id = $a_id;
56 }
57
58 public function getGroupId(): int
59 {
60 return $this->grp_id;
61 }
62
63 public function setIdentifier(string $a_ide): void
64 {
65 $this->identifier = $a_ide;
66 }
67
68 public function getIdentifier(): string
69 {
70 return $this->identifier;
71 }
72
73 public function setLastUpdate(ilDateTime $a_update): void
74 {
75 $this->last_update = $a_update;
76 }
77
78 public function getLastUpdate(): ilDateTime
79 {
80 if (!$this->last_update) {
81 return $this->last_update = new ilDateTime();
82 }
83 return $this->last_update;
84 }
85
86 public function setStatus(int $a_status): void
87 {
88 $this->status = $a_status;
89 }
90
91 public function getStatus(): int
92 {
93 return $this->status;
94 }
95
96 public function isActive(): bool
97 {
98 return true;
99 }
100
101 public function read(): bool
102 {
103 if (!$this->getId()) {
104 return false;
105 }
106
107 $query = 'SELECT * FROM sysc_tasks ' .
108 'WHERE id = ' . $this->db->quote($this->getId(), ilDBConstants::T_INTEGER);
109 $res = $this->db->query($query);
110 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
111 $this->setGroupId((int) $row->grp_id);
112 $this->setLastUpdate(new ilDateTime($row->last_update, IL_CAL_DATETIME, ilTimeZone::UTC));
113 $this->setStatus((int) $row->status);
114 $this->setIdentifier((string) $row->identifier);
115 }
116 return true;
117 }
118
119 public function create(): int
120 {
121 $this->id = $this->db->nextId('sysc_tasks');
122
123 $query = 'INSERT INTO sysc_tasks (id,grp_id,status,identifier) ' .
124 'VALUES ( ' .
125 $this->db->quote($this->getId(), ilDBConstants::T_INTEGER) . ', ' .
126 $this->db->quote($this->getGroupId(), ilDBConstants::T_INTEGER) . ', ' .
127 $this->db->quote($this->getStatus(), ilDBConstants::T_INTEGER) . ', ' .
128 $this->db->quote($this->getIdentifier(), ilDBConstants::T_TEXT) . ' ' .
129 ')';
130 $this->db->manipulate($query);
131 return $this->getId();
132 }
133
134 public function update(): void
135 {
136 $query = 'UPDATE sysc_tasks SET ' .
137 'last_update = ' . $this->db->quote($this->getLastUpdate()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC), ilDBConstants::T_TIMESTAMP) . ', ' .
138 'status = ' . $this->db->quote($this->getStatus(), ilDBConstants::T_INTEGER) . ', ' .
139 'identifier = ' . $this->db->quote($this->getIdentifier(), ilDBConstants::T_TEXT) . ' ' .
140 'WHERE id = ' . $this->db->quote($this->getId(), ilDBConstants::T_INTEGER);
141 $this->db->manipulate($query);
142 }
143}
const IL_CAL_DATETIME
@classDescription Date and time handling
Defines a system check task.
const STATUS_COMPLETED
ilDBInterface $db
const STATUS_FAILED
setGroupId(int $a_id)
ilDateTime $last_update
const STATUS_IN_PROGRESS
setIdentifier(string $a_ide)
const STATUS_NOT_ATTEMPTED
__construct(int $a_id=0)
setStatus(int $a_status)
setLastUpdate(ilDateTime $a_update)
string $identifier
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26