This repository was archived by the owner on Feb 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtils.php
More file actions
84 lines (71 loc) · 2.65 KB
/
StringUtils.php
File metadata and controls
84 lines (71 loc) · 2.65 KB
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
<?php
namespace uzgent\StringUtils;
// Declare your module class, which must extend AbstractExternalModule
use REDCap;
require_once "AnnotationParser.php";
class StringUtils extends \ExternalModules\AbstractExternalModule {
const annotation = ["@TOLOWER", "@TOUPPER", "@SUBSTR", "@LTRIM", "@RTRIM", "@TRIM", "@STRLEN", "@INDEXOF", "@CONCAT", "@RIGHT", "@LEFT", "@REPLACE"];
public function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance)
{
$listeners = [];
$warnings = [];
$fieldNames = $this->getFieldNames($project_id);
foreach ($this->getMetadata($project_id) as $field) {
$field_annotation = $field['field_annotation'];
foreach (self::annotation as $annotation)
{
if (strpos($field_annotation, $annotation) !== false) {
list($warnings, $listeners) = AnnotationParser::getListenersFromAnot($field_annotation, $field, $annotation, $listeners, $warnings, $fieldNames);
}
}
}
$this->showWarnings($listeners, $fieldNames, $warnings);
$this->writeListeners($listeners);
}
public function redcap_survey_page($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance)
{
$this->redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance);
}
/**
* @param $project_id
* @param array $fieldNames
* @return array
*/
public function getFieldNames($project_id)
{
$fieldNames = [];
foreach ($this->getMetadata($project_id) as $field) {
$fieldNames [] = $field["field_name"];
}
return $fieldNames;
}
/**
* @param array $listeners
* @param array $fieldNames
* @param array $warnings
*/
public function showWarnings(array $listeners, array $fieldNames, array $warnings)
{
foreach ($listeners as $sourceField => $code) {
if (!in_array($sourceField, $fieldNames)) {
echo '<div class="alert">The following field is used but cannot be found: ' . $sourceField . '</div>';
}
}
foreach ($warnings as $warning) {
echo '<div class="alert">' . $warning . '</div>';
}
}
/**
* @param array $listeners
*/
public function writeListeners(array $listeners)
{
echo '<script>';
foreach ($listeners as $sourceField => $code) {
echo '$("input[name=\'' . $sourceField . '\']").keyup(function(){';
echo $code;
echo '} );';
}
echo '</script>';
}
}