-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowByRolesClass.php
53 lines (42 loc) · 1.46 KB
/
ShowByRolesClass.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
<?php
namespace uzgent\ShowByRolesClass;
require_once ("ShowByRolesParser.php");
// Declare your module class, which must extend AbstractExternalModule
class ShowByRolesClass extends \ExternalModules\AbstractExternalModule {
public function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance)
{
//Get the current role.
$userInitiator = \UserRights::getRightsAllUsers();
$roleId = $userInitiator[USERID]["role_id"];
$projectRoles = \UserRights::getRoles();
$fieldsToHide = [];
$metadata = $this->getMetadata($project_id, $instrument);
foreach($metadata as $fieldname => $values)
{
$foundUserRoleIds = ShowByRolesParser::parseAnnotationRoleIds($values, $projectRoles);
if ($foundUserRoleIds != null)
{
if (!in_array($roleId, $foundUserRoleIds))
{
$fieldsToHide[]= $fieldname;
}
}
}
$this->printJavaScriptHiders($fieldsToHide);
}
/**
* @param $fieldsToHide
*/
public function printJavaScriptHiders($fieldsToHide)
{
echo "<script>";
include "hideaway.js";
echo "function hideAll() { ";
foreach ($fieldsToHide as $fieldToHide) {
echo 'UZG_hideaway.hideIt("' . $fieldToHide . '");';
}
echo "}";
echo "hideAll();\n";
echo "</script>";
}
}