3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 class CRM_Report_Utils_Get
{
43 public static function getTypedValue($name, $type) {
44 $value = CRM_Utils_Array
::value($name, $_GET);
45 if ($value === NULL) {
48 return CRM_Utils_Type
::escape($value,
49 CRM_Utils_Type
::typeToString($type),
55 * @param string $fieldName
61 public static function dateParam($fieldName, &$field, &$defaults) {
62 // type = 12 (datetime) is not recognized by Utils_Type::escape() method,
63 // and therefore the below hack
66 $from = self
::getTypedValue("{$fieldName}_from", $type);
67 $to = self
::getTypedValue("{$fieldName}_to", $type);
69 $relative = self
::getTypedValue("{$fieldName}_relative", CRM_Utils_Type
::T_STRING
);
70 if ($relative !== NULL) {
71 $defaults["{$fieldName}_relative"] = $relative;
74 list($from, $to) = CRM_Utils_Date
::getFromTo($relative, NULL, NULL);
75 $from = substr($from, 0, 8);
76 $to = substr($to, 0, 8);
79 if (!($from ||
$to)) {
84 $dateFrom = CRM_Utils_Date
::setDateDefaults($from);
85 if ($dateFrom !== NULL &&
88 $defaults["{$fieldName}_from"] = $dateFrom[0];
93 $dateTo = CRM_Utils_Date
::setDateDefaults($to);
94 if ($dateTo !== NULL &&
97 $defaults["{$fieldName}_to"] = $dateTo[0];
103 * @param string $fieldName
107 public static function stringParam($fieldName, &$field, &$defaults) {
108 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'like');
117 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Array
::value('type', $field));
118 if ($value !== NULL) {
119 $defaults["{$fieldName}_value"] = $value;
120 $defaults["{$fieldName}_op"] = $fieldOP;
126 $defaults["{$fieldName}_op"] = $fieldOP;
132 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
133 if ($value !== NULL) {
134 $defaults["{$fieldName}_value"] = explode(",", $value);
135 $defaults["{$fieldName}_op"] = $fieldOP;
142 * @param string $fieldName
146 public static function intParam($fieldName, &$field, &$defaults) {
147 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'eq');
156 $value = self
::getTypedValue("{$fieldName}_value", $field['type']);
157 if ($value !== NULL) {
158 $defaults["{$fieldName}_value"] = $value;
159 $defaults["{$fieldName}_op"] = $fieldOP;
165 $minValue = self
::getTypedValue("{$fieldName}_min", $field['type']);
166 $maxValue = self
::getTypedValue("{$fieldName}_max", $field['type']);
167 if ($minValue !== NULL ||
170 if ($minValue !== NULL) {
171 $defaults["{$fieldName}_min"] = $minValue;
173 if ($maxValue !== NULL) {
174 $defaults["{$fieldName}_max"] = $maxValue;
176 $defaults["{$fieldName}_op"] = $fieldOP;
182 // send the type as string so that multiple values can also be retrieved from url.
183 // for e.g url like - "memtype_in=in&memtype_value=1,2,3"
184 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
185 if (!preg_match('/^(\d+)(,\d+){0,14}$/', $value)) {
186 // extra check. Also put a limit of 15 max values.
189 if ($value !== NULL) {
190 $defaults["{$fieldName}_value"] = explode(",", $value);
191 $defaults["{$fieldName}_op"] = $fieldOP;
200 public static function processChart(&$defaults) {
201 $chartType = CRM_Utils_Array
::value("charts", $_GET);
202 if (in_array($chartType, array(
206 $defaults["charts"] = $chartType;
214 public static function processFilter(&$fieldGrp, &$defaults) {
215 // process only filters for now
216 foreach ($fieldGrp as $tableName => $fields) {
217 foreach ($fields as $fieldName => $field) {
218 switch (CRM_Utils_Array
::value('type', $field)) {
219 case CRM_Utils_Type
::T_INT
:
220 case CRM_Utils_Type
::T_FLOAT
:
221 case CRM_Utils_Type
::T_MONEY
:
222 self
::intParam($fieldName, $field, $defaults);
225 case CRM_Utils_Type
::T_DATE
:
226 case CRM_Utils_Type
::T_DATE | CRM_Utils_Type
::T_TIME
:
227 self
::dateParam($fieldName, $field, $defaults);
230 case CRM_Utils_Type
::T_STRING
:
232 self
::stringParam($fieldName, $field, $defaults);
240 * unset default filters.
243 public static function unsetFilters(&$defaults) {
244 static $unsetFlag = TRUE;
246 foreach ($defaults as $field_name => $field_value) {
247 $newstr = substr($field_name, strrpos($field_name, '_'));
248 if ($newstr == '_value' ||
$newstr == '_op' ||
249 $newstr == '_min' ||
$newstr == '_max' ||
250 $newstr == '_from' ||
$newstr == '_to' ||
251 $newstr == '_relative'
253 unset($defaults[$field_name]);
264 public static function processGroupBy(&$fieldGrp, &$defaults) {
265 // process only group_bys for now
268 if (is_array($fieldGrp)) {
269 foreach ($fieldGrp as $tableName => $fields) {
270 if ($groupBys = CRM_Utils_Array
::value("gby", $_GET)) {
271 $groupBys = explode(' ', $groupBys);
272 if (!empty($groupBys)) {
274 unset($defaults['group_bys']);
277 foreach ($groupBys as $gby) {
278 if (array_key_exists($gby, $fields)) {
279 $defaults['group_bys'][$gby] = 1;
289 * @param $reportFields
292 public static function processFields(&$reportFields, &$defaults) {
293 //add filters from url
294 if (is_array($reportFields)) {
295 if ($urlFields = CRM_Utils_Array
::value("fld", $_GET)) {
296 $urlFields = explode(',', $urlFields);
298 if (CRM_Utils_Array
::value("ufld", $_GET) == 1) {
299 // unset all display columns
300 $defaults['fields'] = array();
302 if (!empty($urlFields)) {
303 foreach ($reportFields as $tableName => $fields) {
304 foreach ($urlFields as $fld) {
305 if (array_key_exists($fld, $fields)) {
306 $defaults['fields'][$fld] = 1;