4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
36 class CRM_Report_Utils_Get
{
38 static function getTypedValue($name, $type) {
39 $value = CRM_Utils_Array
::value($name, $_GET);
40 if ($value === NULL) {
43 return CRM_Utils_Type
::escape($value,
44 CRM_Utils_Type
::typeToString($type),
49 static function dateParam($fieldName, &$field, &$defaults) {
50 // type = 12 (datetime) is not recognized by Utils_Type::escape() method,
51 // and therefore the below hack
54 $from = self
::getTypedValue("{$fieldName}_from", $type);
55 $to = self
::getTypedValue("{$fieldName}_to", $type);
57 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $_GET);
59 list($from, $to) = CRM_Report_Form
::getFromTo($relative, NULL, NULL);
60 $from = substr($from, 0, 8);
61 $to = substr($to, 0, 8);
64 if (!($from ||
$to)) {
69 $dateFrom = CRM_Utils_Date
::setDateDefaults($from);
70 if ($dateFrom !== NULL &&
73 $defaults["{$fieldName}_from"] = $dateFrom[0];
78 $dateTo = CRM_Utils_Date
::setDateDefaults($to);
79 if ($dateTo !== NULL &&
82 $defaults["{$fieldName}_to"] = $dateTo[0];
87 static function stringParam($fieldName, &$field, &$defaults) {
88 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'like');
97 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Array
::value('type', $field));
98 if ($value !== NULL) {
99 $defaults["{$fieldName}_value"] = $value;
100 $defaults["{$fieldName}_op"] = $fieldOP;
106 $defaults["{$fieldName}_op"] = $fieldOP;
110 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
111 if ($value !== NULL) {
112 $defaults["{$fieldName}_value"] = explode(",", $value);
113 $defaults["{$fieldName}_op"] = $fieldOP;
119 static function intParam($fieldName, &$field, &$defaults) {
120 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'eq');
129 $value = self
::getTypedValue("{$fieldName}_value", $field['type']);
130 if ($value !== NULL) {
131 $defaults["{$fieldName}_value"] = $value;
132 $defaults["{$fieldName}_op"] = $fieldOP;
138 $minValue = self
::getTypedValue("{$fieldName}_min", $field['type']);
139 $maxValue = self
::getTypedValue("{$fieldName}_max", $field['type']);
140 if ($minValue !== NULL ||
143 if ($minValue !== NULL) {
144 $defaults["{$fieldName}_min"] = $minValue;
146 if ($maxValue !== NULL) {
147 $defaults["{$fieldName}_max"] = $maxValue;
149 $defaults["{$fieldName}_op"] = $fieldOP;
155 // send the type as string so that multiple values can also be retrieved from url.
156 // for e.g url like - "memtype_in=in&memtype_value=1,2,3"
157 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
158 if (!preg_match('/^(\d+)(,\d+){0,14}$/', $value)) {
159 // extra check. Also put a limit of 15 max values.
162 if ($value !== NULL) {
163 $defaults["{$fieldName}_value"] = explode(",", $value);
164 $defaults["{$fieldName}_op"] = $fieldOP;
170 static function processChart(&$defaults) {
171 $chartType = CRM_Utils_Array
::value("charts", $_GET);
172 if (in_array($chartType, array(
173 'barChart', 'pieChart'))) {
174 $defaults["charts"] = $chartType;
178 static function processFilter(&$fieldGrp, &$defaults) {
179 // process only filters for now
180 foreach ($fieldGrp as $tableName => $fields) {
181 foreach ($fields as $fieldName => $field) {
182 switch (CRM_Utils_Array
::value('type', $field)) {
183 case CRM_Utils_Type
::T_INT
:
184 case CRM_Utils_Type
::T_FLOAT
:
185 case CRM_Utils_Type
::T_MONEY
:
186 self
::intParam($fieldName, $field, $defaults);
189 case CRM_Utils_Type
::T_DATE
:
190 case CRM_Utils_Type
::T_DATE | CRM_Utils_Type
::T_TIME
:
191 self
::dateParam($fieldName, $field, $defaults);
194 case CRM_Utils_Type
::T_STRING
:
196 self
::stringParam($fieldName, $field, $defaults);
203 //unset default filters
204 static function unsetFilters(&$defaults) {
205 static $unsetFlag = TRUE;
207 foreach ($defaults as $field_name => $field_value) {
208 $newstr = substr($field_name, strrpos($field_name, '_'));
209 if ($newstr == '_value' ||
$newstr == '_op' ||
210 $newstr == '_min' ||
$newstr == '_max' ||
211 $newstr == '_from' ||
$newstr == '_to' ||
212 $newstr == '_relative'
214 unset($defaults[$field_name]);
221 static function processGroupBy(&$fieldGrp, &$defaults) {
222 // process only group_bys for now
225 if (is_array($fieldGrp)) {
226 foreach ($fieldGrp as $tableName => $fields) {
227 if ($groupBys = CRM_Utils_Array
::value("gby", $_GET)) {
228 $groupBys = explode(' ', $groupBys);
229 if (!empty($groupBys)) {
231 unset($defaults['group_bys']);
234 foreach ($groupBys as $gby) {
235 if (array_key_exists($gby, $fields)) {
236 $defaults['group_bys'][$gby] = 1;
245 static function processFields(&$reportFields, &$defaults) {
246 //add filters from url
247 if (is_array($reportFields)) {
248 if ($urlFields = CRM_Utils_Array
::value("fld", $_GET)) {
249 $urlFields = explode(',', $urlFields);
251 if (CRM_Utils_Array
::value("ufld", $_GET) == 1) {
252 // unset all display columns
253 $defaults['fields'] = array();
255 if (!empty($urlFields)) {
256 foreach ($reportFields as $tableName => $fields) {
257 foreach ($urlFields as $fld) {
258 if (array_key_exists($fld, $fields)) {
259 $defaults['fields'][$fld] = 1;