some code improvements
authorunknown <priyanka.karan26@gmail.com>
Wed, 22 Oct 2014 20:34:55 +0000 (21:34 +0100)
committerunknown <priyanka.karan26@gmail.com>
Wed, 22 Oct 2014 20:34:55 +0000 (21:34 +0100)
CRM/Core/BAO/RecurringEntity.php
CRM/Core/Form/RecurringEntity.php

index 3e636dd971d10ad83c759457e18f944e65fbb75d..a1388313721ac4cf1fbdd1108969a1d9913f0503 100644 (file)
@@ -36,7 +36,8 @@
 require_once 'packages/When/When.php'; 
 
 class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
-
+  
+  CONST RUNNING = 1;
   public $schedule = array();
   public $scheduleId = NULL;
   public $scheduleFormValues = array();
@@ -123,6 +124,13 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       ),
     );
   
+  static function getStatus() {
+    return self::$status;
+  }
+  
+  static function setStatus($status) {
+    self::$status = $status;
+  }
   /**
    * Function to save records in civicrm_recujrring_entity table
    *
@@ -241,7 +249,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
    * @return array
    */
   function generateEntities() {
-    self::$status = "Running"; 
+    self::setStatus(self::RUNNING);
 
     $newEntities  = array();
     $findCriteria = array();
@@ -628,7 +636,7 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity {
       return NULL;
     }
 
-    if (self::$status == 'Running') {
+    if (self::getStatus() == self::RUNNING) {
       // if recursion->generate() is doing some work, lets not intercept
       return NULL;
     }
index 327214a1ca281b7f368ed7b211f141f69db329bc..9560e0a5f1a6e3e9ca1625bf9bb17e7e1f9f7b09 100644 (file)
@@ -242,7 +242,7 @@ class CRM_Core_Form_RecurringEntity {
       //Ends
       if (CRM_Utils_Array::value('ends', $values)) {
         if ($values['ends'] == 1) {
-          if ($values['start_action_offset'] == "") {
+          if (empty($values['start_action_offset'])) {
             $errors['start_action_offset'] = ts('This is a required field');
           }
           else if ($values['start_action_offset'] > 30) {
@@ -250,7 +250,7 @@ class CRM_Core_Form_RecurringEntity {
           }
         }
         if ($values['ends'] == 2) {
-          if ($values['repeat_absolute_date'] != "") {
+          if (CRM_Utils_Array::value('repeat_absolute_date', $values)) {
             $entityStartDate = CRM_Utils_Date::processDate($values['repetition_start_date']);
             $end = CRM_Utils_Date::processDate($values['repeat_absolute_date']);
             if (($end < $entityStartDate) && ($end != 0)) {
@@ -269,7 +269,7 @@ class CRM_Core_Form_RecurringEntity {
       //Repeats BY
       if (CRM_Utils_Array::value('repeats_by', $values)) {
         if ($values['repeats_by'] == 1) {
-          if ($values['limit_to'] != "") {
+          if (CRM_Utils_Array::value('limit_to', $values)) {
             if ($values['limit_to'] < 1 && $values['limit_to'] > 31) {
               $errors['limit_to'] = ts('Invalid day of the month');
             }
@@ -279,7 +279,7 @@ class CRM_Core_Form_RecurringEntity {
           }
         }
         if ($values['repeats_by'] == 2) {
-          if ($values['entity_status_1'] != "" ) {
+          if (CRM_Utils_Array::value('entity_status_1', $values)) {
             $dayOfTheWeekNo = array(first, second, third, fourth, last);
             if (!in_array($values['entity_status_1'], $dayOfTheWeekNo)) {
                $errors['entity_status_1'] = ts('Invalid option');
@@ -288,7 +288,7 @@ class CRM_Core_Form_RecurringEntity {
           else {
             $errors['entity_status_1'] = ts('Invalid option');
           }
-          if ($values['entity_status_2'] != "" ) {
+          if (CRM_Utils_Array::value('entity_status_2', $values)) {
             if (!in_array($values['entity_status_2'], $dayOfTheWeek)) {
                $errors['entity_status_2'] = ts('Invalid day name');
             }