5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
37 class CRM_Report_Utils_Get
{
39 static function getTypedValue($name, $type) {
40 $value = CRM_Utils_Array
::value($name, $_GET);
41 if ($value === NULL) {
44 return CRM_Utils_Type
::escape($value,
45 CRM_Utils_Type
::typeToString($type),
50 static function dateParam($fieldName, &$field, &$defaults) {
51 // type = 12 (datetime) is not recognized by Utils_Type::escape() method,
52 // and therefore the below hack
55 $from = self
::getTypedValue("{$fieldName}_from", $type);
56 $to = self
::getTypedValue("{$fieldName}_to", $type);
58 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $_GET);
60 list($from, $to) = CRM_Report_Form
::getFromTo($relative, NULL, NULL);
61 $from = substr($from, 0, 8);
62 $to = substr($to, 0, 8);
65 if (!($from ||
$to)) {
70 $dateFrom = CRM_Utils_Date
::setDateDefaults($from);
71 if ($dateFrom !== NULL &&
74 $defaults["{$fieldName}_from"] = $dateFrom[0];
79 $dateTo = CRM_Utils_Date
::setDateDefaults($to);
80 if ($dateTo !== NULL &&
83 $defaults["{$fieldName}_to"] = $dateTo[0];
88 static function stringParam($fieldName, &$field, &$defaults) {
89 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'like');
98 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Array
::value('type', $field));
99 if ($value !== NULL) {
100 $defaults["{$fieldName}_value"] = $value;
101 $defaults["{$fieldName}_op"] = $fieldOP;
107 $defaults["{$fieldName}_op"] = $fieldOP;
112 static function intParam($fieldName, &$field, &$defaults) {
113 $fieldOP = CRM_Utils_Array
::value("{$fieldName}_op", $_GET, 'eq');
122 $value = self
::getTypedValue("{$fieldName}_value", $field['type']);
123 if ($value !== NULL) {
124 $defaults["{$fieldName}_value"] = $value;
125 $defaults["{$fieldName}_op"] = $fieldOP;
131 $minValue = self
::getTypedValue("{$fieldName}_min", $field['type']);
132 $maxValue = self
::getTypedValue("{$fieldName}_max", $field['type']);
133 if ($minValue !== NULL ||
136 if ($minValue !== NULL) {
137 $defaults["{$fieldName}_min"] = $minValue;
139 if ($maxValue !== NULL) {
140 $defaults["{$fieldName}_max"] = $maxValue;
142 $defaults["{$fieldName}_op"] = $fieldOP;
148 // send the type as string so that multiple values can also be retrieved from url.
149 // for e.g url like - "memtype_in=in&memtype_value=1,2,3"
150 $value = self
::getTypedValue("{$fieldName}_value", CRM_Utils_Type
::T_STRING
);
151 if (!preg_match('/^(\d+)(,\d+){0,14}$/', $value)) {
152 // extra check. Also put a limit of 15 max values.
155 if ($value !== NULL) {
156 $defaults["{$fieldName}_value"] = explode(",", $value);
157 $defaults["{$fieldName}_op"] = $fieldOP;
163 static function processChart(&$defaults) {
164 $chartType = CRM_Utils_Array
::value("charts", $_GET);
165 if (in_array($chartType, array(
166 'barChart', 'pieChart'))) {
167 $defaults["charts"] = $chartType;
171 static function processFilter(&$fieldGrp, &$defaults) {
172 // process only filters for now
173 foreach ($fieldGrp as $tableName => $fields) {
174 foreach ($fields as $fieldName => $field) {
175 switch (CRM_Utils_Array
::value('type', $field)) {
176 case CRM_Utils_Type
::T_INT
:
177 case CRM_Utils_Type
::T_MONEY
:
178 self
::intParam($fieldName, $field, $defaults);
181 case CRM_Utils_Type
::T_DATE
:
182 case CRM_Utils_Type
::T_DATE | CRM_Utils_Type
::T_TIME
:
183 self
::dateParam($fieldName, $field, $defaults);
186 case CRM_Utils_Type
::T_STRING
:
188 self
::stringParam($fieldName, $field, $defaults);
195 //unset default filters
196 static function unsetFilters(&$defaults) {
197 static $unsetFlag = TRUE;
199 foreach ($defaults as $field_name => $field_value) {
200 $newstr = substr($field_name, strrpos($field_name, '_'));
201 if ($newstr == '_value' ||
$newstr == '_op' ||
202 $newstr == '_min' ||
$newstr == '_max' ||
203 $newstr == '_from' ||
$newstr == '_to' ||
204 $newstr == '_relative'
206 unset($defaults[$field_name]);
213 static function processGroupBy(&$fieldGrp, &$defaults) {
214 // process only group_bys for now
217 if (is_array($fieldGrp)) {
218 foreach ($fieldGrp as $tableName => $fields) {
219 if ($groupBys = CRM_Utils_Array
::value("gby", $_GET)) {
220 $groupBys = explode(' ', $groupBys);
221 if (!empty($groupBys)) {
223 unset($defaults['group_bys']);
226 foreach ($groupBys as $gby) {
227 if (array_key_exists($gby, $fields)) {
228 $defaults['group_bys'][$gby] = 1;
237 static function processFields(&$reportFields, &$defaults) {
238 //add filters from url
239 if (is_array($reportFields)) {
240 if ($urlFields = CRM_Utils_Array
::value("fld", $_GET)) {
241 $urlFields = explode(',', $urlFields);
243 if (!empty($urlFields)) {
244 foreach ($reportFields as $tableName => $fields) {
245 foreach ($urlFields as $fld) {
246 if (array_key_exists($fld, $fields)) {
247 $defaults['fields'][$fld] = 1;