$activity = $this->processActivity($params);
$params['parent_entity_start_date'] = $this->_parentActivityStartDate;
$params['start_date_column_name'] = 'activity_date_time';
+ $params['entity_table'] = 'civicrm_activity';
//Unset activity id
unset($params['id']);
$linkedEntities = array(
protected $recursion = NULL;
+ public static $_entitiesToBeDeleted = array();
+
static $_recurringEntityHelper =
array(
'civicrm_event' => array(
- 'helper_class' => 'CRM_Event_BAO_Event',
- 'delete_func' => 'del',
- 'count_func' => ''
+ 'helper_class' => 'CRM_Event_DAO_Event',
+ 'delete_func' => 'CRM_Event_BAO_Event::del',
+ 'pre_delete_func' => 'CRM_Event_Form_ManageEvent_Repeat::checkRegistrationForEvents'
),
'civicrm_activity' => array(
- 'helper_class' => 'CRM_Activity_BAO_Activity',
- 'delete_func' => 'del',
- 'count_func' => ''
+ 'helper_class' => 'CRM_Activity_DAO_Activity',
+ 'delete_func' => 'CRM_Activity_BAO_Activity::deleteActivity',
+ 'pre_delete_func' => ''
)
);
/**
* This function gets all columns from civicrm_action_schedule on the basis of event id
*
- * @param int $eventId Entity ID
+ * @param int $entityId Entity ID
* @param string $used_for Specifies for which entity type it's used for
*
* @access public
*
* @return object
*/
- static public function getReminderDetailsByEntityId($entityId, $used_for) {
+ public static function getReminderDetailsByEntityId($entityId, $used_for) {
if ($entityId) {
$query = "
SELECT *
*/
static function postProcess($params = array(), $type, $linkedEntities = array()) {
$params['entity_id'] = self::$_entityId;
- if ($type && CRM_Utils_Array::value('entity_id', $params)) {
+ if (CRM_Utils_Array::value('entity_table', $params) && CRM_Utils_Array::value('entity_id', $params) && $type) {
$params['used_for'] = $type;
$params['parent_entity_id'] = self::$_parentEntityId;
$params['id'] = self::$_scheduleReminderID;
//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['entity_id']) {
- CRM_Event_BAO_Event::del($value['id']);
+ //If entity has any pre delete function, consider that first
+ if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) &&
+ CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
+ call_user_func(array(
+ CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
+ call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id'])))
+ );
+ }
+ //Ready to execute delete on entities if it has delete function set
+ if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) &&
+ CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) {
+ //Check if pre delete function has some ids to be deleted
+ if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) {
+ foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $value) {
+ call_user_func(array(
+ CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
+ call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array($value)))
+ );
+ }
+ }
+ else {
+ $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE);
+ foreach ($getRelatedEntities as $key => $value) {
+ call_user_func(array(
+ CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'],
+ call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array(array('id' => $value['id']))))
+ );
+ }
}
- }
}
- CRM_Core_BAO_RecurringEntity::delEntityRelations($params['entity_id'], 'civicrm_'.$type);
+ CRM_Core_BAO_RecurringEntity::delEntityRelations($params['entity_id'], $params['entity_table']);
}
$recursion = new CRM_Core_BAO_RecurringEntity();
}
$recursion->entity_id = $params['entity_id'];
- $recursion->entity_table = 'civicrm_'.$type;
+ $recursion->entity_table = $params['entity_table'];
if (!empty($linkedEntities)) {
$recursion->linkedEntities = $linkedEntities;
}
$params['parent_entity_end_date'] = $this->_parentEventEndDate;
$params['start_date_column_name'] = 'start_date';
$params['end_date_column_name'] = 'end_date';
+ $params['entity_table'] = 'civicrm_event';
//Unset event id
unset($params['id']);
return $participantDetails;
}
- /**
- * Update mode column in civicrm_recurring_entity table for event related tabs
- *
- * @params int $entityId event id
- * @params string $linkedEntityTable Linked entity table name for this event
- * @return array
- */
+ /**
+ * Update mode column in civicrm_recurring_entity table for event related tabs
+ *
+ * @params int $entityId event id
+ * @params string $linkedEntityTable Linked entity table name for this event
+ * @return array
+ */
public static function updateModeRecurringEntityForEvent($entityId, $linkedEntityTable) {
$result = array();
if ( $entityId && $linkedEntityTable ) {
}
}
return $result;
- }
+ }
+
+ /**
+ * This function checks if there was any registraion for related event ids,
+ * and returns array of ids with no regsitrations
+ * @param type $eventID Event ID
+ * @return type
+ */
+ public static function checkRegistrationForEvents($eventID) {
+ $eventIdsWithNoRegistration = array();
+ if ($eventID) {
+ $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($eventID, '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'] != $eventID) {
+ //CRM_Event_BAO_Event::del($value['id']);
+ $eventIdsWithNoRegistration[] = $value['id'];
+ }
+ }
+ }
+ CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted = $eventIdsWithNoRegistration;
+ return CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted;
+ }
}