Merge pull request #1824 from dlobo/CRM-13577
authorKurund Jalmi <kurund@civicrm.org>
Tue, 22 Oct 2013 11:57:33 +0000 (04:57 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Tue, 22 Oct 2013 11:57:33 +0000 (04:57 -0700)
CRM-13577 - cleanup vedaconsulting patch and PR - 1821

CRM/Batch/BAO/Batch.php
CRM/Contact/Form/Contact.php
CRM/Contact/Form/Domain.php
CRM/Contact/Form/Edit/Address.php
CRM/Contact/Page/View/Vcard.php
CRM/Core/BAO/Address.php
CRM/Event/Form/ManageEvent/Location.php
CRM/Report/Form.php
CRM/Report/Form/Contribute/Detail.php
CRM/Report/Form/Member/ContributionDetail.php

index c7ea9fd99fbc6ce61d3ed8bff25932dbeb986f4c..c3bfdc219e4b6babd0f1a0b09160a535ddf760eb 100644 (file)
@@ -470,14 +470,16 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
   /**
    * function to get batch list
    *
-   * @return array array of batches
+   * @return array array of all batches
+   * excluding batches with data entry in progress
    */
   static function getBatches() {
-    $query = 'SELECT id, title
+    $dataEntryStatusId = CRM_Core_OptionGroup::getValue('batch_status','Data Entry');
+    $query = "SELECT id, title
       FROM civicrm_batch
-      WHERE type_id IN (1,2)
-      AND status_id = 2
-      ORDER BY id DESC';
+      WHERE item_count >= 1
+      AND status_id != {$dataEntryStatusId}
+      ORDER BY id DESC";
 
     $batches = array();
     $dao = CRM_Core_DAO::executeQuery($query);
index 6cea50882c87a1b81da83515791598518a8c36de..000931f50e36e4f7de5fc130106ea312020fadb7 100644 (file)
@@ -591,7 +591,7 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form {
     }
 
     if (array_key_exists('Address', $this->_editOptions)) {
-      $this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'));
+      $this->addFormRule(array('CRM_Contact_Form_Edit_Address', 'formRule'), $this);
     }
 
     if (array_key_exists('CommunicationPreferences', $this->_editOptions)) {
index 74d0df2e23436f5712dfb1f16b79438ed11c7330..1e1671122b4b4bce8952a0784059619ba2ca38b9 100644 (file)
@@ -207,7 +207,7 @@ class CRM_Contact_Form_Domain extends CRM_Core_Form {
   static function formRule($fields) {
     $errors = array();
     // check for state/country mapping
-    CRM_Contact_Form_Edit_Address::formRule($fields, $errors);
+    $errors = CRM_Contact_Form_Edit_Address::formRule($fields, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullObject);
 
     //fix for CRM-3552,
     //as we use "fromName"<emailaddresss> format for domain email.
index 42c83697615f3e088c1c38045c1864a58a71a829..95b95fb2543e69695c9179a538c9fc1a63c4162e 100644 (file)
@@ -274,6 +274,13 @@ class CRM_Contact_Form_Edit_Address {
       // And we can't set it to 'address_' because we want to set it in a slightly different format.
       CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
 
+      // during contact editing : if no address is filled
+      // required custom data must not produce 'required' form rule error
+      // more handling done in formRule func
+      if (!$inlineEdit) {
+        CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree);
+      }
+
       $template     = CRM_Core_Smarty::singleton();
       $tplGroupTree = $template->get_template_vars('address_groupTree');
       $tplGroupTree = empty($tplGroupTree) ? array(
@@ -312,16 +319,47 @@ class CRM_Contact_Form_Edit_Address {
    * @access public
    * @static
    */
-  static function formRule($fields) {
+  static function formRule($fields, $files, $self) {
     $errors = array();
+
+    $customDataRequiredFields = array();
+    if (property_exists($self, '_addressRequireOmission')) {
+      $customDataRequiredFields = explode(',', $self->_addressRequireOmission);
+    }
+
     // check for state/county match if not report error to user.
     if (CRM_Utils_Array::value('address', $fields) && is_array($fields['address'])) {
       foreach ($fields['address'] as $instance => $addressValues) {
+
         if (CRM_Utils_System::isNull($addressValues)) {
+          // DETACH 'required' form rule error to
+          // custom data only if address data not exists upon submission
+          if (!empty($customDataRequiredFields)) {
+            foreach($customDataRequiredFields as $customElementName) {
+              $elementName = "address[$instance][$customElementName]";
+              if ($self->getElementError($elementName)) {
+                // set element error to none
+                $self->setElementError($elementName, NULL);
+              }
+            }
+          }
           continue;
         }
 
+        // DETACH 'required' form rule error to
+        // custom data only if address data not exists upon submission
+        if (!empty($customDataRequiredFields) && !CRM_Core_BAO_Address::dataExists($addressValues)) {
+          foreach($customDataRequiredFields as $customElementName) {
+            $elementName = "address[$instance][$customElementName]";
+            if ($self->getElementError($elementName)) {
+              // set element error to none
+              $self->setElementError($elementName, NULL);
+            }
+          }
+        }
+
         $countryId = CRM_Utils_Array::value('country_id', $addressValues);
+
         $stateProvinceId = CRM_Utils_Array::value('state_province_id', $addressValues);
 
         //do check for mismatch countries
@@ -546,5 +584,29 @@ class CRM_Contact_Form_Edit_Address {
       // end of parse address functionality
     }
   }
-}
 
+
+  static function storeRequiredCustomDataInfo(&$form, $groupTree) {
+    if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
+      $requireOmission = NULL;
+      foreach ($groupTree as $csId => $csVal) {
+        // only process Address entity fields
+        if ($csVal['extends'] != 'Address') {
+          continue;
+        }
+
+        foreach ($csVal['fields'] as $cdId => $cdVal) {
+          if ($cdVal['is_required']) {
+            $elementName = $cdVal['element_name'];
+            if (in_array($elementName, $form->_required)) {
+              // store the omitted rule for a element, to be used later on
+              $requireOmission .= $cdVal['element_custom_name'] . ',';
+            }
+          }
+        }
+      }
+
+      $form->_addressRequireOmission = rtrim($requireOmission, ',');
+    }
+  }
+}
\ No newline at end of file
index 5e1ce28dba22268675116dc4d5b1acbc5fa158f8..2d4759a4a9ae4a804b58f58441a33fd93632abaa 100644 (file)
@@ -70,6 +70,10 @@ class CRM_Contact_Page_View_Vcard extends CRM_Contact_Page_View {
         CRM_Utils_Array::value('prefix', $defaults),
         CRM_Utils_Array::value('suffix', $defaults)
       );
+      $organizationName = CRM_Utils_Array::value('organization_name', $defaults);
+      if ($organizationName !== NULL) {
+        $vcard->addOrganization($organizationName);
+      }
     }
     elseif ($defaults['contact_type'] == 'Organization') {
       $vcard->setName($defaults['organization_name'], '', '', '', '');
index 21be1e027d39ba75ad67b5f27137fe88e73a5b9b..40785fcb7883d6ecaa4c9dda2b549b02e8a63a18 100644 (file)
@@ -1198,4 +1198,4 @@ SELECT is_primary,
     }
     return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
   }
-}
+}
\ No newline at end of file
index 738e06e89251ccba370968a05bdf4174c1c70811..05cc054ab602a1126fd187a30c7f3f78eeada53a 100644 (file)
@@ -165,7 +165,7 @@ class CRM_Event_Form_ManageEvent_Location extends CRM_Event_Form_ManageEvent {
    */
   static function formRule($fields) {
     // check for state/country mapping
-    $errors = CRM_Contact_Form_Edit_Address::formRule($fields);
+    $errors = CRM_Contact_Form_Edit_Address::formRule($fields, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullObject);
 
     return empty($errors) ? TRUE : $errors;
   }
index 763b10bb2f85b62e30a31aa5f3849968981013e3..87bbb52bace17a86016604292f76a35c2437c741 100644 (file)
@@ -591,7 +591,7 @@ class CRM_Report_Form extends CRM_Core_Form {
     foreach ($this->_columns as $tableName => $table) {
       if (array_key_exists('fields', $table)) {
         foreach ($table['fields'] as $fieldName => $field) {
-          if (!array_key_exists('no_display', $field)) {
+          if (!CRM_Utils_Array::value('no_display', $field)) {
             if (isset($field['required'])) {
               // set default
               $this->_defaults['fields'][$fieldName] = 1;
@@ -734,7 +734,7 @@ class CRM_Report_Form extends CRM_Core_Form {
       if (array_key_exists('fields', $table)) {
         foreach ($table['fields'] as $fieldName => $field) {
           $groupTitle = '';
-          if (!array_key_exists('no_display', $field)) {
+          if (!CRM_Utils_Array::value('no_display', $field)) {
             foreach ( array('table', 'field') as $var) {
               if (!empty(${$var}['grouping'])) {
                 if (!is_array(${$var}['grouping'])) {
@@ -939,7 +939,7 @@ class CRM_Report_Form extends CRM_Core_Form {
 
       if ($this->_autoIncludeIndexedFieldsAsOrderBys && array_key_exists('extends', $table) && !empty($table['extends'])) {
         foreach ($table['fields'] as $fieldName => $field) {
-          if (!array_key_exists('no_display', $field)) {
+          if (!CRM_Utils_Array::value('no_display', $field)) {
             $options[$fieldName] = $field['title'];
           }
         }
@@ -1690,7 +1690,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND
 
     // unset columns not to be displayed.
     foreach ($this->_columnHeaders as $key => $value) {
-      if (is_array($value) && isset($value['no_display'])) {
+      if (CRM_Utils_Array::value('no_display', $value)) {
         unset($this->_columnHeaders[$key]);
       }
     }
index b4c7cd1a46dc46288be7c6a7295d24a816715e4f..b3c68d9e009a6c5e62028f28e8828ecd6af72b13 100644 (file)
@@ -41,6 +41,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
   protected $_nameFieldHonor = FALSE;
 
   protected $_summary = NULL;
+  protected $_allBatches = NULL;
 
   protected $_customGroupExtends = array(
     'Contribution');
@@ -341,8 +342,8 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
     $this->_tagFilter = TRUE;
 
     // Don't show Batch display column and filter unless batches are being used
-    $this->_closedBatches = CRM_Batch_BAO_Batch::getBatches();
-    if (!empty($this->_closedBatches)) {
+    $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
+    if (!empty($this->_allBatches)) {
       $this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
       $this->_columns['civicrm_batch']['fields']['batch_id'] = array(
         'name' => 'id',
@@ -353,7 +354,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
         'title' => ts('Batch Name'),
         'type' => CRM_Utils_Type::T_INT,
         'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-        'options' => $this->_closedBatches,
+        'options' => $this->_allBatches,
       );
       $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
       $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array(
@@ -485,11 +486,14 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form {
                            {$this->_aliases['civicrm_contribution']}.id = {$this->_aliases['civicrm_note']}.entity_id )";
     }
     //for contribution batches
-    if ($this->_closedBatches && CRM_Utils_Array::value('batch_id', $this->_params['fields'])) {
+    if ($this->_allBatches &&
+      (CRM_Utils_Array::value('batch_id', $this->_params['fields']) || !empty($this->_params['bid_value']))) {
       $this->_from .= "
+                LEFT JOIN civicrm_entity_financial_trxn tx ON (tx.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+                   tx.entity_table = 'civicrm_contribution')
                  LEFT JOIN  civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
-                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
-                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution')
+                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = tx.financial_trxn_id AND
+                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_financial_trxn')
                  LEFT JOIN civicrm_batch {$this->_aliases['civicrm_batch']}
                         ON {$this->_aliases['civicrm_batch']}.id = {$this->_aliases['civicrm_entity_batch']}.batch_id";
     }
index ac0482e0ecf72548dafefb20a30629036f26cf3c..442c6f856c8a9b3b0767934a970d65f3608b8035 100644 (file)
@@ -42,6 +42,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
   protected $_nameFieldHonor = FALSE;
 
   protected $_summary = NULL;
+  protected $_allBatches = NULL;
 
   protected $_customGroupExtends = array(
     'Contribution', 'Membership');
@@ -420,8 +421,8 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
     $this->_tagFilter = TRUE;
 
     // Don't show Batch display column and filter unless batches are being used
-    $this->_closedBatches = CRM_Batch_BAO_Batch::getBatches();
-    if (!empty($this->_closedBatches)) {
+    $this->_allBatches = CRM_Batch_BAO_Batch::getBatches();
+    if (!empty($this->_allBatches)) {
       $this->_columns['civicrm_batch']['dao'] = 'CRM_Batch_DAO_Batch';
       $this->_columns['civicrm_batch']['fields']['batch_id'] = array(
         'name' => 'id',
@@ -432,7 +433,7 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
         'title' => ts('Batch Name'),
         'type' => CRM_Utils_Type::T_INT,
         'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-        'options' => $this->_closedBatches,
+        'options' => $this->_allBatches,
       );
       $this->_columns['civicrm_entity_batch']['dao'] = 'CRM_Batch_DAO_EntityBatch';
       $this->_columns['civicrm_entity_batch']['fields']['entity_batch_id'] = array(
@@ -575,12 +576,14 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form {
                          {$this->_aliases['civicrm_phone']}.is_primary = 1)";
     }
     //for contribution batches
-    if ($this->_closedBatches &&
+    if ($this->_allBatches &&
       (CRM_Utils_Array::value('batch_id', $this->_params['fields']) || !empty($this->_params['bid_value']))) {
       $this->_from .= "
+                LEFT JOIN civicrm_entity_financial_trxn tx ON (tx.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
+                   tx.entity_table = 'civicrm_contribution')
                  LEFT JOIN  civicrm_entity_batch {$this->_aliases['civicrm_entity_batch']}
-                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = {$this->_aliases['civicrm_contribution']}.id AND
-                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_contribution')
+                        ON ({$this->_aliases['civicrm_entity_batch']}.entity_id = tx.financial_trxn_id AND
+                        {$this->_aliases['civicrm_entity_batch']}.entity_table = 'civicrm_financial_trxn')
                  LEFT JOIN civicrm_batch {$this->_aliases['civicrm_batch']}
                         ON {$this->_aliases['civicrm_batch']}.id = {$this->_aliases['civicrm_entity_batch']}.batch_id";
     }