INFRA-132 - Drupal.Classes.ClassDeclaration
[civicrm-core.git] / CRM / UF / Form / Field.php
index 97a936c763ff711f29f985e3f2220decdbd090d2..583608ee9836c3f0cbe55fd4e7b8f6f98b1507e6 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_UF_Form_Field extends CRM_Core_Form {
 
   /**
-   * the uf group id saved to the session for an update
+   * The uf group id saved to the session for an update
    *
    * @var int
-   * @access protected
    */
   protected $_gid;
 
@@ -50,7 +49,6 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
    * The field id, used when editing the field
    *
    * @var int
-   * @access protected
    */
   protected $_id;
 
@@ -58,15 +56,13 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
    * The set of fields that we can view/edit in the user field framework
    *
    * @var array
-   * @access protected
    */
   protected $_fields;
 
   /**
-   * the title for field
+   * The title for field
    *
    * @var int
-   * @access protected
    */
   protected $_title;
 
@@ -74,32 +70,28 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
    * The set of fields sent to the select element
    *
    * @var array
-   * @access protected
    */
   protected $_selectFields;
 
   /**
-   * to store fields with if locationtype exits status
+   * store fields with if locationtype exits status
    *
    * @var array
-   * @access protected
    */
   protected $_hasLocationTypes;
 
   /**
-   * is this profile has searchable field
+   * Is this profile has searchable field
    * or is any field having in selector true.
    *
    * @var boolean.
-   * @access protected
    */
   protected $_hasSearchableORInSelector;
 
   /**
-   * Function to set variables up before form is built
+   * Set variables up before form is built
    *
    * @return void
-   * @access public
    */
   public function preProcess() {
     $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
@@ -115,9 +107,12 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
 
       $session = CRM_Core_Session::singleton();
       $session->pushUserContext($url);
-      $breadCrumb = array(array('title' => ts('CiviCRM Profile Fields'),
+      $breadCrumb = array(
+        array(
+          'title' => ts('CiviCRM Profile Fields'),
           'url' => $url,
-        ));
+        )
+      );
       CRM_Utils_System::appendBreadCrumb($breadCrumb);
     }
 
@@ -183,10 +178,9 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * Function to actually build the form
+   * Build the form object
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
     if ($this->_action & CRM_Core_Action::DELETE) {
@@ -300,7 +294,8 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
       $defaultLocation = $this->_location_types[$defaultLocationType->id];
       unset($this->_location_types[$defaultLocationType->id]);
       $this->_location_types = array(
-        $defaultLocationType->id => $defaultLocation) + $this->_location_types;
+          $defaultLocationType->id => $defaultLocation,
+        ) + $this->_location_types;
     }
 
     $this->_location_types = array('Primary') + $this->_location_types;
@@ -374,8 +369,8 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
     }
 
     $this->_defaults = array();
-    $js              = "<script type='text/javascript'>\n";
-    $formName        = "document.{$this->_name}";
+    $js = "<script type='text/javascript'>\n";
+    $formName = "document.{$this->_name}";
 
     $alreadyMixProfile = FALSE;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
@@ -420,7 +415,6 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
       }
     }
 
-    // CRM_Core_Error::debug(array($sel1, $sel2, $sel3, $sel4));
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
 
     // proper interpretation of spec in CRM-8732
@@ -508,14 +502,13 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
    * Process the form
    *
    * @return void
-   * @access public
    */
   public function postProcess() {
     $ids = array('uf_group' => $this->_gid);
     if ($this->_action & CRM_Core_Action::DELETE) {
       $fieldValues = array('uf_group_id' => $this->_gid);
       CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
-      $deleted     = CRM_Core_BAO_UFField::del($this->_id);
+      $deleted = CRM_Core_BAO_UFField::del($this->_id);
 
       //update group_type every time. CRM-3608
       if ($this->_gid && $deleted) {
@@ -538,7 +531,6 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
       $ids['uf_field'] = $this->_id;
     }
 
-
     $name = NULL;
     if (isset($params['field_name'][1]) && isset($this->_selectFields[$params['field_name'][1]])) {
       // we dont get a name for a html formatting element
@@ -569,7 +561,10 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
       $config = CRM_Core_Config::singleton();
       $showBestResult = FALSE;
       if (in_array($ufField->field_name, array(
-        'country', 'state_province')) && count($config->countryLimit) > 1) {
+          'country',
+          'state_province',
+        )) && count($config->countryLimit) > 1
+      ) {
         // get state or country field weight if exists
         $field = 'state_province';
         if ($ufField->field_name == 'state_province') {
@@ -597,8 +592,8 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
         CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
       }
       CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.',
-          array(1 => $name, 2 => $this->_title)
-        ), ts('Profile Field Saved'), 'success');
+        array(1 => $name, 2 => $this->_title)
+      ), ts('Profile Field Saved'), 'success');
     }
     $buttonName = $this->controller->getButtonName();
 
@@ -606,40 +601,49 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
     if ($buttonName == $this->getButtonName('next', 'new')) {
       CRM_Core_Session::setStatus(ts(' You can add another profile field.'), '', 'info');
       $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add',
-          "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"
-        ));
+        "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"
+      ));
     }
     else {
       $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field',
-          "reset=1&action=browse&gid={$this->_gid}"
-        ));
+        "reset=1&action=browse&gid={$this->_gid}"
+      ));
       $session->set('showBestResult', $showBestResult);
     }
   }
 
   /**
-   * validation rule for subtype.
+   * Validation rule for subtype.
    *
-   * @param array $groupType contains all groupTypes.
+   * @param array $groupType
+   *   Contains all groupTypes.
    *
-   * @param  string  $fieldType type of field.
+   * @param string $fieldType
+   *   Type of field.
    *
    * @param array $errors
    *
-   * @return array list of errors to be posted back to the form
-   * @static
-   * @access public
+   * @return array
+   *   list of errors to be posted back to the form
    */
-  static function formRuleSubType($fieldType, $groupType, $errors) {
+  public static function formRuleSubType($fieldType, $groupType, $errors) {
     if (in_array($fieldType, array(
-      'Participant', 'Contribution', 'Membership', 'Activity'))) {
+      'Participant',
+      'Contribution',
+      'Membership',
+      'Activity',
+    ))) {
       $individualSubTypes = CRM_Contact_BAO_ContactType::subTypes('Individual');
       foreach ($groupType as $value) {
         if (!in_array($value, $individualSubTypes) &&
           !in_array($value, array(
-            'Participant', 'Contribution', 'Membership',
-              'Individual', 'Contact', 'Activity',
-            ))
+            'Participant',
+            'Contribution',
+            'Membership',
+            'Individual',
+            'Contact',
+            'Activity',
+          ))
         ) {
           $errors['field_name'] = ts('Cannot add or update profile field "%1" with combination of Household or Organization or any subtypes of Household or Organisation.', array(1 => $fieldType));
           break;
@@ -662,21 +666,29 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * validation rule for custom data extends entity column values.
+   * Validation rule for custom data extends entity column values.
    *
-   * @param Object  $customField Custom field
-   * @param Integer $gid         Group Id.
-   * @param String  $fieldType   Group type of the field
-   * @param Array   $errors      Collect errors
+   * @param Object $customField
+   *   Custom field.
+   * @param int $gid
+   *   Group Id.
+   * @param string $fieldType
+   *   Group type of the field.
+   * @param array $errors
+   *   Collect errors.
    *
-   * @return Array  list of errors to be posted back to the form
-   * @static
-   * @access public
+   * @return array
+   *   list of errors to be posted back to the form
    */
-  static function formRuleCustomDataExtentColumnValue($customField, $gid, $fieldType, &$errors) {
+  public static function formRuleCustomDataExtentColumnValue($customField, $gid, $fieldType, &$errors) {
     // fix me : check object $customField
     if (in_array($fieldType, array(
-          'Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) {
+      'Participant',
+      'Contribution',
+      'Membership',
+      'Activity',
+      'Case',
+    ))) {
       $params = array('id' => $customField->custom_group_id);
       $customGroup = array();
       CRM_Core_BAO_CustomGroup::retrieve($params, $customGroup);
@@ -710,15 +722,17 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
   /**
    * Validation rule to prevent multiple fields of primary location type within the same communication type.
    *
-   * @param Array   $fields            Submitted fields
-   * @param String  $profileFieldName  Group Id.
-   * @param Array   $groupFields       List of fields already in the group
-   * @param Array   $errors            Collect errors
+   * @param array $fields
+   *   Submitted fields.
+   * @param string $profileFieldName
+   *   Group Id.
+   * @param array $groupFields
+   *   List of fields already in the group.
+   * @param array $errors
+   *   Collect errors.
    *
-   * @static
-   * @access public
    */
-  static function formRulePrimaryCheck($fields, $profileFieldName, $groupFields, &$errors) {
+  public static function formRulePrimaryCheck($fields, $profileFieldName, $groupFields, &$errors) {
     //FIXME: This may need to also apply to website fields if they are refactored to allow more than one per profile
     $checkPrimary = array('phone' => 'civicrm_phone.phone', 'phone_and_ext' => 'civicrm_phone.phone');
     $whereCheck = NULL;
@@ -735,7 +749,7 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
 
       foreach ($groupFields as $groupField) {
         // if it is a phone
-        if ($groupField['where'] == $whereCheck && is_null($groupField['location_type_id']) && $groupField['field_id']  != $fieldID) {
+        if ($groupField['where'] == $whereCheck && is_null($groupField['location_type_id']) && $groupField['field_id'] != $fieldID) {
           $primaryOfSameTypeFound = $groupField['title'];
           break;
         }
@@ -747,23 +761,23 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * global validation rules for the form
+   * Global validation rules for the form
    *
-   * @param array $fields posted values of the form
+   * @param array $fields
+   *   Posted values of the form.
    *
    * @param $files
    * @param $self
    *
-   * @return array list of errors to be posted back to the form
-   * @static
-   * @access public
+   * @return array
+   *   list of errors to be posted back to the form
    */
-  static function formRule($fields, $files, $self) {
-    $is_required     = CRM_Utils_Array::value('is_required', $fields, FALSE);
+  public static function formRule($fields, $files, $self) {
+    $is_required = CRM_Utils_Array::value('is_required', $fields, FALSE);
     $is_registration = CRM_Utils_Array::value('is_registration', $fields, FALSE);
-    $is_view         = CRM_Utils_Array::value('is_view', $fields, FALSE);
-    $in_selector     = CRM_Utils_Array::value('in_selector', $fields, FALSE);
-    $is_active       = CRM_Utils_Array::value('is_active', $fields, FALSE);
+    $is_view = CRM_Utils_Array::value('is_view', $fields, FALSE);
+    $in_selector = CRM_Utils_Array::value('in_selector', $fields, FALSE);
+    $is_active = CRM_Utils_Array::value('is_active', $fields, FALSE);
 
     $errors = array();
     if ($is_view && $is_registration) {
@@ -779,7 +793,12 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
     }
 
     if ($in_selector && in_array($entityName, array(
-      'Contribution', 'Participant', 'Membership', 'Activity'))) {
+        'Contribution',
+        'Participant',
+        'Membership',
+        'Activity',
+      ))
+    ) {
       $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $entityName));
     }
 
@@ -967,7 +986,10 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
         if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) {
           if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
             if ($fieldType != $profileType) {
-              $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
+              $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(
+                  1 => $fieldType,
+                  2 => $profileType,
+                ));
             }
           }
           else {
@@ -976,7 +998,10 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
               $profileType != $basicType &&
               $profileType != 'Contact'
             ) {
-              $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
+              $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(
+                  1 => $fieldType,
+                  2 => $profileType,
+                ));
             }
           }
         }
@@ -990,4 +1015,5 @@ class CRM_UF_Form_Field extends CRM_Core_Form {
     }
     return empty($errors) ? TRUE : $errors;
   }
+
 }