Moved function generateRecursion and addEntityThroughRecursion from Form/RecurringEnt...
authorunknown <priyanka.karan26@gmail.com>
Fri, 5 Sep 2014 16:11:50 +0000 (17:11 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 08:55:15 +0000 (09:55 +0100)
CRM/Core/BAO/RecurringEntity.php
CRM/Core/Form/RecurringEntity.php
CRM/Core/Page/AJAX/RecurringEntity.php

index bdfae9f077420f1c5b63e38c162136a9be30d9ab..5fd14605b1b145c2d551b17316f0bba35231cacd 100644 (file)
@@ -325,7 +325,6 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
             foreach($explodeStartActionCondition as $key => $val){
               $buildRuleArray[] = strtoupper(substr($val, 0, 2));
             }
-//              CRM_Core_Error::debug('$buildRuleArray', $buildRuleArray);exit;
             $r->wkst('MO')->byday($buildRuleArray);
           }
         }
@@ -402,6 +401,92 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       $dao->fetch();
     }
     return $dao;
-  }   
+  }  
+  
+  static public function generateRecursions($recursionObj, $params=array()){ 
+    $newParams = $recursionResult = array();
+    if($recursionObj && !empty($params)){ 
+      //Proceed only if these keys are found in array
+      if(CRM_Utils_Array::value('parent_event_start_date', $params) && CRM_Utils_Array::value('parent_event_id', $params)){
+        $count = 1;
+        while($result = $recursionObj->next()){
+          $newParams['start_date'] = CRM_Utils_Date::processDate($result->format('Y-m-d H:i:s'));
+          $parentStartDate = new DateTime($params['parent_event_start_date']);
+          //If events with end date
+          if(CRM_Utils_Array::value('parent_event_end_date', $params)){
+            $parentEndDate = new DateTime($params['parent_event_end_date']);
+            $interval = $parentStartDate->diff($parentEndDate);
+            $end_date = new DateTime($newParams['start_date']);
+            $end_date->add($interval);
+            $newParams['end_date'] = CRM_Utils_Date::processDate($end_date->format('Y-m-d H:i:s'));
+            $recursionResult[$count]['end_date'] = $newParams['end_date'];
+          }
+          $recursionResult[$count]['start_date'] = $newParams['start_date'];
+          $count++;
+        }
+      }
+    }
+    return $recursionResult;
+  }
+  
+  static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){
+    if(!empty($recursionResult) && $currEntityID){
+      $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event');
+      if(!$parent_event_id){
+        $parent_event_id = $currEntityID;
+      }
+
+      // add first entry just for parent
+      CRM_Core_BAO_RecurringEntity::quickAdd($parent_event_id, $parent_event_id, 'civicrm_event');
+
+      foreach ($recursionResult as $key => $value) {
+        $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event', 
+        array('id' => $parent_event_id), 
+        $value);
+
+        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity', 
+          array(
+            'entity_id' => $parent_event_id, 
+            'entity_table' => 'civicrm_event'
+          ), 
+          array(
+            'entity_id' => $newEventObj->id
+          ),
+          FALSE
+        );
+
+        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join', 
+          array(
+            'entity_id' => $parent_event_id, 
+            'entity_table' => 'civicrm_event'
+          ), 
+          array(
+            'entity_id' => $newEventObj->id
+          ),
+          FALSE
+        );
+
+        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend', 
+          array(
+            'entity_id' => $parent_event_id, 
+            'entity_table' => 'civicrm_event'
+          ), 
+          array(
+            'entity_id' => $newEventObj->id
+          )
+        );
+
+        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block', 
+          array(
+            'entity_id' => $parent_event_id, 
+            'entity_table' => 'civicrm_event'
+          ), 
+          array(
+            'entity_id' => $newEventObj->id
+          )
+        );
+      }
+    }
+  }
     
 }
index 0cd9c2c715c51e21b687d23b2113a618cbfdd2b4..7cb10b4031de8303f4d17e4880b6d8b4a55246d5 100644 (file)
@@ -125,7 +125,6 @@ class CRM_Core_Form_RecurringEntity {
   static function formRule($values) {
     $errors = array();
     $dayOfTheWeek = array(monday,tuesday,wednesday,thursday,friday,saturday,sunday);
-//    CRM_Core_Error::debug('$values', $values);
     
     //Repeats
     if(!CRM_Utils_Array::value('repetition_frequency_unit', $values)){
@@ -261,9 +260,9 @@ class CRM_Core_Form_RecurringEntity {
     }
     
     //Give call to create recursions
-    $recurResult = self::generateRecursions($recursionObject, $params);
+    $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params);
     if(!empty($recurResult)){
-      self::addEntityThroughRecursion($recurResult, $params['parent_event_id']);
+      CRM_Core_BAO_RecurringEntity::addEntityThroughRecursion($recurResult, $params['parent_event_id']);
     }
     $status = ts('Repeat Configuration has been saved');
     CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
@@ -279,116 +278,5 @@ class CRM_Core_Form_RecurringEntity {
   public function getTitle() {
     return ts('Repeat Event');
   }
-
-  static public function generateRecursions($recursionObj, $params=array()){ 
-    $newParams = $recursionResult = array();
-    if($recursionObj && !empty($params)){ 
-      //Proceed only if these keys are found in array
-      if(CRM_Utils_Array::value('parent_event_start_date', $params) && CRM_Utils_Array::value('parent_event_id', $params)){
-        $count = 1;
-        while($result = $recursionObj->next()){
-          //$result->format('YmdHis'). '<br />';
-          $newParams['start_date'] = CRM_Utils_Date::processDate($result->format('Y-m-d H:i:s'));
-          $parentStartDate = new DateTime($params['parent_event_start_date']);
-          //If open ended event
-          if(CRM_Utils_Array::value('parent_event_end_date', $params)){
-            $parentEndDate = new DateTime($params['parent_event_end_date']);
-            $interval = $parentStartDate->diff($parentEndDate);
-            $end_date = new DateTime($newParams['start_date']);
-            $end_date->add($interval);
-            $newParams['end_date'] = CRM_Utils_Date::processDate($end_date->format('Y-m-d H:i:s'));
-            $recursionResult[$count]['end_date'] = $newParams['end_date'];
-          }
-          $recursionResult[$count]['start_date'] = $newParams['start_date'];
-          $count++;
-        }
-      }
-    }
-    return $recursionResult;
-  }
-  
-  static public function addEntityThroughRecursion($recursionResult = array(), $currEntityID){
-    if(!empty($recursionResult) && $currEntityID){
-      $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($currEntityID, 'civicrm_event');
-      if(!$parent_event_id){
-        $parent_event_id = $currEntityID;
-      }
-
-      // add first entry just for parent
-      CRM_Core_BAO_RecurringEntity::quickAdd($parent_event_id, $parent_event_id, 'civicrm_event');
-
-      foreach ($recursionResult as $key => $value) {
-        $newEventObj = CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_event', 
-        array('id' => $parent_event_id), 
-        $value);
-
-        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_price_set_entity', 
-          array(
-            'entity_id' => $parent_event_id, 
-            'entity_table' => 'civicrm_event'
-          ), 
-          array(
-            'entity_id' => $newEventObj->id
-          ),
-          FALSE
-        );
-
-        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_uf_join', 
-          array(
-            'entity_id' => $parent_event_id, 
-            'entity_table' => 'civicrm_event'
-          ), 
-          array(
-            'entity_id' => $newEventObj->id
-          ),
-          FALSE
-        );
-
-        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_tell_friend', 
-          array(
-            'entity_id' => $parent_event_id, 
-            'entity_table' => 'civicrm_event'
-          ), 
-          array(
-            'entity_id' => $newEventObj->id
-          )
-        );
-
-        CRM_Core_BAO_RecurringEntity::copyCreateEntity('civicrm_pcp_block', 
-          array(
-            'entity_id' => $parent_event_id, 
-            'entity_table' => 'civicrm_event'
-          ), 
-          array(
-            'entity_id' => $newEventObj->id
-          )
-        );
-      }
-    }
-  }
-  
-  static function getListOfCurrentAndFutureEvents($ids=''){
-    if(isset($ids) and !empty($ids)){
-      $curDate = date('YmdHis');
-      $query = "SELECT group_concat(id) as ids FROM civicrm_event 
-                WHERE id IN ({$ids}) 
-                AND ( end_date >= {$curDate} OR
-                (
-                  ( end_date IS NULL OR end_date = '' ) AND start_date >= {$curDate}
-                ))";
-      $dao = CRM_Core_DAO::executeQuery($query);
-      $dao->fetch();
-    }
-    return $dao;
-  }
-  
-  static function deleleRelationsForEventsInPast($ids=''){
-    if(isset($ids) and !empty($ids)){
-      $query = "DELETE FROM civicrm_recurring_entity
-                WHERE entity_id IN ({$ids})";
-      $dao = CRM_Core_DAO::executeQuery($query);
-    }
-    return; 
-  }
-   
+     
 }
index 9af2a244d51c9a0dd913cd02c6610cc337836f93..a5693fb60112c9eb0833306a51ae3e7a729bd20c 100644 (file)
@@ -55,7 +55,7 @@ class CRM_Core_Page_AJAX_RecurringEntity {
             $params['parent_event_start_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'start_date');
             $params['parent_event_end_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['parent_event_id'], 'end_date');
           }
-          $recurResult = CRM_Core_Form_RecurringEntity::generateRecursions($recursionObject, $params); 
+          $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params); 
           $count = 1;
           foreach ($recurResult as $key => $value) {
             $recurDates[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date']));