Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * |
33 | */ | |
34 | ||
35 | /** | |
36 | * This class contains all campaign related functions that are called using AJAX (jQuery) | |
37 | */ | |
38 | class CRM_Campaign_Page_AJAX { | |
39 | ||
00be9182 | 40 | public static function registerInterview() { |
6a488035 TO |
41 | $fields = array( |
42 | 'result', | |
43 | 'voter_id', | |
44 | 'survey_id', | |
45 | 'activity_id', | |
46 | 'surveyTitle', | |
47 | 'interviewer_id', | |
48 | 'activity_type_id', | |
49 | ); | |
50 | ||
51 | $params = array(); | |
52 | foreach ($fields as $fld) { | |
53 | $params[$fld] = CRM_Utils_Array::value($fld, $_POST); | |
54 | } | |
55 | $params['details'] = CRM_Utils_Array::value('note', $_POST); | |
56 | $voterId = $params['voter_id']; | |
57 | $activityId = $params['activity_id']; | |
58 | ||
59 | $customKey = "field_{$voterId}_custom"; | |
60 | foreach ($_POST as $key => $value) { | |
61 | if (strpos($key, $customKey) !== FALSE) { | |
62 | $customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key); | |
63 | $params[$customFieldKey] = $value; | |
64 | } | |
65 | } | |
66 | ||
8cc574cf | 67 | if (isset($_POST['field']) && !empty($_POST['field'][$voterId]) && |
6a488035 TO |
68 | is_array($_POST['field'][$voterId]) |
69 | ) { | |
70 | foreach ($_POST['field'][$voterId] as $fieldKey => $value) { | |
71 | $params[$fieldKey] = $value; | |
72 | } | |
73 | } | |
74 | ||
75 | //lets pickup contat related fields. | |
76 | foreach ($_POST as $key => $value) { | |
77 | if (strpos($key, "field_{$voterId}_") !== FALSE && | |
78 | strpos($key, "field_{$voterId}_custom") === FALSE | |
79 | ) { | |
80 | $key = substr($key, strlen("field_{$voterId}_")); | |
81 | $params[$key] = $value; | |
82 | } | |
83 | } | |
84 | ||
85 | $result = array( | |
86 | 'status' => 'fail', | |
87 | 'voter_id' => $voterId, | |
88 | 'activity_id' => $params['interviewer_id'], | |
89 | ); | |
90 | ||
91 | //time to validate custom data. | |
92 | $errors = CRM_Core_BAO_CustomField::validateCustomData($params); | |
93 | if (is_array($errors) && !empty($errors)) { | |
94 | $result['errors'] = $errors; | |
ecdef330 | 95 | CRM_Utils_JSON::output($result); |
6a488035 TO |
96 | } |
97 | ||
98 | //process the response/interview data. | |
99 | $activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params); | |
100 | if ($activityId) { | |
101 | $result['status'] = 'success'; | |
102 | } | |
103 | ||
ecdef330 | 104 | CRM_Utils_JSON::output($result); |
6a488035 TO |
105 | } |
106 | ||
00be9182 | 107 | public static function loadOptionGroupDetails() { |
6a488035 TO |
108 | |
109 | $id = CRM_Utils_Array::value('option_group_id', $_POST); | |
110 | $status = 'fail'; | |
111 | $opValues = array(); | |
112 | ||
113 | if ($id) { | |
114 | $groupParams['id'] = $id; | |
115 | CRM_Core_OptionValue::getValues($groupParams, $opValues); | |
116 | } | |
117 | ||
118 | $surveyId = CRM_Utils_Array::value('survey_id', $_POST); | |
119 | if ($surveyId) { | |
120 | $survey = new CRM_Campaign_DAO_Survey(); | |
121 | $survey->id = $surveyId; | |
122 | $survey->result_id = $id; | |
123 | if ($survey->find(TRUE)) { | |
124 | if ($survey->recontact_interval) { | |
125 | $recontactInterval = unserialize($survey->recontact_interval); | |
126 | foreach ($opValues as $opValId => $opVal) { | |
127 | if (is_numeric($recontactInterval[$opVal['label']])) { | |
128 | $opValues[$opValId]['interval'] = $recontactInterval[$opVal['label']]; | |
129 | } | |
130 | } | |
131 | } | |
132 | } | |
133 | } | |
134 | ||
135 | if (!empty($opValues)) { | |
136 | $status = 'success'; | |
137 | } | |
138 | ||
139 | $result = array( | |
140 | 'status' => $status, | |
141 | 'result' => $opValues, | |
142 | ); | |
143 | ||
ecdef330 | 144 | CRM_Utils_JSON::output($result); |
6a488035 TO |
145 | } |
146 | ||
00be9182 | 147 | public function voterList() { |
6a488035 TO |
148 | //get the search criteria params. |
149 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
150 | ||
151 | $params = $searchRows = array(); | |
152 | foreach ($searchParams as $param) { | |
a7488080 | 153 | if (!empty($_POST[$param])) { |
6a488035 TO |
154 | $params[$param] = $_POST[$param]; |
155 | } | |
156 | } | |
157 | ||
158 | //format multi-select group and contact types. | |
159 | foreach (array( | |
160 | 'group', 'contact_type') as $param) { | |
161 | $paramValue = CRM_Utils_Array::value($param, $params); | |
162 | if ($paramValue) { | |
163 | unset($params[$param]); | |
164 | $paramValue = explode(',', $paramValue); | |
165 | foreach ($paramValue as $key => $value) { | |
166 | $params[$param][$value] = 1; | |
167 | } | |
168 | } | |
169 | } | |
170 | ||
171 | $voterClauseParams = array(); | |
172 | foreach (array( | |
173 | 'campaign_survey_id', 'survey_interviewer_id', 'campaign_search_voter_for') as $fld) { | |
174 | $voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params); | |
175 | } | |
176 | ||
177 | $interviewerId = $surveyTypeId = $surveyId = NULL; | |
178 | $searchVoterFor = $params['campaign_search_voter_for']; | |
179 | if ($searchVoterFor == 'reserve') { | |
a7488080 | 180 | if (!empty($params['campaign_survey_id'])) { |
6a488035 TO |
181 | $survey = new CRM_Campaign_DAO_Survey(); |
182 | $survey->id = $surveyId = $params['campaign_survey_id']; | |
183 | $survey->selectAdd('campaign_id, activity_type_id'); | |
184 | $survey->find(TRUE); | |
185 | $campaignId = $survey->campaign_id; | |
186 | $surveyTypeId = $survey->activity_type_id; | |
187 | ||
188 | //allow voter search in sub-part of given constituents, | |
189 | //but make sure in case user does not select any group. | |
190 | //get all associated campaign groups in where filter, CRM-7406 | |
191 | $groups = CRM_Utils_Array::value('group', $params); | |
192 | if ($campaignId && CRM_Utils_System::isNull($groups)) { | |
193 | $campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); | |
94880218 TO |
194 | foreach ($campaignGroups as $id => $group) { $params['group'][$id] = 1; |
195 | } | |
6a488035 TO |
196 | } |
197 | ||
198 | //apply filter of survey contact type for search. | |
199 | $contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId); | |
200 | if ($contactType) { | |
201 | $params['contact_type'][$contactType] = 1; | |
202 | } | |
203 | ||
204 | unset($params['campaign_survey_id']); | |
205 | } | |
206 | unset($params['survey_interviewer_id']); | |
207 | } | |
208 | else { | |
209 | //get the survey status in where clause. | |
210 | $scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name')); | |
211 | if ($scheduledStatusId) { | |
212 | $params['survey_status_id'] = $scheduledStatusId; | |
213 | } | |
214 | //BAO/Query knows reserve/release/interview processes. | |
215 | if ($params['campaign_search_voter_for'] == 'gotv') { | |
216 | $params['campaign_search_voter_for'] = 'release'; | |
217 | } | |
218 | } | |
219 | ||
220 | $selectorCols = array( | |
221 | 'sort_name', | |
222 | 'street_address', | |
223 | 'street_name', | |
224 | 'street_number', | |
225 | 'street_unit', | |
226 | ); | |
227 | ||
228 | // get the data table params. | |
229 | $dataTableParams = array( | |
94880218 TO |
230 | 'sEcho' => array( |
231 | 'name' => 'sEcho', | |
6a488035 TO |
232 | 'type' => 'Integer', |
233 | 'default' => 0, | |
234 | ), | |
235 | 'offset' => array( | |
236 | 'name' => 'iDisplayStart', | |
237 | 'type' => 'Integer', | |
238 | 'default' => 0, | |
239 | ), | |
240 | 'rowCount' => array( | |
241 | 'name' => 'iDisplayLength', | |
242 | 'type' => 'Integer', | |
243 | 'default' => 25, | |
244 | ), | |
245 | 'sort' => array( | |
246 | 'name' => 'iSortCol_0', | |
247 | 'type' => 'Integer', | |
248 | 'default' => 'sort_name', | |
249 | ), | |
250 | 'sortOrder' => array( | |
251 | 'name' => 'sSortDir_0', | |
252 | 'type' => 'String', | |
253 | 'default' => 'asc', | |
254 | ), | |
255 | ); | |
256 | foreach ($dataTableParams as $pName => $pValues) { | |
257 | $$pName = $pValues['default']; | |
a7488080 | 258 | if (!empty($_POST[$pValues['name']])) { |
6a488035 | 259 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
94880218 TO |
260 | if ($pName == 'sort') { $$pName = $selectorCols[$$pName]; |
261 | } | |
6a488035 TO |
262 | } |
263 | } | |
264 | ||
265 | $queryParams = CRM_Contact_BAO_Query::convertFormValues($params); | |
266 | $query = new CRM_Contact_BAO_Query($queryParams, | |
267 | NULL, NULL, FALSE, FALSE, | |
268 | CRM_Contact_BAO_Query::MODE_CAMPAIGN, | |
269 | TRUE | |
270 | ); | |
271 | ||
272 | //get the voter clause to restrict and validate search. | |
273 | $voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams); | |
274 | ||
275 | $searchCount = $query->searchQuery(0, 0, NULL, | |
276 | TRUE, FALSE, | |
277 | FALSE, FALSE, | |
278 | FALSE, | |
279 | CRM_Utils_Array::value('whereClause', $voterClause), | |
280 | NULL, | |
281 | CRM_Utils_Array::value('fromClause', $voterClause) | |
282 | ); | |
283 | ||
284 | $iTotal = $searchCount; | |
285 | ||
286 | $selectorCols = array( | |
287 | 'contact_type', 'sort_name', 'street_address', | |
288 | 'street_name', 'street_number', 'street_unit', | |
289 | ); | |
290 | ||
291 | $extraVoterColName = 'is_interview_conducted'; | |
0aec9935 | 292 | if ($params['campaign_search_voter_for'] == 'reserve') { |
6a488035 TO |
293 | $extraVoterColName = 'reserve_voter'; |
294 | } | |
295 | ||
296 | if ($searchCount > 0) { | |
297 | if ($searchCount < $offset) { | |
298 | $offset = 0; | |
299 | } | |
300 | ||
301 | $config = CRM_Core_Config::singleton(); | |
302 | ||
303 | // get the result of the search | |
304 | $result = $query->searchQuery($offset, $rowCount, $sort, | |
305 | FALSE, FALSE, | |
306 | FALSE, FALSE, | |
307 | FALSE, | |
308 | CRM_Utils_Array::value('whereClause', $voterClause), | |
309 | $sortOrder, | |
310 | CRM_Utils_Array::value('fromClause', $voterClause) | |
311 | ); | |
312 | while ($result->fetch()) { | |
313 | $contactID = $result->contact_id; | |
94880218 | 314 | $typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, |
6a488035 TO |
315 | FALSE, |
316 | $result->contact_id | |
317 | ); | |
318 | ||
319 | $searchRows[$contactID] = array('id' => $contactID); | |
320 | foreach ($selectorCols as $col) { | |
321 | $val = $result->$col; | |
322 | if ($col == 'contact_type') { | |
323 | $val = $typeImage; | |
324 | } | |
325 | $searchRows[$contactID][$col] = $val; | |
326 | } | |
327 | if ($searchVoterFor == 'reserve') { | |
328 | $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />'; | |
329 | $msg = ts('Respondent Reserved.'); | |
330 | $voterExtraColHtml .= " <span id='success_msg_{$contactID}' class='ok' style='display:none;'>$msg</span>"; | |
331 | } | |
332 | elseif ($searchVoterFor == 'gotv') { | |
333 | $surveyActId = $result->survey_activity_id; | |
334 | $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />'; | |
805dd6a2 | 335 | $msg = ts('Vote Recorded.'); |
6a488035 TO |
336 | $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>"; |
337 | } | |
338 | else { | |
339 | $surveyActId = $result->survey_activity_id; | |
340 | $voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />'; | |
805dd6a2 | 341 | $msg = ts('Vote Recorded.'); |
6a488035 TO |
342 | $voterExtraColHtml .= " <span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>"; |
343 | } | |
344 | $searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml; | |
345 | } | |
346 | } | |
347 | ||
348 | $selectorElements = array_merge($selectorCols, array($extraVoterColName)); | |
349 | ||
350 | $iFilteredTotal = $iTotal; | |
351 | ||
352 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
353 | CRM_Utils_System::civiExit(); | |
354 | } | |
355 | ||
00be9182 | 356 | public function processVoterData() { |
6a488035 TO |
357 | $status = NULL; |
358 | $operation = CRM_Utils_Type::escape($_POST['operation'], 'String'); | |
359 | if ($operation == 'release') { | |
360 | $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); | |
361 | $isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String')); | |
362 | if ($activityId && | |
363 | CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
364 | $activityId, | |
365 | 'is_deleted', | |
366 | $isDelete | |
367 | ) | |
368 | ) { | |
369 | $status = 'success'; | |
370 | } | |
371 | } | |
372 | elseif ($operation == 'reserve') { | |
373 | $activityId = NULL; | |
374 | $createActivity = TRUE; | |
a7488080 | 375 | if (!empty($_POST['activity_id'])) { |
6a488035 TO |
376 | $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); |
377 | if ($activityId) { | |
378 | $createActivity = FALSE; | |
379 | $activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
380 | $activityId, | |
381 | 'is_deleted', | |
382 | 0 | |
383 | ); | |
384 | if ($activityUpdated) { | |
385 | $status = 'success'; | |
386 | } | |
387 | } | |
388 | } | |
389 | if ($createActivity) { | |
390 | $ids = array( | |
391 | 'source_record_id', | |
392 | 'source_contact_id', | |
393 | 'target_contact_id', | |
394 | 'assignee_contact_id', | |
395 | ); | |
396 | $activityParams = array(); | |
397 | foreach ($ids as $id) { | |
398 | $val = CRM_Utils_Array::value($id, $_POST); | |
399 | if (!$val) { | |
400 | $createActivity = FALSE; | |
401 | break; | |
402 | } | |
403 | $activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer'); | |
404 | } | |
405 | } | |
406 | if ($createActivity) { | |
407 | $isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String')); | |
408 | $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); | |
409 | $scheduledStatusId = array_search('Scheduled', $activityStatus); | |
410 | if ($isReserved) { | |
411 | $surveyValues = array(); | |
412 | $surveyParams = array('id' => $activityParams['source_record_id']); | |
413 | CRM_Core_DAO::commonRetrieve('CRM_Campaign_DAO_Survey', | |
414 | $surveyParams, | |
415 | $surveyValues, | |
416 | array('title', 'activity_type_id', 'campaign_id') | |
417 | ); | |
418 | ||
419 | $activityTypeId = $surveyValues['activity_type_id']; | |
420 | ||
421 | $surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST); | |
422 | if (!$surveytitle) { | |
423 | $surveytitle = $surveyValues['title']; | |
424 | } | |
425 | ||
426 | $subject = ts('%1', array(1 => $surveytitle)) . ' - ' . ts('Respondent Reservation'); | |
427 | $activityParams['subject'] = $subject; | |
428 | $activityParams['status_id'] = $scheduledStatusId; | |
429 | $activityParams['skipRecentView'] = 1; | |
430 | $activityParams['activity_date_time'] = date('YmdHis'); | |
431 | $activityParams['activity_type_id'] = $activityTypeId; | |
bef6ccc5 | 432 | $activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL; |
6a488035 TO |
433 | |
434 | $activity = CRM_Activity_BAO_Activity::create($activityParams); | |
435 | if ($activity->id) { | |
436 | $status = 'success'; | |
437 | } | |
438 | } | |
439 | else { | |
440 | //delete reserved activity for given voter. | |
441 | $voterIds = array($activityParams['target_contact_id']); | |
442 | $activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'], | |
443 | $voterIds, | |
444 | $activityParams['source_contact_id'], | |
445 | array($scheduledStatusId) | |
446 | ); | |
447 | foreach ($activities as $voterId => $values) { | |
448 | $activityId = CRM_Utils_Array::value('activity_id', $values); | |
449 | if ($activityId && ($values['status_id'] == $scheduledStatusId)) { | |
450 | CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
451 | $activityId, | |
452 | 'is_deleted', | |
453 | TRUE | |
454 | ); | |
455 | $status = 'success'; | |
456 | break; | |
457 | } | |
458 | } | |
459 | } | |
460 | } | |
461 | } | |
462 | elseif ($operation == 'gotv') { | |
463 | $activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer'); | |
464 | $hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String')); | |
465 | if ($activityId) { | |
466 | if ($hasVoted) { | |
467 | $statusValue = 2; | |
468 | } | |
469 | else { | |
470 | $statusValue = 1; | |
471 | } | |
472 | CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity', | |
473 | $activityId, | |
474 | 'status_id', | |
475 | $statusValue | |
476 | ); | |
477 | $status = 'success'; | |
478 | } | |
479 | } | |
480 | ||
ecdef330 | 481 | CRM_Utils_JSON::output(array('status' => $status)); |
6a488035 TO |
482 | } |
483 | ||
00be9182 | 484 | public function allActiveCampaigns() { |
6a488035 TO |
485 | $currentCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(); |
486 | $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, TRUE, FALSE, TRUE); | |
487 | $options = array( | |
94880218 TO |
488 | array( |
489 | 'value' => '', | |
6a488035 TO |
490 | 'title' => ts('- select -'), |
491 | )); | |
492 | foreach ($campaigns as $value => $title) { | |
493 | $class = NULL; | |
494 | if (!array_key_exists($value, $currentCampaigns)) { | |
495 | $class = 'status-past'; | |
496 | } | |
497 | $options[] = array( | |
498 | 'value' => $value, | |
499 | 'title' => $title, | |
500 | 'class' => $class, | |
501 | ); | |
502 | } | |
503 | $status = 'fail'; | |
504 | if (count($options) > 1) { | |
505 | $status = 'success'; | |
506 | } | |
507 | ||
508 | $results = array( | |
509 | 'status' => $status, | |
510 | 'campaigns' => $options, | |
511 | ); | |
512 | ||
ecdef330 | 513 | CRM_Utils_JSON::output($results); |
6a488035 TO |
514 | } |
515 | ||
00be9182 | 516 | public function campaignGroups() { |
6a488035 TO |
517 | $surveyId = CRM_Utils_Request::retrieve('survey_id', 'Positive', |
518 | CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST' | |
519 | ); | |
520 | $campGroups = array(); | |
521 | if ($surveyId) { | |
522 | $campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'campaign_id'); | |
523 | if ($campaignId) { | |
524 | $campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId); | |
525 | } | |
526 | } | |
527 | ||
528 | //CRM-7406 --If there is no campaign or no group associated with | |
529 | //campaign of given survey, lets allow to search across all groups. | |
530 | if (empty($campGroups)) { | |
531 | $campGroups = CRM_Core_PseudoConstant::group(); | |
532 | } | |
533 | $groups = array( | |
94880218 TO |
534 | array( |
535 | 'value' => '', | |
6a488035 TO |
536 | 'title' => ts('- select -'), |
537 | )); | |
538 | foreach ($campGroups as $grpId => $title) { | |
539 | $groups[] = array( | |
540 | 'value' => $grpId, | |
541 | 'title' => $title, | |
542 | ); | |
543 | } | |
544 | $results = array( | |
545 | 'status' => 'success', | |
546 | 'groups' => $groups, | |
547 | ); | |
548 | ||
ecdef330 | 549 | CRM_Utils_JSON::output($results); |
6a488035 TO |
550 | } |
551 | ||
552 | /** | |
553 | * Retrieve campaigns as for campaign dashboard. | |
554 | * | |
555 | **/ | |
00be9182 | 556 | public function campaignList() { |
6a488035 TO |
557 | //get the search criteria params. |
558 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
559 | ||
560 | $params = $searchRows = array(); | |
561 | foreach ($searchParams as $param) { | |
a7488080 | 562 | if (!empty($_POST[$param])) { |
6a488035 TO |
563 | $params[$param] = $_POST[$param]; |
564 | } | |
565 | } | |
566 | ||
567 | //this is sequence columns on datatable. | |
568 | $selectorCols = array( | |
569 | 'id', | |
570 | 'name', | |
571 | 'title', | |
572 | 'description', | |
573 | 'start_date', | |
574 | 'end_date', | |
575 | 'campaign_type_id', | |
576 | 'campaign_type', | |
577 | 'status_id', | |
578 | 'status', | |
579 | 'is_active', | |
580 | 'isActive', | |
581 | 'action', | |
582 | ); | |
583 | ||
584 | // get the data table params. | |
585 | $dataTableParams = array( | |
94880218 TO |
586 | 'sEcho' => array( |
587 | 'name' => 'sEcho', | |
6a488035 TO |
588 | 'type' => 'Integer', |
589 | 'default' => 0, | |
590 | ), | |
591 | 'offset' => array( | |
592 | 'name' => 'iDisplayStart', | |
593 | 'type' => 'Integer', | |
594 | 'default' => 0, | |
595 | ), | |
596 | 'rowCount' => array( | |
597 | 'name' => 'iDisplayLength', | |
598 | 'type' => 'Integer', | |
599 | 'default' => 25, | |
600 | ), | |
601 | 'sort' => array( | |
602 | 'name' => 'iSortCol_0', | |
603 | 'type' => 'Integer', | |
604 | 'default' => 'start_date', | |
605 | ), | |
606 | 'sortOrder' => array( | |
607 | 'name' => 'sSortDir_0', | |
608 | 'type' => 'String', | |
609 | 'default' => 'desc', | |
610 | ), | |
611 | ); | |
612 | foreach ($dataTableParams as $pName => $pValues) { | |
613 | $$pName = $pValues['default']; | |
a7488080 | 614 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
615 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
616 | if ($pName == 'sort') { | |
617 | $$pName = $selectorCols[$$pName]; | |
618 | } | |
619 | } | |
620 | } | |
621 | foreach (array( | |
622 | 'sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) { | |
623 | $params[$sortParam] = $$sortParam; | |
624 | } | |
625 | ||
626 | $searchCount = CRM_Campaign_BAO_Campaign::getCampaignSummary($params, TRUE); | |
627 | $campaigns = CRM_Campaign_Page_DashBoard::getCampaignSummary($params); | |
628 | $iTotal = $searchCount; | |
629 | ||
630 | if ($searchCount > 0) { | |
631 | if ($searchCount < $offset) { | |
632 | $offset = 0; | |
633 | } | |
634 | foreach ($campaigns as $campaignID => $values) { | |
635 | foreach ($selectorCols as $col) { | |
636 | $searchRows[$campaignID][$col] = CRM_Utils_Array::value($col, $values); | |
637 | } | |
638 | } | |
639 | } | |
640 | ||
641 | $selectorElements = $selectorCols; | |
642 | ||
643 | $iFilteredTotal = $iTotal; | |
644 | ||
645 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
646 | CRM_Utils_System::civiExit(); | |
647 | } | |
648 | ||
649 | /** | |
650 | * Retrieve survey for survey dashboard. | |
651 | * | |
652 | **/ | |
00be9182 | 653 | public function surveyList() { |
6a488035 TO |
654 | //get the search criteria params. |
655 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
656 | ||
657 | $params = $searchRows = array(); | |
658 | foreach ($searchParams as $param) { | |
a7488080 | 659 | if (!empty($_POST[$param])) { |
6a488035 TO |
660 | $params[$param] = $_POST[$param]; |
661 | } | |
662 | } | |
663 | ||
664 | //this is sequence columns on datatable. | |
665 | $selectorCols = array( | |
666 | 'id', | |
667 | 'title', | |
668 | 'campaign_id', | |
669 | 'campaign', | |
670 | 'activity_type_id', | |
671 | 'activity_type', | |
672 | 'release_frequency', | |
673 | 'default_number_of_contacts', | |
674 | 'max_number_of_contacts', | |
675 | 'is_default', | |
676 | 'is_active', | |
677 | 'isActive', | |
678 | 'result_id', | |
679 | 'action', | |
680 | 'voterLinks', | |
681 | ); | |
682 | ||
683 | // get the data table params. | |
684 | $dataTableParams = array( | |
94880218 TO |
685 | 'sEcho' => array( |
686 | 'name' => 'sEcho', | |
6a488035 TO |
687 | 'type' => 'Integer', |
688 | 'default' => 0, | |
689 | ), | |
690 | 'offset' => array( | |
691 | 'name' => 'iDisplayStart', | |
692 | 'type' => 'Integer', | |
693 | 'default' => 0, | |
694 | ), | |
695 | 'rowCount' => array( | |
696 | 'name' => 'iDisplayLength', | |
697 | 'type' => 'Integer', | |
698 | 'default' => 25, | |
699 | ), | |
700 | 'sort' => array( | |
701 | 'name' => 'iSortCol_0', | |
702 | 'type' => 'Integer', | |
703 | 'default' => 'created_date', | |
704 | ), | |
705 | 'sortOrder' => array( | |
706 | 'name' => 'sSortDir_0', | |
707 | 'type' => 'String', | |
708 | 'default' => 'desc', | |
709 | ), | |
710 | ); | |
711 | foreach ($dataTableParams as $pName => $pValues) { | |
712 | $$pName = $pValues['default']; | |
a7488080 | 713 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
714 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
715 | if ($pName == 'sort') { | |
716 | $$pName = $selectorCols[$$pName]; | |
717 | } | |
718 | } | |
719 | } | |
720 | foreach (array( | |
721 | 'sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) { | |
722 | $params[$sortParam] = $$sortParam; | |
723 | } | |
724 | ||
725 | $surveys = CRM_Campaign_Page_DashBoard::getSurveySummary($params); | |
726 | $searchCount = CRM_Campaign_BAO_Survey::getSurveySummary($params, TRUE); | |
727 | $iTotal = $searchCount; | |
728 | ||
729 | if ($searchCount > 0) { | |
730 | if ($searchCount < $offset) { | |
731 | $offset = 0; | |
732 | } | |
733 | foreach ($surveys as $surveyID => $values) { | |
734 | foreach ($selectorCols as $col) { | |
735 | $searchRows[$surveyID][$col] = CRM_Utils_Array::value($col, $values); | |
736 | } | |
737 | } | |
738 | } | |
739 | ||
740 | $selectorElements = $selectorCols; | |
741 | ||
742 | $iFilteredTotal = $iTotal; | |
743 | ||
744 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
745 | CRM_Utils_System::civiExit(); | |
746 | } | |
747 | ||
748 | /** | |
749 | * Retrieve petitions for petition dashboard. | |
750 | * | |
751 | **/ | |
00be9182 | 752 | public function petitionList() { |
6a488035 TO |
753 | //get the search criteria params. |
754 | $searchParams = explode(',', CRM_Utils_Array::value('searchCriteria', $_POST)); | |
755 | ||
756 | $params = $searchRows = array(); | |
757 | foreach ($searchParams as $param) { | |
a7488080 | 758 | if (!empty($_POST[$param])) { |
6a488035 TO |
759 | $params[$param] = $_POST[$param]; |
760 | } | |
761 | } | |
762 | ||
763 | //this is sequence columns on datatable. | |
764 | $selectorCols = array( | |
765 | 'id', | |
766 | 'title', | |
767 | 'campaign_id', | |
768 | 'campaign', | |
769 | 'activity_type_id', | |
770 | 'activity_type', | |
771 | 'is_default', | |
772 | 'is_active', | |
773 | 'isActive', | |
774 | 'action', | |
775 | ); | |
776 | ||
777 | // get the data table params. | |
778 | $dataTableParams = array( | |
94880218 TO |
779 | 'sEcho' => array( |
780 | 'name' => 'sEcho', | |
6a488035 TO |
781 | 'type' => 'Integer', |
782 | 'default' => 0, | |
783 | ), | |
784 | 'offset' => array( | |
785 | 'name' => 'iDisplayStart', | |
786 | 'type' => 'Integer', | |
787 | 'default' => 0, | |
788 | ), | |
789 | 'rowCount' => array( | |
790 | 'name' => 'iDisplayLength', | |
791 | 'type' => 'Integer', | |
792 | 'default' => 25, | |
793 | ), | |
794 | 'sort' => array( | |
795 | 'name' => 'iSortCol_0', | |
796 | 'type' => 'Integer', | |
797 | 'default' => 'created_date', | |
798 | ), | |
799 | 'sortOrder' => array( | |
800 | 'name' => 'sSortDir_0', | |
801 | 'type' => 'String', | |
802 | 'default' => 'desc', | |
803 | ), | |
804 | ); | |
805 | foreach ($dataTableParams as $pName => $pValues) { | |
806 | $$pName = $pValues['default']; | |
a7488080 | 807 | if (!empty($_POST[$pValues['name']])) { |
6a488035 TO |
808 | $$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']); |
809 | if ($pName == 'sort') { | |
810 | $$pName = $selectorCols[$$pName]; | |
811 | } | |
812 | } | |
813 | } | |
814 | foreach (array( | |
815 | 'sort', 'offset', 'rowCount', 'sortOrder') as $sortParam) { | |
816 | $params[$sortParam] = $$sortParam; | |
817 | } | |
818 | ||
819 | $petitions = CRM_Campaign_Page_DashBoard::getPetitionSummary($params); | |
820 | $searchCount = CRM_Campaign_BAO_Petition::getPetitionSummary($params, TRUE); | |
821 | $iTotal = $searchCount; | |
822 | ||
823 | if ($searchCount > 0) { | |
824 | if ($searchCount < $offset) { | |
825 | $offset = 0; | |
826 | } | |
827 | foreach ($petitions as $petitionID => $values) { | |
828 | foreach ($selectorCols as $col) { | |
829 | $searchRows[$petitionID][$col] = CRM_Utils_Array::value($col, $values); | |
830 | } | |
831 | } | |
832 | } | |
833 | ||
834 | $selectorElements = $selectorCols; | |
835 | ||
836 | $iFilteredTotal = $iTotal; | |
837 | ||
838 | echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
839 | CRM_Utils_System::civiExit(); | |
840 | } | |
841 | } |