towards event:recursions thru objects
authorpriyankakaran26 <priyanka.karan26@gmail.com>
Fri, 12 Sep 2014 09:34:35 +0000 (10:34 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 09:00:54 +0000 (10:00 +0100)
CRM/Core/BAO/RecurringEntity.php

index b80cb34261b0c7d2c8e1aa8b1f6cfefdbecbe7d1..72a0f2f222ec0a8c90235a012840fc1fdd92d0ce 100644 (file)
@@ -660,4 +660,46 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
     $daoActivity->subject = 'I changed it';
     $daoActivity->save();
   }
+
+  static function testEventGeneration(){
+    //Event set initial params
+    $daoEvent = new CRM_Event_DAO_Event();
+    $daoEvent->title = 'Test event for Recurring Entity';
+    $daoEvent->event_type_id = 3;
+    $daoEvent->is_public = 1;
+    $daoEvent->start_date = date('YmdHis', strtotime('2014-09-24 10:30:00'));
+    $daoEvent->end_date =   date('YmdHis', strtotime('2014-09-26 10:30:00'));
+    $daoEvent->created_date = date('YmdHis');
+    $daoEvent->save();
+
+    //Lets assume you saved the repeat configuration with these criterias
+    /**
+     * Event occurs every 2 weeks
+     * on monday, wednesday and friday
+     * for 4 times
+     * For eg - A small course on art and craft
+     */
+    $recursion = new CRM_Core_BAO_RecurringEntity();
+    $recursion->entity_id    = $daoEvent->id;
+    $recursion->entity_table = 'civicrm_event';
+    $recursion->dateColumns  = array('start_date');
+    $recursion->scheduleDBParams = array (
+      'entity_value'                  => $daoEvent->id,
+      'entity_status'                 => $daoEvent->start_date,
+      'start_action_condition'        => 'monday,wednesday,friday',
+      'repetition_frequency_unit'     => 'week',
+      'repetition_frequency_interval' => 2,
+      'start_action_offset'           => 4,
+      'used_for'                      => 'event'
+    );
+
+    $generatedEntities = $recursion->generate(); 
+
+    // try changing something
+    $recursion->mode(3); // sets ->mode var & saves in DB
+
+    $daoEvent->find(TRUE);
+    $daoEvent->title = 'I changed event';
+    $daoEvent->save();
+  }
 }