require_once 'packages/When/When.php';
class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
- public $linkedEntities = array();
+
public $schedule = array();
public $scheduleId = NULL;
- public $scheduleDBParams = array();
+ public $scheduleFormValues = array();
public $dateColumns = array();
public $overwriteColumns = array();
public $intervalDateColumns = array();
-
public $excludeDates = array();
-
- public $recursion = NULL;
- public $recursionCounter = NULL;
+
+ public $linkedEntities = array();
public $isRecurringEntityRecord = TRUE;
+ protected $recursion = NULL;
+
static $_tableDAOMapper =
array(
'civicrm_event' => 'CRM_Event_DAO_Event',
'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
);
+
+ static $_updateSkipFields =
+ array(
+ 'civicrm_event' => array('start_date', 'end_date'),
+ 'civicrm_tell_friend' => array('entity_id'),
+ 'civicrm_pcp_block' => array('entity_id'),
+ 'civicrm_activity' => array('activity_date_time'),
+ );
+
static function add(&$params) {
if (CRM_Utils_Array::value('id', $params)) {
CRM_Utils_Hook::pre('edit', 'RecurringEntity', $params['id'], $params);
if ($this->scheduleId) {
// get params by ID
- $this->recursion = $this->getRecursionFromReminder($this->scheduleId);
- } else if (!empty($this->schedule)) {
- $this->scheduleDBParams = $this->mapFormValuesToDB($this->schedule);//call using obj
+ $this->schedule = $this->getScheduleParams($this->scheduleId);
+ } else if (!empty($this->scheduleFormValues)) {
+ $this->schedule = $this->mapFormValuesToDB($this->scheduleFormValues);
}
- if (!empty($this->scheduleDBParams)) {
- $this->recursion = $this->getRecursionFromReminderByDBParams($this->scheduleDBParams);
+ if (!empty($this->schedule)) {
+ $this->recursion = $this->getRecursionFromSchedule($this->schedule);
}
return $this->recursion;
}
$this->isRecurringEntityRecord
);
- if ($obj->id) {
+ if (is_a($obj, 'CRM_Core_DAO') && $obj->id) {
$newCriteria = array();
$newEntities[$this->entity_table][$count] = $obj->id;
CRM_Utils_Array::value('isRecurringEntityRecord', $linkedInfo, TRUE)
);
- if ($linkedObj->id) {
+ if (is_a($linkedObj, 'CRM_Core_DAO') && $linkedObj->id) {
$newEntities[$linkedInfo['table']][$count] = $linkedObj->id;
}
}
$recursionDates = array();
if (is_a($this->recursion, 'When')) {
- $initialCount = CRM_Utils_Array::value('start_action_offset', $this->scheduleDBParams);
+ $initialCount = CRM_Utils_Array::value('start_action_offset', $this->scheduleFormValues);
$exRangeStart = $exRangeEnd = NULL;
if (!empty($this->excludeDateRangeColumns)) {
// lets increase the counter, so we get correct number of occurrences
$initialCount++;
$this->recursion->count($initialCount);
- $this->recursionCounter = $initialCount;
}
continue;
}
}
$newObject = CRM_Core_DAO::copyGeneric($daoName, $fromCriteria, $newParams);
- if ($newObject && $newObject->id && $createRecurringEntity) {
+ if (is_a($newObject, 'CRM_Core_DAO') && $newObject->id && $createRecurringEntity) {
$object = new $daoName( );
foreach ($fromCriteria as $key => $value) {
$object->$key = $value;
$processedEntities[$key] = 1;
if (array_key_exists($entityTable, self::$_tableDAOMapper)) {
- $daoName = self::$_tableDAOMapper[$entityTable];
+ $daoName = self::$_tableDAOMapper[$entityTable];
- // FIXME: generalize me
- $skipData = array('start_date' => NULL,
- 'end_date' => NULL,
- );
+ $skipData = array();
+ if (array_key_exists($entityTable, self::$_updateSkipFields)) {
+ $skipFields = self::$_updateSkipFields[$entityTable];
+ foreach ($skipFields as $sfield) {
+ $skipData[$sfield] = NULL;
+ }
+ }
$updateDAO = CRM_Core_DAO::cascadeUpdate($daoName, $obj->id, $entityID, $skipData);
CRM_Core_DAO::freeResult();
return $dao;
}
- function getRecursionFromReminder($scheduleReminderId){
- if($scheduleReminderId){
+ function getScheduleParams($scheduleReminderId) {
+ $scheduleReminderDetails = array();
+ if ($scheduleReminderId){
//Get all the details from schedule reminder table
$scheduleReminderDetails = self::getScheduleReminderDetailsById($scheduleReminderId);
$scheduleReminderDetails = (array) $scheduleReminderDetails;
- $recursionDetails = self::getRecursionFromReminderByDBParams($scheduleReminderDetails);
}
- return $recursionDetails;
+ return $scheduleReminderDetails;
}
- function getRecursionFromReminderByDBParams($scheduleReminderDetails = array()){
+ function getRecursionFromSchedule($scheduleReminderDetails = array()){
$r = new When();
//If there is some data for this id
if($scheduleReminderDetails['repetition_frequency_unit']){
$recursion->entity_id = $daoActivity->id;
$recursion->entity_table = 'civicrm_activity';
$recursion->dateColumns = array('activity_date_time');
- $recursion->scheduleDBParams = array(
+ $recursion->schedule = array(
'entity_value' => $daoActivity->id,
'start_action_date' => $daoActivity->activity_date_time,
'entity_status' => 'fourth saturday',
);
$generatedEntities = $recursion->generate();
- foreach ($generatedEntities as $entityID) {
+ foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id',
'id', 'Check DB if repeating activities were created'
);
$daoActivity->save();
// check if other activities were affected
- foreach ($generatedEntities as $entityID) {
+ foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBCompareValue('CRM_Activity_DAO_Activity', $entityID, 'subject', 'id', 'Changed Activity', 'Check if subject was updated');
}
}
$recursion->entity_id = $daoEvent->id;
$recursion->entity_table = 'civicrm_event';
$recursion->dateColumns = array('start_date');
- $recursion->scheduleDBParams = array (
+ $recursion->schedule = array (
'entity_value' => $daoEvent->id,
'start_action_date' => $daoEvent->start_date,
'start_action_condition' => 'wednesday',
$daoEvent->save();
// check if other events were affected
- foreach ($generatedEntities as $entityID) {
+ foreach ($generatedEntities['civicrm_event'] as $entityID) {
$this->assertDBCompareValue('CRM_Event_DAO_Event', $entityID, 'title', 'id', 'Event Changed', 'Check if title was updated');
}
}