-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathExternalModule.php
113 lines (96 loc) · 3.16 KB
/
ExternalModule.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
<?php
/**
* @file
* Provides ExternalModule class for REDCap Entity module.
*/
namespace REDCapEntity\ExternalModule;
require_once 'classes/EntityDB.php';
require_once 'classes/EntityFactory.php';
require_once 'classes/Page.php';
require_once 'classes/EntityFormTrait.php';
require_once 'classes/EntityForm.php';
require_once 'classes/EntityDeleteForm.php';
require_once 'classes/EntityList.php';
require_once 'classes/StatusMessageQueue.php';
use ExternalModules\AbstractExternalModule;
use ExternalModules\ExternalModules;
/**
* ExternalModule class for REDCap Entity module.
*/
class ExternalModule extends AbstractExternalModule {
/**
* @inheritdoc.
*/
function redcap_every_page_before_render($project_id = null) {
define('REDCAP_ENTITY_PREFIX', $this->PREFIX);
}
/**
* @inheritdoc
*/
function redcap_every_page_top($project_id) {
if (strpos(PAGE, 'ExternalModules/manager/control_center.php') === false) {
return;
}
$this->includeJs('manager/js/global_config.js');
$this->setJsSettings(['modulePrefix' => $this->PREFIX]);
}
/**
* @inheritdoc
*/
function redcap_module_system_enable($version) {
// Making sure the module is enabled on all projects.
$this->setSystemSetting(ExternalModules::KEY_ENABLED, true);
}
/**
* Includes a local JS file.
*
* @param string $path
* The relative path to the js file.
*/
function includeJs($path) {
echo '<script src="' . $this->getUrl($path) . '"></script>';
}
/**
* Sets JS settings.
*
* @param mixed $settings
* The setting settings.
*/
protected function setJsSettings($settings) {
echo '<script>redcapEntity = ' . json_encode($settings) . ';</script>';
}
/**
* @return \string[][]
* @throws \Exception
*/
public function getProjectList() {
// get the project list that conforms to the user rights of the current user
$sql = "SELECT p.project_id, p.app_title
FROM redcap_projects p, redcap_user_rights u
WHERE p.project_id = u.project_id
AND p.date_deleted IS NULL
AND u.username = '" . db_real_escape_string( USERID ) . "'";
if (SUPER_USER) {
$sql = "SELECT p.project_id, p.app_title
FROM redcap_projects p
WHERE p.project_id > 15
AND p.date_deleted IS NULL";
}
$queryResults = $this->query( $sql, [] );
// get the Array
$resultArray = $queryResults->fetch_all( MYSQLI_ASSOC );
// Define the array with the Blank entry to be first.
$listArray = [ [ "id" => "", "text" => "--- None ---" ] ];
foreach ( $resultArray as $result ) {
// Translate the data to the standard output
$id = $result["project_id"];
$name = $result["app_title"];
// Accumulate the translated data
$listArray[] = [
'id' => $id,
'text' => "($id) $name"
];
};
return $listArray;
}
}