*
*/
/**
- * This class generates form components for processing Event
+ * This class generates form components for processing Entity
*
*/
class CRM_Core_Form_RecurringEntity {
*/
protected static $_entityId = NULL;
+ /**
+ * Schedule Reminder ID
+ */
+ protected static $_scheduleReminderID = NULL;
+
+ /**
+ * Schedule Reminder data
+ */
+ protected static $_scheduleReminderDetails = array();
+
+ /**
+ * Parent Entity ID
+ */
+ protected static $_parentEntityId = NULL;
+
+ /**
+ * Exclude date information
+ */
+ public static $_excludeDateInfo = array();
+
+ static function preProcess($entityType) {
+ self::$_entityId = (int) CRM_Utils_Request::retrieve('id', 'Positive');
+ if (self::$_entityId && $entityType) {
+ $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor(self::$_entityId, 'civicrm_'.$entityType);
+ if ($checkParentExistsForThisId) {
+ self::$_parentEntityId = $checkParentExistsForThisId;
+ self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $entityType);
+ }
+ else {
+ self::$_parentEntityId = self::$_entityId;
+ self::$_scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId(self::$_entityId, $entityType);
+ }
+ self::$_scheduleReminderID = self::$_scheduleReminderDetails->id;
+ }
+ CRM_Core_OptionValue::getValues(array('name' => $entityType.'_repeat_exclude_dates_'.self::$_parentEntityId), $optionValue);
+ $excludeOptionValues = array();
+ if (!empty($optionValue)) {
+ foreach($optionValue as $key => $val) {
+ $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
+ }
+ self::$_excludeDateInfo = $excludeOptionValues;
+ }
+ }
+
+ /**
+ * This function sets the default values for the form. For edit/view mode
+ * the default values are retrieved from the database
+ *
+ * @access public
+ *
+ * @return None
+ */
+ static function setDefaultValues() {
+ $defaults = array();
+ if (self::$_scheduleReminderID) {
+ $defaults['repetition_frequency_unit'] = self::$_scheduleReminderDetails->repetition_frequency_unit;
+ $defaults['repetition_frequency_interval'] = self::$_scheduleReminderDetails->repetition_frequency_interval;
+ $defaults['start_action_condition'] = array_flip(explode(",",self::$_scheduleReminderDetails->start_action_condition));
+ foreach($defaults['start_action_condition'] as $key => $val) {
+ $val = 1;
+ $defaults['start_action_condition'][$key] = $val;
+ }
+ $defaults['start_action_offset'] = self::$_scheduleReminderDetails->start_action_offset;
+ if (self::$_scheduleReminderDetails->start_action_offset) {
+ $defaults['ends'] = 1;
+ }
+ list($defaults['repeat_absolute_date']) = CRM_Utils_Date::setDateDefaults(self::$_scheduleReminderDetails->absolute_date);
+ if (self::$_scheduleReminderDetails->absolute_date) {
+ $defaults['ends'] = 2;
+ }
+ $defaults['limit_to'] = self::$_scheduleReminderDetails->limit_to;
+ if (self::$_scheduleReminderDetails->limit_to) {
+ $defaults['repeats_by'] = 1;
+ }
+ $explodeStartActionCondition = array();
+ if (self::$_scheduleReminderDetails->entity_status) {
+ $explodeStartActionCondition = explode(" ", self::$_scheduleReminderDetails->entity_status);
+ $defaults['entity_status_1'] = $explodeStartActionCondition[0];
+ $defaults['entity_status_2'] = $explodeStartActionCondition[1];
+ }
+ if (self::$_scheduleReminderDetails->entity_status) {
+ $defaults['repeats_by'] = 2;
+ }
+ }
+ return $defaults;
+ }
+
static function buildQuickForm(&$form) {
- //$attributes_schedule = CRM_Core_DAO::getAttribute('CRM_Core_DAO_ActionMapping');
- self::$_entityId = CRM_Utils_Array::value('id', $_GET);
$form->assign('currentEntityId', self::$_entityId);
$form->_freqUnits = array('hour' => 'hour') + CRM_Core_OptionGroup::values('recur_frequency_units');
}
if ($values['ends'] == 2) {
if ($values['repeat_absolute_date'] != "") {
- $eventStartDate = CRM_Utils_Date::processDate($values['repetition_start_date']);
+ $entityStartDate = CRM_Utils_Date::processDate($values['repetition_start_date']);
$end = CRM_Utils_Date::processDate($values['repeat_absolute_date']);
- if (($end < $eventStartDate) && ($end != 0)) {
+ if (($end < $entityStartDate) && ($end != 0)) {
$errors['repeat_absolute_date'] = ts('End date should be after event\'s start date');
}
}
*
* @return None
*/
- static function postProcess($params=array(), $type) {
- if (!empty($type)) {
+ static function postProcess($params = array(), $type, $linkedEntities = array()) {
+ $params['entity_id'] = self::$_entityId;
+ if ($type && CRM_Utils_Array::value('entity_id', $params)) {
$params['used_for'] = $type;
- }
-
- //Save post params to the schedule reminder table
- $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($params);
+ $params['parent_entity_id'] = self::$_parentEntityId;
+ $params['id'] = self::$_scheduleReminderID;
- //Delete repeat configuration and rebuild
- if (CRM_Utils_Array::value('id', $params)) {
- CRM_Core_BAO_ActionSchedule::del($params['id']);
- unset($params['id']);
- }
- $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
-
- //exclude dates
- $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();
- $exclude_date_list = explode(",", $params['copyExcludeDates']);
+ //Save post params to the schedule reminder table
+ $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($params);
- //Check if there exists any values for this option group
- $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
- 'event_repeat_exclude_dates_'.$params['parent_event_id'],
- 'id',
- 'name'
- );
- if ($optionGroupIdExists) {
- CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
+ //Delete repeat configuration and rebuild
+ if (CRM_Utils_Array::value('id', $params)) {
+ CRM_Core_BAO_ActionSchedule::del($params['id']);
+ unset($params['id']);
}
- $optionGroupParams =
- array(
- 'name' => 'event_repeat_exclude_dates_'.$params['parent_event_id'],
- 'title' => 'Event Recursion',
- 'is_reserved' => 0,
- 'is_active' => 1
+ $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams);
+
+ //exclude dates
+ $excludeDateList = array();
+ if (CRM_Utils_Array::value('copyExcludeDates', $params) && CRM_Utils_Array::value('parent_entity_id', $params)) {
+ //Since we get comma separated values lets get them in array
+ $exclude_date_list = array();
+ $exclude_date_list = explode(",", $params['copyExcludeDates']);
+
+ //Check if there exists any values for this option group
+ $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
+ $type.'_repeat_exclude_dates_'.$params['parent_entity_id'],
+ 'id',
+ 'name'
);
- $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
- if ($opGroup->id) {
- $oldWeight= 0;
- $fieldValues = array('option_group_id' => $opGroup->id);
- foreach($exclude_date_list as $val) {
- $optionGroupValue =
- array(
- 'option_group_id' => $opGroup->id,
- 'label' => CRM_Utils_Date::processDate($val),
- 'value' => CRM_Utils_Date::processDate($val),
- 'name' => $opGroup->name,
- 'description' => 'Used for event recursion',
- '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);
+ if ($optionGroupIdExists) {
+ CRM_Core_BAO_OptionGroup::del($optionGroupIdExists);
+ }
+ $optionGroupParams =
+ array(
+ 'name' => $type.'_repeat_exclude_dates_'.$params['parent_entity_id'],
+ 'title' => $type.' recursion',
+ 'is_reserved' => 0,
+ 'is_active' => 1
+ );
+ $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams);
+ if ($opGroup->id) {
+ $oldWeight= 0;
+ $fieldValues = array('option_group_id' => $opGroup->id);
+ foreach($exclude_date_list as $val) {
+ $optionGroupValue =
+ array(
+ 'option_group_id' => $opGroup->id,
+ 'label' => CRM_Utils_Date::processDate($val),
+ 'value' => CRM_Utils_Date::processDate($val),
+ 'name' => $opGroup->name,
+ 'description' => 'Used for recurring '.$type,
+ '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);
+ }
}
}
- }
- //Delete relations if any from recurring entity tables before inserting new relations for this entity id
- if ($params['event_id']) {
- $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['event_id'], 'civicrm_event', TRUE);
- $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
- //Check if participants exists for events
- foreach ($getRelatedEntities as $key => $value) {
- if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $params['event_id']) {
- CRM_Event_BAO_Event::del($value['id']);
+ //Delete relations if any from recurring entity tables before inserting new relations for this entity id
+ if ($params['entity_id']) {
+ $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], 'civicrm_'.$type, TRUE);
+ if ($type == 'event') {
+ $participantDetails = CRM_Event_Form_ManageEvent_Repeat::getParticipantCountforEvent($getRelatedEntities);
+ //Check if participants exists for events
+ foreach ($getRelatedEntities as $key => $value) {
+ if (!CRM_Utils_Array::value($value['id'], $participantDetails['countByID']) && $value['id'] != $params['event_id']) {
+ CRM_Event_BAO_Event::del($value['id']);
+ }
+ }
}
+ CRM_Core_BAO_RecurringEntity::delEntityRelations($params['entity_id'], 'civicrm_'.$type);
}
- CRM_Core_BAO_RecurringEntity::delEntityRelations($params['event_id'], 'civicrm_event');
- }
- $recursion = new CRM_Core_BAO_RecurringEntity();
- $recursion->dateColumns = array('start_date');
- $recursion->scheduleId = $actionScheduleObj->id;
+ $recursion = new CRM_Core_BAO_RecurringEntity();
+ $recursion->dateColumns = array('start_date');
+ $recursion->scheduleId = $actionScheduleObj->id;
- if (!empty($excludeDateList)) {
- $recursion->excludeDates = $excludeDateList;
- $recursion->excludeDateRangeColumns = array('start_date', 'end_date');
- }
+ if (!empty($excludeDateList)) {
+ $recursion->excludeDates = $excludeDateList;
+ $recursion->excludeDateRangeColumns = array('start_date', 'end_date');
+ }
- if ($params['parent_event_end_date']) {
- $interval = $recursion->getInterval($params['parent_event_start_date'], $params['parent_event_end_date']);
- $recursion->intervalDateColumns = array('end_date' => $interval);
- }
+ if ($params['parent_entity_end_date']) {
+ $interval = $recursion->getInterval($params['parent_entity_start_date'], $params['parent_entity_end_date']);
+ $recursion->intervalDateColumns = array('end_date' => $interval);
+ }
- $recursion->entity_id = $params['event_id'];
- $recursion->entity_table = 'civicrm_event';
- $recursion->linkedEntities = array(
- array(
- 'table' => 'civicrm_price_set_entity',
- 'findCriteria' => array(
- 'entity_id' => $recursion->entity_id,
- 'entity_table' => 'civicrm_event'
- ),
- 'linkedColumns' => array('entity_id'),
- 'isRecurringEntityRecord' => FALSE,
- ),
- array(
- 'table' => 'civicrm_uf_join',
- 'findCriteria' => array(
- 'entity_id' => $recursion->entity_id,
- 'entity_table' => 'civicrm_event'
- ),
- 'linkedColumns' => array('entity_id'),
- 'isRecurringEntityRecord' => FALSE,
- ),
- array(
- 'table' => 'civicrm_tell_friend',
- 'findCriteria' => array(
- 'entity_id' => $recursion->entity_id,
- 'entity_table' => 'civicrm_event'
- ),
- 'linkedColumns' => array('entity_id'),
- 'isRecurringEntityRecord' => TRUE,
- ),
- array(
- 'table' => 'civicrm_pcp_block',
- 'findCriteria' => array(
- 'entity_id' => $recursion->entity_id,
- 'entity_table' => 'civicrm_event'
- ),
- 'linkedColumns' => array('entity_id'),
- 'isRecurringEntityRecord' => TRUE,
- ),
- );
+ $recursion->entity_id = $params['entity_id'];
+ $recursion->entity_table = 'civicrm_'.$type;
+ if (!empty($linkedEntities)) {
+ $recursion->linkedEntities = $linkedEntities;
+ }
- $recurResult = $recursion->generate();
+ $recurResult = $recursion->generate();
- $status = ts('Repeat Configuration has been saved');
- CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
+ $status = ts('Repeat Configuration has been saved');
+ CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
+ }
}
//end of function
*/
class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
- /**
- * Schedule Reminder Id
- */
- protected $_scheduleReminderId = NULL;
-
- /**
- * Schedule Reminder data
- */
- protected $_scheduleReminderDetails = array();
-
- /**
- * Parent Event ID
- */
- protected $_parentEventId = NULL;
-
/**
* Parent Event Start Date
*/
*/
protected $_parentEventEndDate = NULL;
- /**
- * Exclude date information
- */
- public $_excludeDateInfo = array();
-
- protected $_pager = NULL;
-
-
function preProcess() {
parent::preProcess();
+ CRM_Core_Form_RecurringEntity::preProcess('event');
$this->assign('currentEventId', $this->_id);
- $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
- $checkParentExistsForThisId;
+ $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event');
//If this ID has parent, send parent id
if ($checkParentExistsForThisId) {
- $this->_scheduleReminderDetails = self::getReminderDetailsByEventId($checkParentExistsForThisId, 'event');
- $this->_parentEventId = $checkParentExistsForThisId;
-
/**
* Get connected event information list
*/
//Get all connected event ids
//$allEventIds = CRM_Core_Form_RecurringEntity::getAllConnectedEvents($checkParentExistsForThisId);
- $allEventIdsArray = CRM_Core_BAo_RecurringEntity::getEntitiesForParent($checkParentExistsForThisId, 'civicrm_event');
+ $allEventIdsArray = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($checkParentExistsForThisId, 'civicrm_event');
$allEventIds = array();
if (!empty($allEventIdsArray)) {
foreach($allEventIdsArray as $key => $val) {
$this->assign('rows', $manageEvent);
}
}
- else {
- //ELse send this id as parent
- $this->_scheduleReminderDetails = self::getReminderDetailsByEventId($this->_id, 'event');
- $this->_parentEventId = $this->_id;
- }
+ //FIX ME : For summary
//Assign this to hide summary
- if (property_exists($this->_scheduleReminderDetails, 'id')) {
- $this->assign('scheduleReminderId', $this->_scheduleReminderDetails->id);
- }
+// if (property_exists($this->_scheduleReminderDetails, 'id')) {
+// $this->assign('scheduleReminderId', $this->_scheduleReminderDetails->id);
+// }
$parentEventParams = array('id' => $this->_id);
$parentEventValues = array();
$parentEventAttributes = CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $parentEventParams, $parentEventValues, $parentEventReturnProperties);
$this->_parentEventStartDate = $parentEventAttributes->start_date;
$this->_parentEventEndDate = $parentEventAttributes->end_date;
-
- //Get option exclude date information
- //$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'event_repeat_exclude_dates_'.$this->_parentEventId, 'id', 'name');
- CRM_Core_OptionValue::getValues(array('name' => 'event_repeat_exclude_dates_'.$this->_parentEventId), $optionValue);
- $excludeOptionValues = array();
- if (!empty($optionValue)) {
- foreach($optionValue as $key => $val) {
- $excludeOptionValues[$val['value']] = date('m/d/Y', strtotime($val['value']));
- }
- $this->_excludeDateInfo = $excludeOptionValues;
- }
}
/**
function setDefaultValues() {
$defaults = array();
- //Set Schedule Reminder Id
- if (property_exists($this->_scheduleReminderDetails, 'id')) {
- $this->_scheduleReminderId = $this->_scheduleReminderDetails->id;
- }
//Always pass current event's start date by default
$currentEventStartDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'start_date', 'id');
list($defaults['repetition_start_date'], $defaults['repetition_start_date_time']) = CRM_Utils_Date::setDateDefaults($currentEventStartDate, 'activityDateTime');
-
- // Check if there is id for this event in Reminder table
- if ($this->_scheduleReminderId) {
- $defaults['repetition_frequency_unit'] = $this->_scheduleReminderDetails->repetition_frequency_unit;
- $defaults['repetition_frequency_interval'] = $this->_scheduleReminderDetails->repetition_frequency_interval;
- $defaults['start_action_condition'] = array_flip(explode(",",$this->_scheduleReminderDetails->start_action_condition));
- foreach($defaults['start_action_condition'] as $key => $val) {
- $val = 1;
- $defaults['start_action_condition'][$key] = $val;
- }
- list($defaults['repeat_event_start_date'], $defaults['repeat_event_start_date_time']) = CRM_Utils_Date::setDateDefaults($this->_parentEventStartDate, 'activityDateTime');
- $defaults['start_action_offset'] = $this->_scheduleReminderDetails->start_action_offset;
- if ($this->_scheduleReminderDetails->start_action_offset) {
- $defaults['ends'] = 1;
- }
- list($defaults['repeat_absolute_date']) = CRM_Utils_Date::setDateDefaults($this->_scheduleReminderDetails->absolute_date);
- if ($this->_scheduleReminderDetails->absolute_date) {
- $defaults['ends'] = 2;
- }
- $defaults['limit_to'] = $this->_scheduleReminderDetails->limit_to;
- if ($this->_scheduleReminderDetails->limit_to) {
- $defaults['repeats_by'] = 1;
- }
- $explodeStartActionCondition = array();
- if ($this->_scheduleReminderDetails->entity_status) {
- $explodeStartActionCondition = explode(" ", $this->_scheduleReminderDetails->entity_status);
- $defaults['entity_status_1'] = $explodeStartActionCondition[0];
- $defaults['entity_status_2'] = $explodeStartActionCondition[1];
- }
- if ($this->_scheduleReminderDetails->entity_status) {
- $defaults['repeats_by'] = 2;
- }
- }
+ $recurringEntityDefaults = array();
+ $recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues();
+ $defaults = array_merge($defaults, $recurringEntityDefaults);
return $defaults;
}
public function postProcess() {
if ($this->_id) {
$params = $this->controller->exportValues($this->_name);
- $params['event_id'] = $this->_id;
- $params['parent_event_id'] = $this->_parentEventId;
- $params['parent_event_start_date'] = $this->_parentEventStartDate;
- $params['parent_event_end_date'] = $this->_parentEventEndDate;
+ $params['parent_entity_start_date'] = $this->_parentEventStartDate;
+ $params['parent_entity_end_date'] = $this->_parentEventEndDate;
//Unset event id
unset($params['id']);
-
- //Set Schedule Reminder id
- $params['id'] = $this->_scheduleReminderId;
+
$url = 'civicrm/event/manage/repeat';
$urlParams = "action=update&reset=1&id={$this->_id}";
- CRM_Core_Form_RecurringEntity::postProcess($params, 'event');
+ $linkedEntities = array(
+ array(
+ 'table' => 'civicrm_price_set_entity',
+ 'findCriteria' => array(
+ 'entity_id' => $this->_id,
+ 'entity_table' => 'civicrm_event'
+ ),
+ 'linkedColumns' => array('entity_id'),
+ 'isRecurringEntityRecord' => FALSE,
+ ),
+ array(
+ 'table' => 'civicrm_uf_join',
+ 'findCriteria' => array(
+ 'entity_id' => $this->_id,
+ 'entity_table' => 'civicrm_event'
+ ),
+ 'linkedColumns' => array('entity_id'),
+ 'isRecurringEntityRecord' => FALSE,
+ ),
+ array(
+ 'table' => 'civicrm_tell_friend',
+ 'findCriteria' => array(
+ 'entity_id' => $this->_id,
+ 'entity_table' => 'civicrm_event'
+ ),
+ 'linkedColumns' => array('entity_id'),
+ 'isRecurringEntityRecord' => TRUE,
+ ),
+ array(
+ 'table' => 'civicrm_pcp_block',
+ 'findCriteria' => array(
+ 'entity_id' => $this->_id,
+ 'entity_table' => 'civicrm_event'
+ ),
+ 'linkedColumns' => array('entity_id'),
+ 'isRecurringEntityRecord' => TRUE,
+ ),
+ );
+ CRM_Core_Form_RecurringEntity::postProcess($params, 'event', $linkedEntities);
CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams));
}
else {
return $participantDetails;
}
- /**
- * This function gets all columns from civicrm_action_schedule on the basis of event id
- *
- * @param int $eventId Event ID
- * @param string $used_for Specifies for which entity type it's used for
- *
- * @access public
- * @static
- *
- * @return object
- */
- static public function getReminderDetailsByEventId($eventId, $used_for) {
- if ($eventId) {
- $query = "
- SELECT *
- FROM civicrm_action_schedule
- WHERE entity_value = %1";
- if ($used_for) {
- $query .= " AND used_for = %2";
- }
- $params = array(
- 1 => array($eventId, 'Integer'),
- 2 => array($used_for, 'String')
- );
- $dao = CRM_Core_DAO::executeQuery($query, $params);
- $dao->fetch();
- }
- return $dao;
- }
-
/**
* Update mode column in civicrm_recurring_entity table for event related tabs
*