-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProductionManager.class.php
136 lines (108 loc) · 4.91 KB
/
ProductionManager.class.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
require_once("../userManagement/config.php");
class ProductionManager {
private $DB;
public function __construct ($DB) {
$this->DB = $DB;
}
public function projectExists($projectID) {
if ($this->getProject($projectID)) {
return true;
} else {
return false;
}
}
public function updateProject ($projectID, $data) {
$canvasManager = new CanvasManager($this->DB);
// TODO check for permission
$this->updateProjectMetaData($projectID, $data["Name"], $data["Description"]);
foreach ($data["Panels"] as $panel) {
$canvasManager->updatePanel($projectID, $panel);
// TODO: Prevent manipulating assets that are assigned to another project...
$canvasManager->updateAssets($panel["ID"], $panel["Assets"]);
}
}
public function updateProjectMetaData($id, $name, $description) {
$parameters = Array();
$parameters[":projectID"] = $id;
$parameters[":name"] = $name;
$parameters[":description"] = $description;
$this->DB->query("UPDATE " . PROJECT_TABLE . " SET Name = :name, Description = :description WHERE ID = :projectID", $parameters);
}
public function deleteProject ($projectID) {
// TODO: Warning! Remove related data, like uploaded images and so on?
$parameters = Array();
$parameters[":id"] = $projectID;
return $this->DB->query("DELETE FROM " . PROJECT_TABLE . " WHERE ID = :id", $parameters);
}
public function createProject($name, $description) {
$parameters = Array();
$parameters[":name"] = $name;
if (!array_values($this->DB->getList("SELECT EXISTS(SELECT * FROM " . PROJECT_TABLE . " WHERE Name = :name)", $parameters))[0])
return false;
$parameters[":description"] = $description;
if (!$this->DB->query("INSERT INTO " . PROJECT_TABLE . " (Name, Description, Approved) VALUES (:name, :description, 0)", $parameters))
return false;
return $this->DB->getLastInsertId();
}
public function openProject($projectID) {
$parameters = Array();
$parameters[":projectID"] = $projectID;
return $this->DB->query("UPDATE " . PROJECT_TABLE . " SET Approved = 0 WHERE ID = :projectID", $parameters);
}
public function closeProject($projectID) {
$parameters = Array();
$parameters[":projectID"] = $projectID;
return $this->DB->query("UPDATE " . PROJECT_TABLE . " SET Approved = 1 WHERE ID = :projectID", $parameters);
}
public function getProjectUsers ($projectID) {
$parameters = Array();
$parameters[":projectID"] = $projectID;
return $this->DB->getList("SELECT UserID, Role, Name, Fullname FROM " . USERSINPROJECTS_TABLE . " JOIN " . USER_TABLE . " ON " . USERSINPROJECTS_TABLE . ".UserID = " . USER_TABLE . ".ID " .
"WHERE ProjectID = :projectID", $parameters);
}
public function addUser2Project ($userID, $projectID, $role) {
$parameters = Array();
$parameters[":userID"] = $userID;
$parameters[":projectID"] = $projectID;
if (is_array($this->DB->getRow("SELECT * FROM " . USERSINPROJECTS_TABLE . " WHERE UserID = :userID AND ProjectID = :projectID", $parameters))) {
changeUserRole($userID, $projectID, $role);
} else {
$parameters[":role"] = $role;
$this->DB->query("INSERT INTO " . USERSINPROJECTS_TABLE . " (UserID, ProjectID, Role) VALUES (:userID, :projectID, :role)", $parameters);
}
}
public function changeUserRole ($userID, $projectID, $role) {
$parameters = Array();
$parameters[":userID"] = $userID;
$parameters[":projectID"] = $projectID;
$parameters[":role"] = $role;
$this->DB->query("UPDATE " . USERSINPROJECTS_TABLE . " SET Role = :role WHERE UserID = :userID AND ProjectID = :projectID", $parameters);
}
public function removeUserFromProject ($userID, $projectID) {
$parameters = Array();
$parameters[":userID"] = $userID;
$parameters[":projectID"] = $projectID;
$this->DB->query("DELETE FROM " . USERSINPROJECTS_TABLE . " WHERE UserID = :userID AND ProjectID = :projectID");
}
public function removeAllUsersFromProject ($projectID) {
$parameters = Array();
$parameters[":projectID"] = $projectID;
$this->DB->query("DELETE FROM " . USERSINPROJECTS_TABLE . " WHERE ProjectID = :projectID", $parameters);
}
public function getProject ($projectID) {
$parameters = array();
$parameters[":ProjectID"] = $projectID;
return $this->DB->getRow("SELECT * FROM " . PROJECT_TABLE . " WHERE ID = :ProjectID", $parameters);
}
public function getAllProjects () {
return $this->DB->getList("SELECT * FROM " . PROJECT_TABLE);
}
// Gets the projects the user is associated with and the roles he/she has
public function getBelongedProjects ($userID) {
$parameters = Array();
$parameters[":userID"] = $userID;
return $this->DB->getList("SELECT " . PROJECT_TABLE . ".*, " . USERSINPROJECTS_TABLE . ".Role FROM " . PROJECT_TABLE . " JOIN " . USERSINPROJECTS_TABLE . " ON Projects.ID = " . USERSINPROJECTS_TABLE . ".ProjectID WHERE UserID = :userID", $parameters);
}
}
?>