Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 0fa32b5

Browse files
committed
Also add right function.
1 parent 875f146 commit 0fa32b5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

StringUtils.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class StringUtils extends \ExternalModules\AbstractExternalModule {
1010

11-
const annotation = ["@TOLOWER", "@TOUPPER", "@SUBSTR", "@LTRIM", "@RTRIM", "@TRIM", "@STRLEN", "@INDEXOF", "@CONCAT"];
11+
const annotation = ["@TOLOWER", "@TOUPPER", "@SUBSTR", "@LTRIM", "@RTRIM", "@TRIM", "@STRLEN", "@INDEXOF", "@CONCAT", "@RIGHT"];
1212

1313

1414
public function redcap_data_entry_form($project_id, $record, $instrument, $event_id, $group_id, $repeat_instance)
@@ -127,6 +127,16 @@ public function getListenersFromAnot($field_annotation, $field, $annotation, arr
127127
}
128128
$listeners[$selectedFields[0]] .= '$("input[name=\'' . $destinationField . '\']").val($("input[name=\'' . $selectedFields[0] . '\']").val().substr(' . $selectedFields[1] . ', ' . $selectedFields[2] . '));';
129129
break;
130+
case "@RIGHT":
131+
$selectedFields = explode(",", $sourceField);
132+
if (!is_numeric($selectedFields[1])) {
133+
$warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[1] . ' is not numeric';
134+
}
135+
if (!in_array($selectedFields[0], $fieldNames)) {
136+
$warnings [] = 'For field: ' . $destinationField . ' ' . $selectedFields[0] . ' is not a field.';
137+
}
138+
$listeners[$selectedFields[0]] .= '$("input[name=\'' . $destinationField . '\']").val($("input[name=\'' . $selectedFields[0] . '\']").val().substr($("input[name=\'' . $selectedFields[0] . '\']").val().length - ' . $selectedFields[1] . ', $("input[name=\'' . $selectedFields[0] . '\']").val().length));';
139+
break;
130140
case "@CONCAT":
131141
$sourceFieldsConcat = [];
132142
$explodedSource = explode (",", $sourceField);

howto.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ <h1><span class="glyphicon glyphicon-info-sign"></span> How to use the StringUti
100100
Takes a part of a string from <code>start</code>, returns the specified number of characters (<code>length</code>). <code>start</code> and <code>length</code> must be valid integers.
101101
</td>
102102
</tr>
103+
<tr>
104+
<td>
105+
@RIGHT=sourcefieldnamehere,length
106+
</td>
107+
<td>
108+
Returns the <code>length</code> number of characters from the end of a text string.
109+
</td>
110+
</tr>
103111
<tr>
104112
<td>
105113
@CONCAT=field1,field2,field3,...

0 commit comments

Comments
 (0)