-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackendUserAcl.php
117 lines (78 loc) · 2.83 KB
/
BackendUserAcl.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
<?php
/**
* Created by PhpStorm.
* User: tonimoeckel
* Date: 10.12.13
* Time: 19:17
*/
namespace Dreebit;
class BackendUserAcl
{
private static $instance = NULL;
private function __construct(){
}
private function __clone(){
}
public static function getInstance(){
if (self::$instance == NULL){
self::$instance = new self();
}
return self::$instance;
}
/**
* @param String $id
*/
public function isAllowedForProject($pid){
if (\BackendUser::getInstance()->isAdmin){
return true;
}
$projectsArr = \Database::getInstance()->prepare('SELECT id FROM tl_core_project WHERE id=? AND (supplier IN (?) OR customer IN (?))')
->limit(1)
->execute(intval(\Input::get('id')), implode(',',\BackendUser::getInstance()->groups), implode(',',\BackendUser::getInstance()->groups))
->first();
if ($projectsArr) {
return true;
}
return false;
}
/**
* @param String $id
*/
public function isAllowedForRequirement($rid){
if (\BackendUser::getInstance()->isAdmin){
return true;
}
$projectsArr = \Database::getInstance()->prepare('SELECT tl_core_project.id FROM tl_core_project INNER JOIN tl_core_requirement ON tl_core_project.id =tl_core_requirement.pid WHERE tl_core_requirement.id=? AND (tl_core_project.supplier IN (?) OR tl_core_project.customer IN (?))')
->limit(1)
->execute(intval(\Input::get('id')), implode(',',\BackendUser::getInstance()->groups), implode(',',\BackendUser::getInstance()->groups))
->first();
if ($projectsArr) {
return true;
}
return false;
}
public function getProjectForRequirement($id){
$project = \Database::getInstance()->prepare('SELECT * FROM tl_core_requirement INNER JOIN tl_core_project WHERE tl_core_requirement.id=? AND tl_core_project.id = tl_core_requirement.pid')
->limit(1)
->execute($id)
->first();
return $project;
}
public function getRequirement($id){
$requirement = \Database::getInstance()->prepare('SELECT * FROM tl_core_requirement WHERE tl_core_requirement.id=?')
->limit(1)
->execute($id)
->first();
return $requirement;
}
public function getPalletsForUser(){
$pallets = array('{title_legend}','title','state','acceptButton','description','category','steakholder','testCases','prerequisite','influenceTo','files','sub_requirements');
// if (\BackendUser::getInstance()->isAdmin){
//
// }else {
// $insert = array("acceptButton");
// array_splice($pallets,3,0, $insert);
// }
return implode(",",$pallets).';';
}
}