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