Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-01-20-54-24
[civicrm-core.git] / CRM / Custom / Form / Field.php
index 04a1ae661b1c1a0dc7f722914646c118fce1c528..bf63a9fc2dea2e8211ac3b27c0988296cb9a9912 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -190,7 +190,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
         $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', $countryId);
       }
 
-      if ($defaults['data_type'] == 'ContactReference' && CRM_Utils_Array::value('filter', $defaults)) {
+      if ($defaults['data_type'] == 'ContactReference' && !empty($defaults['filter'])) {
         $contactRefFilter = 'Advance';
         if (strpos($defaults['filter'], 'action=lookup') !== FALSE &&
           strpos($defaults['filter'], 'group=') !== FALSE
@@ -261,6 +261,11 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
     if (isset($dontShowLink)) {
       $this->assign('dontShowLink', $dontShowLink);
     }
+    if ($this->_action & CRM_Core_Action::ADD &&
+      CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple', 'id')) {
+      $defaults['in_selector'] = 1;
+    }
+
     return $defaults;
   }
 
@@ -304,6 +309,11 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       '&nbsp;&nbsp;&nbsp;'
     );
     $sel->setOptions(array($dt, $it));
+
+    if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple')) {
+      $this->add('checkbox', 'in_selector', ts('Display in Table?'));
+    }
+
     if ($this->_action == CRM_Core_Action::UPDATE) {
       $this->freeze('data_type');
     }
@@ -551,7 +561,10 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
   /**
    * global validation rules for the form
    *
-   * @param array  $fields   (referance) posted values of the form
+   * @param array $fields (referance) posted values of the form
+   *
+   * @param $files
+   * @param $self
    *
    * @return array    if errors then list of errors to be posted back to the form,
    *                  true otherwise
@@ -660,19 +673,12 @@ SELECT count(*)
           break;
 
         case 'ContactReference':
-          if ($fields['filter_selected'] == 'Advance' &&
-            CRM_Utils_Array::value('filter', $fields)
-          ) {
+          if ($fields['filter_selected'] == 'Advance' && !empty($fields['filter'])) {
             if (strpos($fields['filter'], 'entity=') !== FALSE) {
               $errors['filter'] = ts("Please do not include entity parameter (entity is always 'contact')");
             }
-            elseif (strpos($fields['filter'], 'action=') === FALSE) {
-              $errors['filter'] = ts("Please specify 'action' parameter, it should be 'lookup' or 'get'");
-            }
-            elseif (strpos($fields['filter'], 'action=get') === FALSE &&
-              strpos($fields['filter'], 'action=lookup') === FALSE
-            ) {
-              $errors['filter'] = ts("Only 'get' and 'lookup' actions are supported.");
+            elseif (strpos($fields['filter'], 'action=get') === FALSE) {
+              $errors['filter'] = ts("Only 'get' action is supported.");
             }
           }
           $self->setDefaults(array('filter_selected', $fields['filter_selected']));
@@ -876,9 +882,7 @@ AND    option_group_id = %2";
     }
 
     // we can not set require and view at the same time.
-    if (!empty($fields['is_required']) &&
-      CRM_Utils_Array::value('is_view', $fields)
-    ) {
+    if (!empty($fields['is_required']) && !empty($fields['is_view'])) {
       $errors['is_view'] = ts('Can not set this field Required and View Only at the same time.');
     }
 
@@ -919,11 +923,11 @@ AND    option_group_id = %2";
     }
 
     $filter = 'null';
-    if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) {
+    if ($dataTypeKey == 11 && !empty($params['filter_selected'])) {
       if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) {
         $filter = trim($params['filter']);
       }
-      elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) {
+      elseif ($params['filter_selected'] == 'Group' && !empty($params['group_id'])) {
 
         $filter = 'action=lookup&group=' . implode(',', $params['group_id']);
       }
@@ -985,7 +989,6 @@ SELECT id
     if ($this->_action & CRM_Core_Action::UPDATE) {
       $params['id'] = $this->_id;
     }
-
     $customField = CRM_Core_BAO_CustomField::create($params);
     $this->_id = $customField->id;
 
@@ -997,7 +1000,7 @@ SELECT id
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
-      $msg += '<p>' . ts("Ready to add another.") . '</p>';
+      $msg .= '<p>' . ts("Ready to add another.") . '</p>';
       $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add',
           'reset=1&action=add&gid=' . $this->_gid
         ));