public $recursion = NULL;
public $recursionCounter = NULL;
- public $isGenRecurringEntity = TRUE;
+ public $isRecurringEntityRecord = TRUE;
static $_tableDAOMapper =
array(
'civicrm_tell_friend' => 'CRM_Friend_DAO_Friend',
'civicrm_pcp_block' => 'CRM_PCP_DAO_PCPBlock',
'civicrm_activity' => 'CRM_Activity_DAO_Activity',
+ 'civicrm_activity_contact' => 'CRM_Activity_DAO_ActivityContact',
);
static function add(&$params) {
// generate new DAOs and along with entries in recurring_entity table
function generateEntities() {
- // fixme: check if entityid & entitytable set
-
- $newEntities = array();
+ $newEntities = array();
+ $findCriteria = array();
if (!empty($this->recursionDates)) {
- // save an entry with initiating entity-id & entity-table
- if (!$this->find(TRUE)) {
- $this->parent_id = $this->entity_id;
- $this->save();
+ if ($this->entity_id) {
+ $findCriteria = array('id' => $this->entity_id);
+
+ // save an entry with initiating entity-id & entity-table
+ if ($this->entity_table && !$this->find(TRUE)) {
+ $this->parent_id = $this->entity_id;
+ $this->save();
+ }
+ }
+ if (empty($findCriteria)) {
+ CRM_Core_Error::fatal("Find criteria missing to generate from. Make sure entity_id and table is set.");
}
foreach ($this->recursionDates as $key => $dateCols) {
$newCriteria[$col] = $val;
}
$obj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($this->entity_table,
- array('id' => $this->entity_id),
+ $findCriteria,
$newCriteria,
- $this->isGenRecurringEntity
+ $this->isRecurringEntityRecord
);
+
+ if ($obj->id) {
+ $newCriteria = array();
+ foreach ($this->linkedEntities as $linkedInfo) {
+ foreach ($linkedInfo['linkedColumns'] as $col) {
+ $newCriteria[$col] = $obj->id;
+ }
+ $linkedObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity($linkedInfo['table'],
+ $linkedInfo['findCriteria'],
+ $newCriteria,
+ CRM_Utils_Array::value('isRecurringEntityRecord', $linkedInfo, TRUE)
+ );
+ }
+ }
$newEntities[] = $obj->id;
}
}
+
return $newEntities;
}
static public function copyCreateEntity($entityTable, $fromCriteria, $newParams, $createRecurringEntity = TRUE) {
$daoName = self::$_tableDAOMapper[$entityTable];
+ if (!$daoName) {
+ CRM_Core_Error::fatal("DAO Mapper missing for $entityTable.");
+ }
$newObject = CRM_Core_DAO::copyGeneric($daoName, $fromCriteria, $newParams);
if ($newObject->id && $createRecurringEntity) {
$recursion->intervalDateColumns = array('end_date' => $interval);
}
- $recurResult = $recursion->generateRecursiveDates();
+ $recursion->entity_id = $params['current_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,
+ ),
+ );
+
+ $recurResult = $recursion->generate();
- //$recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params, $excludeDateList);
- if(!empty($recurResult) && $params['parent_event_id']) {
- CRM_Core_Form_RecurringEntity::addEntityThroughRecursion($recurResult, $params['parent_event_id']);
- }
$status = ts('Repeat Configuration has been saved');
CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
}
//end of function
- static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){
- if(!empty($recursionResult) && $currEntityID){
- $parentEventId = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event');
- if(!$parentEventId){
- $parentEventId = $currEntityID;
- }
-
- // add first entry just for parent
- CRM_Core_BAO_RecurringEntity::quickAdd($parentEventId, $parentEventId, 'civicrm_event');
-
- foreach ($recursionResult as $key => $value) {
- $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event',
- array('id' => $parentEventId),
- $value);
-
- CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity',
- array(
- 'entity_id' => $parentEventId,
- 'entity_table' => 'civicrm_event'
- ),
- array(
- 'entity_id' => $newEventObj->id
- ),
- FALSE
- );
-
- CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join',
- array(
- 'entity_id' => $parentEventId,
- 'entity_table' => 'civicrm_event'
- ),
- array(
- 'entity_id' => $newEventObj->id
- ),
- FALSE
- );
-
- CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend',
- array(
- 'entity_id' => $parentEventId,
- 'entity_table' => 'civicrm_event'
- ),
- array(
- 'entity_id' => $newEventObj->id
- )
- );
-
- CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block',
- array(
- 'entity_id' => $parentEventId,
- 'entity_table' => 'civicrm_event'
- ),
- array(
- 'entity_id' => $newEventObj->id
- )
- );
- }
- }
- }
-
/**
* Return a descriptive name for the page, used in wizard header
*