4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
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 public 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),
56 * @param string $fieldName
60 public 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];
99 * @param string $fieldName
103 public 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;
128 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
129 if ($value !== NULL) {
130 $defaults["{$fieldName}_value"] = explode(",", $value);
131 $defaults["{$fieldName}_op"] = $fieldOP;
138 * @param string $fieldName
142 public static function intParam($fieldName, &$field, &$defaults) {
143 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'eq');
152 $value = self
::getTypedValue("{$fieldName}_value", $field['type']);
153 if ($value !== NULL) {
154 $defaults["{$fieldName}_value"] = $value;
155 $defaults["{$fieldName}_op"] = $fieldOP;
161 $minValue = self
::getTypedValue("{$fieldName}_min", $field['type']);
162 $maxValue = self
::getTypedValue("{$fieldName}_max", $field['type']);
163 if ($minValue !== NULL ||
166 if ($minValue !== NULL) {
167 $defaults["{$fieldName}_min"] = $minValue;
169 if ($maxValue !== NULL) {
170 $defaults["{$fieldName}_max"] = $maxValue;
172 $defaults["{$fieldName}_op"] = $fieldOP;
178 // send the type as string so that multiple values can also be retrieved from url.
179 // for e.g url like - "memtype_in=in&memtype_value=1,2,3"
180 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
181 if (!preg_match('/^(\d+)(,\d+){0,14}$/', $value)) {
182 // extra check. Also put a limit of 15 max values.
185 if ($value !== NULL) {
186 $defaults["{$fieldName}_value"] = explode(",", $value);
187 $defaults["{$fieldName}_op"] = $fieldOP;
196 public static function processChart(&$defaults) {
197 $chartType = CRM_Utils_Array
::value("charts", $_GET);
198 if (in_array($chartType, array(
202 $defaults["charts"] = $chartType;
210 public static function processFilter(&$fieldGrp, &$defaults) {
211 // process only filters for now
212 foreach ($fieldGrp as $tableName => $fields) {
213 foreach ($fields as $fieldName => $field) {
214 switch (CRM_Utils_Array
::value('type', $field)) {
215 case CRM_Utils_Type
::T_INT
:
216 case CRM_Utils_Type
::T_FLOAT
:
217 case CRM_Utils_Type
::T_MONEY
:
218 self
::intParam($fieldName, $field, $defaults);
221 case CRM_Utils_Type
::T_DATE
:
222 case CRM_Utils_Type
::T_DATE | CRM_Utils_Type
::T_TIME
:
223 self
::dateParam($fieldName, $field, $defaults);
226 case CRM_Utils_Type
::T_STRING
:
228 self
::stringParam($fieldName, $field, $defaults);
235 //unset default filters
239 public static function unsetFilters(&$defaults) {
240 static $unsetFlag = TRUE;
242 foreach ($defaults as $field_name => $field_value) {
243 $newstr = substr($field_name, strrpos($field_name, '_'));
244 if ($newstr == '_value' ||
$newstr == '_op' ||
245 $newstr == '_min' ||
$newstr == '_max' ||
246 $newstr == '_from' ||
$newstr == '_to' ||
247 $newstr == '_relative'
249 unset($defaults[$field_name]);
260 public static function processGroupBy(&$fieldGrp, &$defaults) {
261 // process only group_bys for now
264 if (is_array($fieldGrp)) {
265 foreach ($fieldGrp as $tableName => $fields) {
266 if ($groupBys = CRM_Utils_Array
::value("gby", $_GET)) {
267 $groupBys = explode(' ', $groupBys);
268 if (!empty($groupBys)) {
270 unset($defaults['group_bys']);
273 foreach ($groupBys as $gby) {
274 if (array_key_exists($gby, $fields)) {
275 $defaults['group_bys'][$gby] = 1;
285 * @param $reportFields
288 public static function processFields(&$reportFields, &$defaults) {
289 //add filters from url
290 if (is_array($reportFields)) {
291 if ($urlFields = CRM_Utils_Array
::value("fld", $_GET)) {
292 $urlFields = explode(',', $urlFields);
294 if (CRM_Utils_Array
::value("ufld", $_GET) == 1) {
295 // unset all display columns
296 $defaults['fields'] = array();
298 if (!empty($urlFields)) {
299 foreach ($reportFields as $tableName => $fields) {
300 foreach ($urlFields as $fld) {
301 if (array_key_exists($fld, $fields)) {
302 $defaults['fields'][$fld] = 1;