62933949 |
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 | |
079617dc |
15 | class CRM_Core_Page_AJAX_RecurringEntity { |
62933949 |
16 | |
60b36f60 |
17 | public static function updateMode() { |
18 | if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST)){ |
62933949 |
19 | $finalResult = array(); |
60b36f60 |
20 | $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer'); |
62933949 |
21 | $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer'); |
60b36f60 |
22 | |
62933949 |
23 | $sql = "UPDATE |
60b36f60 |
24 | civicrm_recurring_entity |
25 | SET mode = %1 |
26 | WHERE entity_id = %2 AND entity_table = 'civicrm_event'"; |
62933949 |
27 | $params = array( |
60b36f60 |
28 | 1 => array($mode, 'Integer'), |
29 | 2 => array($entityId, 'Integer') |
30 | ); |
62933949 |
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(){ |
f51acb7a |
39 | $params = $formValues = $genericResult = array(); |
62933949 |
40 | $formValues = $_REQUEST; |
41 | if(!empty($formValues)){ |
dfbe9b91 |
42 | $recursion = new CRM_Core_BAO_RecurringEntity(); |
43 | $recursion->dateColumns = array('start_date'); |
84f02991 |
44 | $recursion->scheduleFormValues = $formValues; |
dfbe9b91 |
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(); |
d10273dc |
63 | |
dfbe9b91 |
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']; |
62933949 |
77 | } |
78 | } |
79 | } |
dfbe9b91 |
80 | echo json_encode($result); |
62933949 |
81 | CRM_Utils_System::civiExit(); |
82 | } |
62933949 |
83 | } |