towards linked entities and generation
authorpriyankakaran26 <priyanka.karan26@gmail.com>
Sat, 13 Sep 2014 15:23:16 +0000 (16:23 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 09:08:25 +0000 (10:08 +0100)
CRM/Core/BAO/RecurringEntity.php
CRM/Core/Form/RecurringEntity.php
CRM/Event/Form/ManageEvent/Repeat.php

index d6ef935b6e1beac2d3d9b1f5f2689dfb48f14b4f..6ed728d357ea4016d46f2b57e0f36c594af8167b 100644 (file)
@@ -50,7 +50,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
   public $recursion = NULL;
   public $recursionCounter = NULL;
 
-  public $isGenRecurringEntity = TRUE;
+  public $isRecurringEntityRecord = TRUE;
 
   static $_tableDAOMapper = 
     array(
@@ -60,6 +60,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       '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) {
@@ -133,14 +134,20 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
 
   // 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) {
@@ -149,13 +156,28 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
           $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;
   }
 
@@ -300,6 +322,9 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
 
   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) {
index 667b238437cd3fd0c103d45a359f40101155160e..3a6123ad0995c36a0b7c67fd7d04d981d9b0b1c9 100644 (file)
@@ -296,77 +296,54 @@ class CRM_Core_Form_RecurringEntity {
       $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
    *
index 6072bb2272e7678a0a3d33c23245498a6428bd27..bf10d120744e5cfd7886de17b5e0cbd1b0cccc0d 100644 (file)
@@ -178,7 +178,8 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
   public function postProcess() {
     if($this->_id){
       $params = $this->controller->exportValues($this->_name); 
-      $params['parent_event_id'] = $this->_parentEventId;
+      $params['current_event_id'] = $this->_id;
+      $params['parent_event_id']  = $this->_parentEventId;
       $params['parent_event_start_date'] = $this->_parentEventStartDate;
       $params['parent_event_end_date'] = $this->_parentEventEndDate;
       //Unset event id
@@ -197,4 +198,4 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
     }  
   }
   
-}
\ No newline at end of file
+}