Commit | Line | Data |
---|---|---|
2aa397bc TO |
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) && CRM_Utils_Array::value('entityTable', $_REQUEST)) { | |
19 | ||
20 | $finalResult = array(); | |
21 | $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer'); | |
22 | $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer'); | |
23 | $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String'); | |
24 | ||
25 | if (CRM_Utils_Array::value('linkedEntityTable', $_REQUEST)) { | |
26 | $result = array(); | |
27 | $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable); | |
28 | } | |
29 | ||
30 | $dao = new CRM_Core_DAO_RecurringEntity(); | |
31 | if (!empty($result)) { | |
32 | $dao->entity_id = $result['entityId']; | |
33 | $dao->entity_table = $result['entityTable']; | |
34 | } | |
35 | else { | |
36 | $dao->entity_id = $entityId; | |
37 | $dao->entity_table = $entityTable; | |
38 | } | |
39 | ||
40 | if ($dao->find(TRUE)) { | |
41 | $dao->mode = $mode; | |
42 | $dao->save(); | |
43 | $finalResult['status'] = 'Done'; | |
44 | } | |
45 | else { | |
46 | $finalResult['status'] = 'Error'; | |
47 | } | |
48 | } | |
49 | echo json_encode($finalResult); | |
50 | CRM_Utils_System::civiExit(); | |
51 | } | |
52 | ||
53 | public static function generatePreview() { | |
54 | $params = $formValues = $genericResult = array(); | |
55 | $formValues = $_REQUEST; | |
56 | if (!empty($formValues) && | |
57 | CRM_Utils_Array::value('entity_table', $formValues)) { | |
58 | $startDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns'][0]; | |
59 | $endDateColumnName = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['intervalDateColumns'][0]; | |
60 | ||
61 | $recursion = new CRM_Core_BAO_RecurringEntity(); | |
62 | if (CRM_Utils_Array::value('dateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { | |
63 | $recursion->dateColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['dateColumns']; | |
64 | } | |
65 | $recursion->scheduleFormValues = $formValues; | |
66 | if (!empty($formValues['exclude_date_list'])) { | |
67 | $recursion->excludeDates = $formValues['exclude_date_list']; | |
68 | } | |
69 | if (CRM_Utils_Array::value('excludeDateRangeColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { | |
70 | $recursion->excludeDateRangeColumns = CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']]['excludeDateRangeColumns']; | |
71 | } | |
72 | ||
73 | if (CRM_Utils_Array::value('entity_id', $formValues)) { | |
74 | $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['entity_id'], $formValues['entity_table']); | |
75 | } | |
76 | ||
77 | //Check if there is any enddate column defined to find out the interval between the two range | |
78 | if (CRM_Utils_Array::value('intervalDateColumns', CRM_Core_BAO_RecurringEntity::$_dateColumns[$formValues['entity_table']])) { | |
79 | $daoName = CRM_Core_BAO_RecurringEntity::$_tableDAOMapper[$formValues['entity_table']]; | |
80 | if ($parentEventId) { | |
81 | $startDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $startDateColumnName); | |
82 | $endDate = CRM_Core_DAO::getFieldValue($daoName, $parentEventId, $endDateColumnName); | |
83 | } | |
84 | if ($endDate) { | |
85 | $interval = $recursion->getInterval($startDate, $endDate); | |
86 | $recursion->intervalDateColumns = array($endDateColumnName => $interval); | |
87 | } | |
88 | } | |
89 | ||
90 | $result = $recursion->generateRecursiveDates(); | |
91 | ||
92 | foreach ($result as $key => $value) { | |
93 | if ($startDateColumnName) { | |
94 | $result[$key]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$startDateColumnName])); | |
95 | } | |
96 | if ($value[$endDateColumnName]) { | |
97 | if ($endDateColumnName) { | |
98 | $result[$key]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value[$endDateColumnName])); | |
99 | } | |
100 | } | |
101 | } | |
102 | ||
103 | //Show the list of participants registered for the events if any | |
104 | if ($formValues['entity_table'] == "civicrm_event" && !empty($parentEventId)) { | |
105 | $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parentEventId, 'civicrm_event', TRUE); | |
106 | if ($getConnectedEntities) { | |
107 | $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getConnectedEntities); | |
108 | if (!empty($participantDetails['countByName'])) { | |
109 | $result['participantData'] = $participantDetails['countByName']; | |
110 | } | |
111 | } | |
112 | } | |
113 | } | |
114 | echo json_encode($result); | |
115 | CRM_Utils_System::civiExit(); | |
116 | } | |
117 | } |