-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utilities.php
47 lines (43 loc) · 1.55 KB
/
Utilities.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
<?php
/**
* This file is par of getQuestionInformation plugin
* @license AGPL v3
*/
namespace getQuestionInformation;
Class Utilities
{
/**
* @var string current api version of this file
*/
const API = "3.2.0";
/**
* @param integer $surveyId
* @param string $extraFilters : one filter by line, colun and filter must be separated by :
* @return array : column by key, value is value not managed
*/
public static function getFinalOtherFilter($surveyId, $extraFilters)
{
$aFiltersFields = array();
$extraFilters = trim($extraFilters);
if($extraFilters == "") {
return $aFiltersFields;
}
$aColumnToCode = \getQuestionInformation\helpers\surveyCodeHelper::getAllQuestions($surveyId);
$aCodeToColumn = array_flip($aColumnToCode);
$availableColumns = \SurveyDynamic::model($surveyId)->getAttributes();
$aFieldsLines = preg_split('/\r\n|\r|\n/', $extraFilters, -1, PREG_SPLIT_NO_EMPTY);
foreach ($aFieldsLines as $aFieldLine) {
if (!strpos($aFieldLine, ":")) {
continue; // Invalid line
}
$key = substr($aFieldLine, 0, strpos($aFieldLine, ":"));
$value = substr($aFieldLine, strpos($aFieldLine, ":")+1);
if (array_key_exists($key, $availableColumns)) {
$aFiltersFields[$key] = $value;
} elseif(isset($aCodeToColumn[$key])) {
$aFiltersFields[$aCodeToColumn[$key]] = $value;
}
}
return $aFiltersFields;
}
}