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.
10 * Description of Repeat
14 class CRM_Event_Form_ManageEvent_Repeat
extends CRM_Event_Form_ManageEvent
{
17 * Schedule Reminder Id
19 protected $_scheduleReminderId = NULL;
22 * Schedule Reminder data
24 protected $_scheduleReminderDetails = array();
29 protected $_parentEventId = NULL;
32 * Parent Event Start Date
34 protected $_parentEventStartDate = NULL;
37 * Parent Event End Date
39 protected $_parentEventEndDate = NULL;
42 * Exclude date information
44 public $_excludeDateInfo = array();
46 protected $_pager = NULL;
50 function preProcess() {
52 $this->assign('currentEventId', $this->_id
);
54 $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity
::getParentFor($this->_id
, 'civicrm_event');
55 $checkParentExistsForThisId;
56 //If this ID has parent, send parent id
57 if($checkParentExistsForThisId){
58 $this->_scheduleReminderDetails
= self
::getReminderDetailsByEventId($checkParentExistsForThisId, 'event');
59 $this->_parentEventId
= $checkParentExistsForThisId;
62 * Get connected event information list
64 //Get all connected event ids
65 //$allEventIds = CRM_Core_Form_RecurringEntity::getAllConnectedEvents($checkParentExistsForThisId);
66 $allEventIdsArray = CRM_Core_BAo_RecurringEntity
::getEntitiesForParent($checkParentExistsForThisId, 'civicrm_event');
67 $allEventIds = array();
68 if(!empty($allEventIdsArray)){
69 foreach($allEventIdsArray as $key => $val){
70 $allEventIds[] = $val['id'];
72 if(!empty($allEventIds)){
77 WHERE id IN (".implode(",", $allEventIds).")
78 ORDER BY start_date asc
81 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event');
82 $permissions = CRM_Event_BAO_Event
::checkPermission();
84 if(in_array($dao->id
, $permissions[CRM_Core_Permission
::VIEW
])){
85 $manageEvent[$dao->id
] = array();
86 CRM_Core_DAO
::storeValues($dao, $manageEvent[$dao->id
]);
90 $this->assign('rows', $manageEvent);
93 //ELse send this id as parent
94 $this->_scheduleReminderDetails
= self
::getReminderDetailsByEventId($this->_id
, 'event');
95 $this->_parentEventId
= $this->_id
;
97 //Assign this to hide summary
98 $this->assign('scheduleReminderId', $this->_scheduleReminderDetails
->id
);
100 $parentEventParams = array('id' => $this->_id
);
101 $parentEventValues = array();
102 $parentEventReturnProperties = array('start_date', 'end_date');
103 $parentEventAttributes = CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $parentEventParams, $parentEventValues, $parentEventReturnProperties);
104 $this->_parentEventStartDate
= $parentEventAttributes->start_date
;
105 $this->_parentEventEndDate
= $parentEventAttributes->end_date
;
107 //Get option exclude date information
108 //$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'event_repeat_exclude_dates_'.$this->_parentEventId, 'id', 'name');
109 CRM_Core_OptionValue
::getValues(array('name' => 'event_repeat_exclude_dates_'.$this->_parentEventId
), $optionValue);
110 $excludeOptionValues = array();
111 if(!empty($optionValue)){
112 foreach($optionValue as $key => $val){
113 $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
115 $this->_excludeDateInfo
= $excludeOptionValues;
120 * This function sets the default values for the form. For edit/view mode
121 * the default values are retrieved from the database
127 function setDefaultValues() {
130 //Set Schedule Reminder Id
131 $this->_scheduleReminderId
= $this->_scheduleReminderDetails
->id
;
132 //Always pass current event's start date by default
133 $currentEventStartDate = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $this->_id
, 'start_date', 'id');
134 list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date
::setDateDefaults($currentEventStartDate, 'activityDateTime');
136 // Check if there is id for this event in Reminder table
137 if($this->_scheduleReminderId
){
138 $defaults['repetition_frequency_unit'] = $this->_scheduleReminderDetails
->repetition_frequency_unit
;
139 $defaults['repetition_frequency_interval'] = $this->_scheduleReminderDetails
->repetition_frequency_interval
;
140 $defaults['start_action_condition'] = array_flip(explode(",",$this->_scheduleReminderDetails
->start_action_condition
));
141 foreach($defaults['start_action_condition'] as $key => $val){
143 $defaults['start_action_condition'][$key] = $val;
145 list($defaults['repeat_event_start_date'], $defaults['repeat_event_start_date_time']) = CRM_Utils_Date
::setDateDefaults($this->_parentEventStartDate
, 'activityDateTime');
146 $defaults['start_action_offset'] = $this->_scheduleReminderDetails
->start_action_offset
;
147 if($this->_scheduleReminderDetails
->start_action_offset
){
148 $defaults['ends'] = 1;
150 list($defaults['repeat_absolute_date']) = CRM_Utils_Date
::setDateDefaults($this->_scheduleReminderDetails
->absolute_date
);
151 if($this->_scheduleReminderDetails
->absolute_date
){
152 $defaults['ends'] = 2;
154 $defaults['limit_to'] = $this->_scheduleReminderDetails
->limit_to
;
155 if($this->_scheduleReminderDetails
->limit_to
){
156 $defaults['repeats_by'] = 1;
158 $explodeStartActionCondition = array();
159 $explodeStartActionCondition = explode(" ", $this->_scheduleReminderDetails
->entity_status
);
160 $defaults['entity_status_1'] = $explodeStartActionCondition[0];
161 $defaults['entity_status_2'] = $explodeStartActionCondition[1];
162 if($this->_scheduleReminderDetails
->entity_status
){
163 $defaults['repeats_by'] = 2;
165 $defaults['exclude_date_list'] = array('a', 'b');
170 public function buildQuickForm() {
171 CRM_Core_Form_RecurringEntity
::buildQuickForm($this);
174 public function postProcess() {
176 $params = $this->controller
->exportValues($this->_name
);
177 $params['event_id'] = $this->_id
;
178 $params['parent_event_id'] = $this->_parentEventId
;
179 $params['parent_event_start_date'] = $this->_parentEventStartDate
;
180 $params['parent_event_end_date'] = $this->_parentEventEndDate
;
182 unset($params['id']);
184 //Set Schedule Reminder id
185 $params['id'] = $this->_scheduleReminderId
;
186 $url = 'civicrm/event/manage/repeat';
187 $urlParams = "action=update&reset=1&id={$this->_id}";
189 CRM_Core_Form_RecurringEntity
::postProcess($params, 'event');
190 CRM_Utils_System
::redirect(CRM_Utils_System
::url($url, $urlParams));
192 CRM_Core_Error
::fatal("Could not find Event ID");
197 * This function gets the number of participant count for the list of related event ids
199 * @param array $listOfRelatedEntities list of related event ids
206 static public function getParticipantCountforEvent($listOfRelatedEntities = array()){
207 if(!empty($listOfRelatedEntities)){
208 $implodeRelatedEntities = implode(',', array_map(function($entity){
209 return $entity['id'];
210 }, $listOfRelatedEntities));
211 if($implodeRelatedEntities){
212 $query = "SELECT p.event_id as event_id,
213 concat_ws(' ', e.title, concat_ws(' - ', DATE_FORMAT(e.start_date, '%b %d %Y %h:%i %p'), DATE_FORMAT(e.end_date, '%b %d %Y %h:%i %p'))) as event_data,
214 count(p.id) as participant_count
215 FROM civicrm_participant p, civicrm_event e
216 WHERE p.event_id = e.id AND p.event_id IN ({$implodeRelatedEntities})
217 GROUP BY p.event_id";
218 $dao = CRM_Core_DAO
::executeQuery($query);
219 $participantDetails = array();
220 while($dao->fetch()) {
221 $participantDetails['countByID'][$dao->event_id
] = $dao->participant_count
;
222 $participantDetails['countByName'][$dao->event_id
][$dao->event_data
] = $dao->participant_count
;
226 return $participantDetails;
230 * This function gets all columns from civicrm_action_schedule on the basis of event id
232 * @param int $eventId Event ID
233 * @param string $used_for Specifies for which entity type it's used for
240 static public function getReminderDetailsByEventId($eventId, $used_for){
244 FROM civicrm_action_schedule
245 WHERE entity_value = %1";
247 $query .= " AND used_for = %2";
250 1 => array($eventId, 'Integer'),
251 2 => array($used_for, 'String')
253 $dao = CRM_Core_DAO
::executeQuery($query, $params);