return $dao;
}
- static public function generateRecursions($recursionObj, $params=array()){
+ static public function generateRecursions($recursionObj, $params = array(), $excludeDates = array()) {
$newParams = $recursionResult = array();
- if($recursionObj && !empty($params)){
+ if ($recursionObj && !empty($params)) {
+ $initialCount = CRM_Utils_Array::value('start_action_offset', $params);
if(CRM_Utils_Array::value('parent_event_start_date', $params) && CRM_Utils_Array::value('parent_event_id', $params)){
$count = 1;
- while($result = $recursionObj->next()){
+ while ($result = $recursionObj->next()) {
$newParams['start_date'] = CRM_Utils_Date::processDate($result->format('Y-m-d H:i:s'));
$parentStartDate = new DateTime($params['parent_event_start_date']);
+
//If events with end date
if(CRM_Utils_Array::value('parent_event_end_date', $params)){
$parentEndDate = new DateTime($params['parent_event_end_date']);
$recursionResult[$count]['end_date'] = $newParams['end_date'];
}
$recursionResult[$count]['start_date'] = $newParams['start_date'];
+
+ $skip = FALSE;
+ foreach ($excludeDates as $date) {
+ $date = CRM_Utils_Date::processDate($date, NULL, FALSE, 'Ymd');
+ if (($date == $result->format('Ymd')) ||
+ ($end_date && ($date > $result->format('Ymd')) && ($date <= $end_date->format('Ymd')))
+ ) {
+ $skip = TRUE;
+ break;
+ }
+ }
+
+ if ($skip) {
+ unset($recursionResult[$count]);
+ if ($initialCount && ($initialCount > 0)) {
+ // lets increase the counter, so we get correct number of occurrences
+ $initialCount++;
+ $recursionObj->count($initialCount);
+ }
+ continue;
+ }
$count++;
}
}
//TO DO - Exclude date functionality
+ $excludeDateList = array();
if(CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_event_id', $params)){
//Since we get comma separated values lets get them in array
$exclude_date_list = array();
'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues),
'is_active' => 1
);
+ $excludeDateList[] = $optionGroupValue['value'];
CRM_Core_BAO_OptionValue::add($optionGroupValue);
}
}
CRM_Core_BAO_RecurringEntity::delEntityRelations($params['parent_event_id'], 'civicrm_event');
}
//Give call to create recursions
- $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params);
- if(!empty($recurResult) && $params['parent_event_id']){
+ $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params, $excludeDateList);
+ if(!empty($recurResult) && $params['parent_event_id']) {
CRM_Core_BAO_RecurringEntity::addEntityThroughRecursion($recurResult, $params['parent_event_id']);
}
$status = ts('Repeat Configuration has been saved');
$params['parent_event_id'] = $parent_event_id;
$params['parent_event_start_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'start_date');
$params['parent_event_end_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'end_date');
+ $params['start_action_offset'] = $formValues['start_action_offset'];
}
- $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params);
+ $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params, $formValues['exclude_date_list']);
$count = 1;
foreach ($recurResult as $key => $value) {
$recurDates[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date']));