repetition start date on the basis of parent event start date
authorunknown <priyanka.karan26@gmail.com>
Sun, 7 Sep 2014 18:57:48 +0000 (19:57 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 08:55:16 +0000 (09:55 +0100)
CRM/Core/BAO/RecurringEntity.php
CRM/Core/Form/RecurringEntity.php
CRM/Event/Form/ManageEvent/Repeat.php
templates/CRM/Core/Form/RecurringEntity.tpl

index 92d5b2fe8194fdd920f7ac9ffd7a93313b32a764..4319dfe85913c1409e5bb21abb284ce5c736d154 100644 (file)
@@ -230,165 +230,175 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
        
     if(CRM_Utils_Array::value('parent_event_id', $formParams)){
         $dbParams['entity_value'] = $formParams['parent_event_id'];
-      }
+    }
+    
+    if(CRM_Utils_Array::value('repetition_start_date', $formParams)){
+      $repetition_start_date = new DateTime($formParams['repetition_start_date']);
+      $repetition_start_date->modify('+1 day');
+      $dbParams['entity_status'] = CRM_Utils_Date::processDate($repetition_start_date->format('Y-m-d H:i:s'));
+    }
 
     if(CRM_Utils_Array::value('repetition_frequency_unit', $formParams)){
-        $dbParams['repetition_frequency_unit'] = $formParams['repetition_frequency_unit'];
-      }
+      $dbParams['repetition_frequency_unit'] = $formParams['repetition_frequency_unit'];
+    }
 
     if(CRM_Utils_Array::value('repetition_frequency_interval', $formParams)){
-        $dbParams['repetition_frequency_interval'] = $formParams['repetition_frequency_interval'];
-      }
+      $dbParams['repetition_frequency_interval'] = $formParams['repetition_frequency_interval'];
+    }
 
     //For Repeats on:(weekly case)
-      if($formParams['repetition_frequency_unit'] == 'week'){
-        if(CRM_Utils_Array::value('start_action_condition', $formParams)){
-          $repeats_on = CRM_Utils_Array::value('start_action_condition', $formParams);
-          $dbParams['start_action_condition'] = implode(",", array_keys($repeats_on));
-        }
+    if($formParams['repetition_frequency_unit'] == 'week'){
+      if(CRM_Utils_Array::value('start_action_condition', $formParams)){
+        $repeats_on = CRM_Utils_Array::value('start_action_condition', $formParams);
+        $dbParams['start_action_condition'] = implode(",", array_keys($repeats_on));
       }
+    }
 
     //For Repeats By:(monthly case)
-      if($formParams['repetition_frequency_unit'] == 'month'){
-        if($formParams['repeats_by'] == 1){
-          if(CRM_Utils_Array::value('limit_to', $formParams)){
-            $dbParams['limit_to'] = $formParams['limit_to'];
-          }
+    if($formParams['repetition_frequency_unit'] == 'month'){
+      if($formParams['repeats_by'] == 1){
+        if(CRM_Utils_Array::value('limit_to', $formParams)){
+          $dbParams['limit_to'] = $formParams['limit_to'];
         }
-        if($formParams['repeats_by'] == 2){
-          if(CRM_Utils_Array::value('start_action_date_1', $formParams) && CRM_Utils_Array::value('start_action_date_2', $formParams)){
-            $dbParams['start_action_date'] = $formParams['start_action_date_1']." ".$formParams['start_action_date_2'];
-          }
+      }
+      if($formParams['repeats_by'] == 2){
+        if(CRM_Utils_Array::value('start_action_date_1', $formParams) && CRM_Utils_Array::value('start_action_date_2', $formParams)){
+          $dbParams['start_action_date'] = $formParams['start_action_date_1']." ".$formParams['start_action_date_2'];
         }
       }
+    }
 
     //For "Ends" - After: 
-      if($formParams['ends'] == 1){
-        if(CRM_Utils_Array::value('start_action_offset', $formParams)){
-          $dbParams['start_action_offset'] = $formParams['start_action_offset'];
-        }
+    if($formParams['ends'] == 1){
+      if(CRM_Utils_Array::value('start_action_offset', $formParams)){
+        $dbParams['start_action_offset'] = $formParams['start_action_offset'];
       }
+    }
 
-      //For "Ends" - On: 
-      if($formParams['ends'] == 2){
-        if(CRM_Utils_Array::value('repeat_absolute_date', $formParams)){
-          $dbParams['absolute_date'] = CRM_Utils_Date::processDate($formParams['repeat_absolute_date']);
-        }
+    //For "Ends" - On: 
+    if($formParams['ends'] == 2){
+      if(CRM_Utils_Array::value('repeat_absolute_date', $formParams)){
+        $dbParams['absolute_date'] = CRM_Utils_Date::processDate($formParams['repeat_absolute_date']);
       }
-      return $dbParams;
     }
+    return $dbParams;
+  }
 
-    static public function getScheduleReminderDetailsById($scheduleReminderId){
-      $query = "SELECT *
-                FROM civicrm_action_schedule WHERE 1";
-      if($scheduleReminderId){
-        $query .= "
-        AND id = %1";
-      }
-      $dao = CRM_Core_DAO::executeQuery($query,
-            array(
-              1 => array($scheduleReminderId, 'Integer')
-            )
-          );
-      $dao->fetch();
-      return $dao;
+  static public function getScheduleReminderDetailsById($scheduleReminderId){
+    $query = "SELECT *
+              FROM civicrm_action_schedule WHERE 1";
+    if($scheduleReminderId){
+      $query .= "
+      AND id = %1";
     }
+    $dao = CRM_Core_DAO::executeQuery($query,
+          array(
+            1 => array($scheduleReminderId, 'Integer')
+          )
+        );
+    $dao->fetch();
+    return $dao;
+  }
     
-    static function getRecursionFromReminder($scheduleReminderId){
-      if($scheduleReminderId){
-        //Get all the details from schedule reminder table
-        $scheduleReminderDetails = self::getScheduleReminderDetailsById($scheduleReminderId);
-        $scheduleReminderDetails = (array) $scheduleReminderDetails;
-        $recursionDetails = self::getRecursionFromReminderByDBParams($scheduleReminderDetails);
-      }
-      return $recursionDetails;
+  static function getRecursionFromReminder($scheduleReminderId){
+    if($scheduleReminderId){
+      //Get all the details from schedule reminder table
+      $scheduleReminderDetails = self::getScheduleReminderDetailsById($scheduleReminderId);
+      $scheduleReminderDetails = (array) $scheduleReminderDetails;
+      $recursionDetails = self::getRecursionFromReminderByDBParams($scheduleReminderDetails);
     }
+    return $recursionDetails;
+  }
     
-    static function getRecursionFromReminderByDBParams($scheduleReminderDetails = array()){
-      $r = new When();
-      //If there is some data for this id
-      if($scheduleReminderDetails['repetition_frequency_unit']){
+  static function getRecursionFromReminderByDBParams($scheduleReminderDetails = array()){
+    $r = new When();
+    //If there is some data for this id
+    if($scheduleReminderDetails['repetition_frequency_unit']){
+      if($scheduleReminderDetails['entity_status']){
+        $currDate = date('Y-m-d H:i:s', strtotime($scheduleReminderDetails['entity_status']));
+      }else{
         $currDate = date("Y-m-d H:i:s");
-        $start = new DateTime($currDate);
-        if($scheduleReminderDetails['repetition_frequency_unit']){
-          $repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
-          if($repetition_frequency_unit == "day"){
-            $repetition_frequency_unit = "dai";
-          }
-          $repetition_frequency_unit = $repetition_frequency_unit.'ly';
-          $r->recur($start, $repetition_frequency_unit);
+      }
+      $start = new DateTime($currDate);
+      if($scheduleReminderDetails['repetition_frequency_unit']){
+        $repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
+        if($repetition_frequency_unit == "day"){
+          $repetition_frequency_unit = "dai";
         }
+        $repetition_frequency_unit = $repetition_frequency_unit.'ly';
+        $r->recur($start, $repetition_frequency_unit);
+      }
 
-        if($scheduleReminderDetails['repetition_frequency_interval']){
-          $r->interval($scheduleReminderDetails['repetition_frequency_interval']);
-        }else{
-          $r->errors[] = 'Repeats every: is a required field';
-        }
+      if($scheduleReminderDetails['repetition_frequency_interval']){
+        $r->interval($scheduleReminderDetails['repetition_frequency_interval']);
+      }else{
+        $r->errors[] = 'Repeats every: is a required field';
+      }
 
-        //week
-        if($scheduleReminderDetails['repetition_frequency_unit'] == 'week'){
-          if($scheduleReminderDetails['start_action_condition']){
-            $startActionCondition = $scheduleReminderDetails['start_action_condition'];
-            $explodeStartActionCondition = explode(',', $startActionCondition);
-            $buildRuleArray = array();
-            foreach($explodeStartActionCondition as $key => $val){
-              $buildRuleArray[] = strtoupper(substr($val, 0, 2));
-            }
-            $r->wkst('MO')->byday($buildRuleArray);
+      //week
+      if($scheduleReminderDetails['repetition_frequency_unit'] == 'week'){
+        if($scheduleReminderDetails['start_action_condition']){
+          $startActionCondition = $scheduleReminderDetails['start_action_condition'];
+          $explodeStartActionCondition = explode(',', $startActionCondition);
+          $buildRuleArray = array();
+          foreach($explodeStartActionCondition as $key => $val){
+            $buildRuleArray[] = strtoupper(substr($val, 0, 2));
           }
+          $r->wkst('MO')->byday($buildRuleArray);
         }
+      }
 
-        //month 
-        if($scheduleReminderDetails['repetition_frequency_unit'] == 'month'){
-          if($scheduleReminderDetails['limit_to']){
-            $r->bymonthday(array($scheduleReminderDetails['limit_to']));
-          }
-          if($scheduleReminderDetails['start_action_date']){
-            $startActionDate = explode(" ", $scheduleReminderDetails['start_action_date']);
-            switch ($startActionDate[0]) {
-              case 'first':
-                  $startActionDate1 = 1;
-                  break;
-              case 'second':
-                  $startActionDate1 = 2;
-                  break;
-              case 'third':
-                  $startActionDate1 = 3;
-                  break;
-              case 'fourth':
-                  $startActionDate1 = 4;
-                  break;
-              case 'last':
-                  $startActionDate1 = -1;
-                  break;
-            }
-            $concatStartActionDateBits = $startActionDate1.strtoupper(substr($startActionDate[1], 0, 2));
-            $r->byday(array($concatStartActionDateBits));
-          }
+      //month 
+      if($scheduleReminderDetails['repetition_frequency_unit'] == 'month'){
+        if($scheduleReminderDetails['limit_to']){
+          $r->bymonthday(array($scheduleReminderDetails['limit_to']));
         }
-
-        //Ends
-        if($scheduleReminderDetails['start_action_offset']){
-          if($scheduleReminderDetails['start_action_offset'] > 30){
-            $r->errors[] = 'Occurrences should be less than or equal to 30';
+        if($scheduleReminderDetails['start_action_date']){
+          $startActionDate = explode(" ", $scheduleReminderDetails['start_action_date']);
+          switch ($startActionDate[0]) {
+            case 'first':
+                $startActionDate1 = 1;
+                break;
+            case 'second':
+                $startActionDate1 = 2;
+                break;
+            case 'third':
+                $startActionDate1 = 3;
+                break;
+            case 'fourth':
+                $startActionDate1 = 4;
+                break;
+            case 'last':
+                $startActionDate1 = -1;
+                break;
           }
-          $r->count($scheduleReminderDetails['start_action_offset']);
+          $concatStartActionDateBits = $startActionDate1.strtoupper(substr($startActionDate[1], 0, 2));
+          $r->byday(array($concatStartActionDateBits));
         }
+      }
 
-        if($scheduleReminderDetails['absolute_date']){
-          $absoluteDate = CRM_Utils_Date::setDateDefaults($scheduleReminderDetails['absolute_date']);
-          $endDate = new DateTime($absoluteDate[0].' '.$absoluteDate[1]);
-          $r->until($endDate);
+      //Ends
+      if($scheduleReminderDetails['start_action_offset']){
+        if($scheduleReminderDetails['start_action_offset'] > 30){
+          $r->errors[] = 'Occurrences should be less than or equal to 30';
         }
+        $r->count($scheduleReminderDetails['start_action_offset']);
+      }
 
-        if(!$scheduleReminderDetails['start_action_offset'] && !$scheduleReminderDetails['absolute_date']){
-          $r->errors[] = 'Ends: is a required field';
-        }
-     }else{
-       $r->errors[] = 'Repeats: is a required field';
-     }
-      return $r;
-    }
+      if($scheduleReminderDetails['absolute_date']){
+        $absoluteDate = CRM_Utils_Date::setDateDefaults($scheduleReminderDetails['absolute_date']);
+        $endDate = new DateTime($absoluteDate[0].' '.$absoluteDate[1]);
+        $r->until($endDate);
+      }
+
+      if(!$scheduleReminderDetails['start_action_offset'] && !$scheduleReminderDetails['absolute_date']){
+        $r->errors[] = 'Ends: is a required field';
+      }
+   }else{
+     $r->errors[] = 'Repeats: is a required field';
+   }
+    return $r;
+  }
     
   /*
    * Get Reminder id based on event id
index 1fc5175a183ec3bd2de7240c58deacbb52f43921..f6e6eb5b425a283f32a4ba26cf234eec54ef3891 100644 (file)
@@ -66,7 +66,8 @@ class CRM_Core_Form_RecurringEntity {
                          );
     $form->add('select', 'repetition_frequency_unit', ts('Repeats:'), $freqUnitsDisplay, TRUE);
     $numericOptions = CRM_Core_SelectValues::getNumericOptions(1, 30);
-    $form->add('select', 'repetition_frequency_interval', ts('Repeats every:'), $numericOptions, TRUE, array('style' => 'width:49px;'));
+    $form->add('select', 'repetition_frequency_interval', ts('Repeats every:'), $numericOptions, TRUE, array('style' => 'width:55px;'));
+    $form->addDate('repetition_start_date', ts('Repetition Start Date'), array(), FALSE);
     foreach($dayOfTheWeek as $key => $val){
         $startActionCondition[] = $form->createElement('checkbox', $key, NULL, substr($val."&nbsp;", 0, 3));
     }
@@ -76,7 +77,7 @@ class CRM_Core_Form_RecurringEntity {
       );
     $form->addRadio('repeats_by', ts("Repeats By:"), $roptionTypes, array(), NULL);
     $getMonths = CRM_Core_SelectValues::getNumericOptions(1, 31);
-    $form->add('select', 'limit_to', '', $getMonths, FALSE, array('style' => 'width:49px;'));
+    $form->add('select', 'limit_to', '', $getMonths, FALSE, array('style' => 'width:55px;'));
     $dayOfTheWeekNo = array('first'  => 'First',
                             'second'=> 'Second',
                             'third' => 'Third',
index a6b05de124348f5c7d36a645a7e475794dd89160..8fa3eb0311bcb30527758e7309ee0bd563ff21fe 100644 (file)
@@ -128,10 +128,11 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent {
     $defaults = array();
     
     //Set Schedule Reminder Id
-      $this->_scheduleReminderId = $this->_scheduleReminderDetails->id;
-
+    $this->_scheduleReminderId = $this->_scheduleReminderDetails->id;
+    list($defaults['repetition_start_date']) = CRM_Utils_Date::setDateDefaults($this->_parentEventStartDate);
     // Check if there is id for this event in Reminder table
     if($this->_scheduleReminderId){
+      list($defaults['repetition_start_date']) = CRM_Utils_Date::setDateDefaults($this->_scheduleReminderDetails->entity_status);
       $defaults['repetition_frequency_unit'] = $this->_scheduleReminderDetails->repetition_frequency_unit;
       $defaults['repetition_frequency_interval'] = $this->_scheduleReminderDetails->repetition_frequency_interval;
       $defaults['start_action_condition'] = array_flip(explode(",",$this->_scheduleReminderDetails->start_action_condition));
index 793a9d78d0a1140a0c9cdc2b556c7c9a4fc12d7f..0dd002b716aae116e6be32f5a6fa82078f0914a5 100644 (file)
             {include file="CRM/common/formButtons.tpl" location="top"}
         </div>
         <table class="form-layout-compressed">
+          <tr class="crm-core-form-recurringentity-block-repetition_start_date" id="tr-repetition_start_date">
+            <td class="label">{$form.repetition_start_date.label}</td>
+            <td>{include file="CRM/common/jcalendar.tpl" elementName=repetition_start_date}</td>
+          </tr>
           <tr class="crm-core-form-recurringentity-block-repetition_frequency_unit">
             <td class="label">{$form.repetition_frequency_unit.label}</td>
             <td>{$form.repetition_frequency_unit.html} {help id="id-repeats"}</td>
 </style>
 <script type="text/javascript">
   cj(document).ready(function() {
+      cj('#repetition_start_date_display').closest("tr").hide();
     /****** On load "Repeats By" and "Repeats On" blocks should be hidden if dropdown value is not week or month****** (Edit Mode)***/
     if(cj('#repetition_frequency_unit').val() == "week"){
         cj('.crm-core-form-recurringentity-block-start_action_condition').show();