|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
Copyright (C) 2018-2020 KANOUN Salim |
|
4
|
|
|
This program is free software; you can redistribute it and/or modify |
|
5
|
|
|
it under the terms of the Affero GNU General Public v.3 License as published by |
|
6
|
|
|
the Free Software Foundation; |
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10
|
|
|
Affero GNU General Public Public for more details. |
|
11
|
|
|
You should have received a copy of the Affero GNU General Public Public along |
|
12
|
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
|
13
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Object handeling Documentation data in Database |
|
18
|
|
|
* @author salim |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
class Documentation { |
|
22
|
|
|
|
|
23
|
|
|
public $documentId; |
|
24
|
|
|
public $study; |
|
25
|
|
|
public $documentName; |
|
26
|
|
|
public $documentFileLocation; |
|
27
|
|
|
public $documentVersion; |
|
28
|
|
|
public $documentDate; |
|
29
|
|
|
public $accessInvestigator; |
|
30
|
|
|
public $accessController; |
|
31
|
|
|
public $accessMonitor; |
|
32
|
|
|
public $accessReviewer; |
|
33
|
|
|
public $deleted; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function __construct(PDO $linkpdo, int $idDocumentation) { |
|
37
|
|
|
|
|
38
|
|
|
$documentationQuery=$linkpdo->prepare("SELECT * FROM documentation WHERE id_documentation = :idDocumentation"); |
|
39
|
|
|
$documentationQuery->execute(array('idDocumentation' => $idDocumentation)); |
|
40
|
|
|
$documentation=$documentationQuery->fetch(PDO::FETCH_ASSOC); |
|
41
|
|
|
|
|
42
|
|
|
$this->documentId=$documentation['id_documentation']; |
|
43
|
|
|
$this->study=$documentation['study']; |
|
44
|
|
|
$this->documentName=$documentation['name']; |
|
45
|
|
|
$this->documentVersion=$documentation['version']; |
|
46
|
|
|
$this->documentDate=$documentation['document_date']; |
|
47
|
|
|
$this->accessInvestigator=$documentation['investigator']; |
|
48
|
|
|
$this->accessController=$documentation['controller']; |
|
49
|
|
|
$this->accessMonitor=$documentation['monitor']; |
|
50
|
|
|
$this->accessReviewer=$documentation['reviewer']; |
|
51
|
|
|
$this->deleted=$documentation['deleted']; |
|
52
|
|
|
|
|
53
|
|
|
$this->documentFileLocation=($_SERVER['DOCUMENT_ROOT']."/data/upload/documentation/".$this->study."/".$this->documentName); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Return if the current documentation is allowed for a given role |
|
58
|
|
|
* @param String $role |
|
59
|
|
|
* @return boolean |
|
60
|
|
|
*/ |
|
61
|
|
|
|
|
62
|
|
|
public function isDocumentationAllowedForRole(String $role) { |
|
63
|
|
|
if ($role == User::INVESTIGATOR) { |
|
64
|
|
|
return $this->accessInvestigator; |
|
65
|
|
|
}else if ($role == User::CONTROLLER) { |
|
66
|
|
|
return $this->accessController; |
|
67
|
|
|
}else if ($role == User::MONITOR) { |
|
68
|
|
|
return $this->accessMonitor; |
|
69
|
|
|
}else if ($role == User::REVIEWER) { |
|
70
|
|
|
return $this->accessReviewer; |
|
71
|
|
|
}else if ($role == User::SUPERVISOR) { |
|
72
|
|
|
return true; |
|
73
|
|
|
}else { |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Update documentation table |
|
80
|
|
|
* @param PDO $linkpdo |
|
81
|
|
|
* @param int $idDocumentation |
|
82
|
|
|
* @param bool $investigator |
|
83
|
|
|
* @param bool $monitor |
|
84
|
|
|
* @param bool $controller |
|
85
|
|
|
* @param bool $reviewer |
|
86
|
|
|
* @param bool $deleted |
|
87
|
|
|
*/ |
|
88
|
|
|
public static function updateDocumentation(PDO $linkpdo, int $idDocumentation, bool $investigator, bool $monitor, bool $controller, bool $reviewer, bool $deleted) { |
|
89
|
|
|
$update=$linkpdo->prepare('UPDATE documentation |
|
90
|
|
|
SET investigator = :investigator, |
|
91
|
|
|
controller = :controller, |
|
92
|
|
|
monitor = :monitor, |
|
93
|
|
|
reviewer=:reviewer, |
|
94
|
|
|
deleted=:deleted |
|
95
|
|
|
WHERE id_documentation = :id'); |
|
96
|
|
|
|
|
97
|
|
|
$update->execute(array('investigator' => intval($investigator), |
|
98
|
|
|
'controller' => intval($controller), |
|
99
|
|
|
'monitor' => intval($monitor), |
|
100
|
|
|
'reviewer' =>intval($reviewer), |
|
101
|
|
|
'deleted'=>intval($deleted), |
|
102
|
|
|
'id' => $idDocumentation)); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Create documentation entry in database |
|
107
|
|
|
* @param PDO $linkpdo |
|
108
|
|
|
* @param String $uploadedFilename |
|
109
|
|
|
* @param String $study |
|
110
|
|
|
* @param String $version |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function insertDocumentation(PDO $linkpdo, String $uploadedFilename, String $study, String $version) { |
|
113
|
|
|
$insertion=$linkpdo->prepare('INSERT INTO documentation (name, document_date, study, version) |
|
114
|
|
|
VALUES (:name, :doc_date, :study, :version)'); |
|
115
|
|
|
$insertion->execute(array( |
|
116
|
|
|
'name' => $uploadedFilename, |
|
117
|
|
|
'doc_date' => date("Y-m-d"), |
|
118
|
|
|
'study' => $study, |
|
119
|
|
|
'version'=>$version |
|
120
|
|
|
)); |
|
121
|
|
|
} |
|
122
|
|
|
} |