generalize skip fields & testing linked-entities
[civicrm-core.git] / CRM / Core / Page / AJAX / RecurringEntity.php
1 <?php
2
3 /*
4 * To change this license header, choose License Headers in Project Properties.
5 * To change this template file, choose Tools | Templates
6 * and open the template in the editor.
7 */
8
9 /**
10 * Description of EntityApplyChangesTo
11 *
12 * @author Priyanka
13 */
14
15 class CRM_Core_Page_AJAX_RecurringEntity {
16
17 public static function updateMode() {
18 if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST)){
19 $finalResult = array();
20 $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
21 $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
22
23 $sql = "UPDATE
24 civicrm_recurring_entity
25 SET mode = %1
26 WHERE entity_id = %2 AND entity_table = 'civicrm_event'";
27 $params = array(
28 1 => array($mode, 'Integer'),
29 2 => array($entityId, 'Integer')
30 );
31 CRM_Core_DAO::executeQuery($sql, $params);
32 $finalResult['status'] = 'Done';
33 }
34 echo json_encode($finalResult);
35 CRM_Utils_System::civiExit();
36 }
37
38 public static function generatePreview(){
39 $params = $formValues = $genericResult = array();
40 $formValues = $_REQUEST;
41 if(!empty($formValues)){
42 $recursion = new CRM_Core_BAO_RecurringEntity();
43 $recursion->dateColumns = array('start_date');
44 $recursion->scheduleFormValues = $formValues;
45 if (!empty($formValues['exclude_date_list'])) {
46 $recursion->excludeDates = $formValues['exclude_date_list'];
47 $recursion->excludeDateRangeColumns = array('start_date', 'end_date');
48 }
49
50 $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['event_id'], 'civicrm_event');
51 if(!$parentEventId){
52 $parentEventId = $formValues['event_id'];
53 }
54
55 $endDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parentEventId, 'end_date');
56 if ($endDate) {
57 $startDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parentEventId, 'start_date');
58 $interval = $recursion->getInterval($startDate, $endDate);
59 $recursion->intervalDateColumns = array('end_date' => $interval);
60 }
61
62 $result = $recursion->generateRecursiveDates();
63
64 foreach ($result as $key => $value) {
65 $result[$key]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date']));
66 if($value['end_date']){
67 $result[$key]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['end_date']));
68 }
69 }
70
71 //Show the list of participants registered for the events if any
72 $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', FALSE);
73 if($getConnectedEntities){
74 $participantDetails = CRM_Core_BAO_RecurringEntity::getParticipantCountforEvent($getConnectedEntities);
75 if(!empty($participantDetails['countByName'])){
76 $result['participantData'] = $participantDetails['countByName'];
77 }
78 }
79 }
80 echo json_encode($result);
81 CRM_Utils_System::civiExit();
82 }
83 }