-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtaskmanager.php
77 lines (63 loc) · 2.19 KB
/
taskmanager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* This file is part of InfectedAPI.
*
* Copyright (C) 2017 Infected <http://infected.no/>.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'settings.php';
require_once 'database.php';
require_once 'interfaces/task.php';
class TaskManager {
/*
* Get a task by given id.
*/
public static function getTask(int $id): ?object {
$database = Database::getConnection(Settings::db_name_infected);
$result = $database->query('SELECT * FROM `'. Settings::db_table_infected_tasks . '`
WHERE `id` = \'' . $database->real_escape_string($id) . '\';');
$row = $result->fetch_array();
return unserialize($row['object']);
}
/*
* Get a list of all the tasks.
*/
public static function getTasks(): array {
$database = Database::getConnection(Settings::db_name_infected);
$result = $database->query('SELECT * FROM `'. Settings::db_table_infected_tasks . '`;');
$taskList = [];
while ($row = $result->fetch_row()) {
$taskList[] = unserialize($row['object']);
}
return $taskList;
}
/*
* Create new task.
*/
public static function createTask(ITask $task) {
$database = Database::getConnection(Settings::db_name_infected);
$database->query('INSERT INTO `' . Settings::db_table_infected_tasks . '` (`object`)
VALUES (\'' . serialize($task) . '\');');
}
/*
* Remove a task.
*/
public static function removeTask(int $id) {
$database = Database::getConnection(Settings::db_name_infected);
$database->query('DELETE FROM `' . Settings::db_table_infected_tasks . '`
WHERE `id` = \'' . $id . '\';');
}
}
?>