1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package org.openpsa.projects |
4
|
|
|
* @author CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
5
|
|
|
* @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/ |
6
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @property integer $project |
11
|
|
|
* @property integer $role |
12
|
|
|
* @property string $description |
13
|
|
|
* @property integer $person |
14
|
|
|
* @property integer $status |
15
|
|
|
* @package org.openpsa.projects |
16
|
|
|
*/ |
17
|
|
|
class org_openpsa_projects_role_dba extends midcom_core_dbaobject |
18
|
|
|
{ |
19
|
|
|
public $__midcom_class_name__ = __CLASS__; |
20
|
|
|
public $__mgdschema_class_name__ = 'org_openpsa_role'; |
21
|
|
|
|
22
|
|
|
public $_use_rcs = false; |
23
|
|
|
|
24
|
19 |
|
public static function add(int $project, int $person, int $role) : bool |
25
|
|
|
{ |
26
|
19 |
|
$mc = self::new_collector('project', $project); |
27
|
19 |
|
$mc->add_constraint('role', '=', $role); |
28
|
19 |
|
$mc->add_constraint('person', '=', $person); |
29
|
19 |
|
$mc->execute(); |
30
|
19 |
|
if ($mc->count() > 0) { |
31
|
|
|
//Resource is already present, aborting silently |
32
|
7 |
|
return true; |
33
|
|
|
} |
34
|
|
|
|
35
|
17 |
|
$new_role = new self(); |
36
|
17 |
|
$new_role->person = $person; |
37
|
17 |
|
$new_role->role = $role; |
38
|
17 |
|
$new_role->project = $project; |
39
|
17 |
|
return $new_role->create(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns true for NO existing duplicates |
44
|
|
|
*/ |
45
|
17 |
|
public function check_duplicates() : bool |
46
|
|
|
{ |
47
|
17 |
|
$qb = new midgard_query_builder('org_openpsa_role'); |
48
|
17 |
|
$qb->add_constraint('person', '=', $this->person); |
49
|
17 |
|
$qb->add_constraint('objectGuid', '=', $this->objectGuid); |
|
|
|
|
50
|
17 |
|
$qb->add_constraint('role', '=', $this->role); |
51
|
|
|
|
52
|
17 |
|
if ($this->id) { |
53
|
|
|
$qb->add_constraint('id', '<>', $this->id); |
54
|
|
|
} |
55
|
|
|
|
56
|
17 |
|
return $qb->count() == 0; |
57
|
|
|
} |
58
|
|
|
|
59
|
17 |
|
public function _on_creating() : bool |
60
|
|
|
{ |
61
|
17 |
|
return $this->check_duplicates(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function _on_updating() : bool |
65
|
|
|
{ |
66
|
|
|
return $this->check_duplicates(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|