4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
36 class CRM_Report_Utils_Get
{
44 static function getTypedValue($name, $type) {
45 $value = CRM_Utils_Array
::value($name, $_GET);
46 if ($value === NULL) {
49 return CRM_Utils_Type
::escape($value,
50 CRM_Utils_Type
::typeToString($type),
60 static function dateParam($fieldName, &$field, &$defaults) {
61 // type = 12 (datetime) is not recognized by Utils_Type::escape() method,
62 // and therefore the below hack
65 $from = self
::getTypedValue("{$fieldName}_from", $type);
66 $to = self
::getTypedValue("{$fieldName}_to", $type);
68 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $_GET);
70 list($from, $to) = CRM_Report_Form
::getFromTo($relative, NULL, NULL);
71 $from = substr($from, 0, 8);
72 $to = substr($to, 0, 8);
75 if (!($from ||
$to)) {
80 $dateFrom = CRM_Utils_Date
::setDateDefaults($from);
81 if ($dateFrom !== NULL &&
84 $defaults["{$fieldName}_from"] = $dateFrom[0];
89 $dateTo = CRM_Utils_Date
::setDateDefaults($to);
90 if ($dateTo !== NULL &&
93 $defaults["{$fieldName}_to"] = $dateTo[0];
103 static function stringParam($fieldName, &$field, &$defaults) {
104 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'like');
113 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Array
::value('type', $field));
114 if ($value !== NULL) {
115 $defaults["{$fieldName}_value"] = $value;
116 $defaults["{$fieldName}_op"] = $fieldOP;
122 $defaults["{$fieldName}_op"] = $fieldOP;
127 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
128 if ($value !== NULL) {
129 $defaults["{$fieldName}_value"] = explode(",", $value);
130 $defaults["{$fieldName}_op"] = $fieldOP;
141 static function intParam($fieldName, &$field, &$defaults) {
142 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'eq');
151 $value = self
::getTypedValue("{$fieldName}_value", $field['type']);
152 if ($value !== NULL) {
153 $defaults["{$fieldName}_value"] = $value;
154 $defaults["{$fieldName}_op"] = $fieldOP;
160 $minValue = self
::getTypedValue("{$fieldName}_min", $field['type']);
161 $maxValue = self
::getTypedValue("{$fieldName}_max", $field['type']);
162 if ($minValue !== NULL ||
165 if ($minValue !== NULL) {
166 $defaults["{$fieldName}_min"] = $minValue;
168 if ($maxValue !== NULL) {
169 $defaults["{$fieldName}_max"] = $maxValue;
171 $defaults["{$fieldName}_op"] = $fieldOP;
177 // send the type as string so that multiple values can also be retrieved from url.
178 // for e.g url like - "memtype_in=in&memtype_value=1,2,3"
179 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
180 if (!preg_match('/^(\d+)(,\d+){0,14}$/', $value)) {
181 // extra check. Also put a limit of 15 max values.
184 if ($value !== NULL) {
185 $defaults["{$fieldName}_value"] = explode(",", $value);
186 $defaults["{$fieldName}_op"] = $fieldOP;
195 static function processChart(&$defaults) {
196 $chartType = CRM_Utils_Array
::value("charts", $_GET);
197 if (in_array($chartType, array(
198 'barChart', 'pieChart'))) {
199 $defaults["charts"] = $chartType;
207 static function processFilter(&$fieldGrp, &$defaults) {
208 // process only filters for now
209 foreach ($fieldGrp as $tableName => $fields) {
210 foreach ($fields as $fieldName => $field) {
211 switch (CRM_Utils_Array
::value('type', $field)) {
212 case CRM_Utils_Type
::T_INT
:
213 case CRM_Utils_Type
::T_FLOAT
:
214 case CRM_Utils_Type
::T_MONEY
:
215 self
::intParam($fieldName, $field, $defaults);
218 case CRM_Utils_Type
::T_DATE
:
219 case CRM_Utils_Type
::T_DATE | CRM_Utils_Type
::T_TIME
:
220 self
::dateParam($fieldName, $field, $defaults);
223 case CRM_Utils_Type
::T_STRING
:
225 self
::stringParam($fieldName, $field, $defaults);
232 //unset default filters
236 static function unsetFilters(&$defaults) {
237 static $unsetFlag = TRUE;
239 foreach ($defaults as $field_name => $field_value) {
240 $newstr = substr($field_name, strrpos($field_name, '_'));
241 if ($newstr == '_value' ||
$newstr == '_op' ||
242 $newstr == '_min' ||
$newstr == '_max' ||
243 $newstr == '_from' ||
$newstr == '_to' ||
244 $newstr == '_relative'
246 unset($defaults[$field_name]);
257 static function processGroupBy(&$fieldGrp, &$defaults) {
258 // process only group_bys for now
261 if (is_array($fieldGrp)) {
262 foreach ($fieldGrp as $tableName => $fields) {
263 if ($groupBys = CRM_Utils_Array
::value("gby", $_GET)) {
264 $groupBys = explode(' ', $groupBys);
265 if (!empty($groupBys)) {
267 unset($defaults['group_bys']);
270 foreach ($groupBys as $gby) {
271 if (array_key_exists($gby, $fields)) {
272 $defaults['group_bys'][$gby] = 1;
282 * @param $reportFields
285 static function processFields(&$reportFields, &$defaults) {
286 //add filters from url
287 if (is_array($reportFields)) {
288 if ($urlFields = CRM_Utils_Array
::value("fld", $_GET)) {
289 $urlFields = explode(',', $urlFields);
291 if (CRM_Utils_Array
::value("ufld", $_GET) == 1) {
292 // unset all display columns
293 $defaults['fields'] = array();
295 if (!empty($urlFields)) {
296 foreach ($reportFields as $tableName => $fields) {
297 foreach ($urlFields as $fld) {
298 if (array_key_exists($fld, $fields)) {
299 $defaults['fields'][$fld] = 1;