Merge pull request #4865 from eileenmcnaughton/my-first-factory
[civicrm-core.git] / CRM / Custom / Form / Field.php
index f15bf18cf4794d9413f0c754c9c24387654f37bd..b40f7ddb85931b806d8d2de0fd8253a8cad0931d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -41,13 +41,12 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
   /**
    * Constants for number of options for data types of multiple option.
    */
-  CONST NUM_OPTION = 11;
+  const NUM_OPTION = 11;
 
   /**
-   * the custom group id saved to the session for an update
+   * The custom group id saved to the session for an update
    *
    * @var int
-   * @access protected
    */
   protected $_gid;
 
@@ -55,7 +54,6 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
    * The field id, used when editing the field
    *
    * @var int
-   * @access protected
    */
   protected $_id;
 
@@ -63,12 +61,11 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
    * The default custom data/input types, when editing the field
    *
    * @var array
-   * @access protected
    */
   protected $_defaultDataType;
 
   /**
-   * array of custom field values if update mode
+   * Array of custom field values if update mode
    */
   protected $_values;
 
@@ -86,12 +83,11 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
   private static $_dataToLabels = NULL;
 
   /**
-   * Function to set variables up before form is built
+   * Set variables up before form is built
    *
    * @param null
    *
    * @return void
-   * @access public
    */
   public function preProcess() {
     if (!(self::$_dataTypeKeys)) {
@@ -136,42 +132,51 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
 
     if (self::$_dataToLabels == NULL) {
       self::$_dataToLabels = array(
-        array('Text' => ts('Text'), 'Select' => ts('Select'),
-          'Radio' => ts('Radio'), 'CheckBox' => ts('CheckBox'), 'Multi-Select' => ts('Multi-Select'),
+        array(
+      'Text' => ts('Text'),
+      'Select' => ts('Select'),
+          'Radio' => ts('Radio'),
+      'CheckBox' => ts('CheckBox'),
+      'Multi-Select' => ts('Multi-Select'),
           'AdvMulti-Select' => ts('Adv Multi-Select (obsolete)'),
-          'Autocomplete-Select' => ts('Autocomplete Select'),
+          'Autocomplete-Select' => ts('Autocomplete-Select'),
         ),
-        array('Text' => ts('Text'), 'Select' => ts('Select'),
+        array(
+      'Text' => ts('Text'),
+      'Select' => ts('Select'),
           'Radio' => ts('Radio'),
         ),
-        array('Text' => ts('Text'), 'Select' => ts('Select'),
+        array(
+      'Text' => ts('Text'),
+      'Select' => ts('Select'),
           'Radio' => ts('Radio'),
         ),
-        array('Text' => ts('Text'), 'Select' => ts('Select'),
+        array(
+      'Text' => ts('Text'),
+      'Select' => ts('Select'),
           'Radio' => ts('Radio'),
         ),
-        array('TextArea' => ts('TextArea'), 'RichTextEditor' => ts('RichTextEditor')),
+        array('TextArea' => ts('TextArea'), 'RichTextEditor' => ts('Rich Text Editor')),
         array('Date' => ts('Select Date')),
         array('Radio' => ts('Radio')),
         array('StateProvince' => ts('Select State/Province'), 'Multi-Select' => ts('Multi-Select State/Province')),
-        array('Country' => ts('Select Country'), 'Multi-Select' => ts('Multi-Select Country ')),
+        array('Country' => ts('Select Country'), 'Multi-Select' => ts('Multi-Select Country')),
         array('File' => ts('Select File')),
         array('Link' => ts('Link')),
-        array('ContactReference' => ts('Autocomplete Select')),
+        array('ContactReference' => ts('Autocomplete-Select')),
       );
     }
   }
 
   /**
-   * This function sets the default values for the form. Note that in edit/view mode
+   * Set default values for the form. Note that in edit/view mode
    * the default values are retrieved from the database
    *
    * @param null
    *
    * @return array    array of default values
-   * @access public
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     $defaults = $this->_values;
 
     if ($this->_id) {
@@ -270,12 +275,11 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
   }
 
   /**
-   * Function to actually build the form
+   * Build the form object
    *
    * @param null
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
     if ($this->_gid) {
@@ -328,7 +332,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       $optionTypes = array('1' => ts('Create a new set of options'));
     }
     else {
-      $optionTypes = array('1' => ts('Create a new set of options'),
+      $optionTypes = array(
+      '1' => ts('Create a new set of options'),
         '2' => ts('Reuse an existing set'),
       );
 
@@ -347,7 +352,6 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
         'onclick' => "showOptionSelect();"), '<br/>'
     );
 
-
     $contactGroups = CRM_Core_PseudoConstant::group();
     asort($contactGroups);
 
@@ -559,9 +563,10 @@ class CRM_Custom_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
@@ -569,9 +574,8 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
    * @return array    if errors then list of errors to be posted back to the form,
    *                  true otherwise
    * @static
-   * @access public
    */
-  static function formRule($fields, $files, $self) {
+  public static function formRule($fields, $files, $self) {
     $default = CRM_Utils_Array::value('default_value', $fields);
 
     $errors = array();
@@ -581,9 +585,10 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
     $name   = CRM_Utils_String::munge($title, '_', 64);
     $gId    = $self->_gid;  // CRM-7564
     $query  = 'select count(*) from civicrm_custom_field where ( name like %1 OR label like %2 ) and id != %3 and custom_group_id = %4';
-    $fldCnt = CRM_Core_DAO::singleValueQuery($query, array(1 => array($name, 'String'),
+    $fldCnt = CRM_Core_DAO::singleValueQuery($query, array(
+    1 => array($name, 'String'),
         2 => array($title, 'String'),
-        3 => array((int)$self->_id, 'Integer'),
+        3 => array((int) $self->_id, 'Integer'),
         4 => array($gId, 'Integer'),
       ));
     if ($fldCnt) {
@@ -595,7 +600,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       // gives the ascii value
       $asciiValue = ord($title{0});
       if ($asciiValue >= 48 && $asciiValue <= 57) {
-        $errors['label'] = ts("Field's Name should not start with digit");
+        $errors['label'] = ts("Name cannot not start with a digit");
       }
     }
 
@@ -614,19 +619,19 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       switch ($dataType) {
         case 'Int':
           if (!CRM_Utils_Rule::integer($default)) {
-            $errors['default_value'] = ts('Please enter a valid integer as default value.');
+            $errors['default_value'] = ts('Please enter a valid integer.');
           }
           break;
 
         case 'Float':
           if (!CRM_Utils_Rule::numeric($default)) {
-            $errors['default_value'] = ts('Please enter a valid number as default value.');
+            $errors['default_value'] = ts('Please enter a valid number.');
           }
           break;
 
         case 'Money':
           if (!CRM_Utils_Rule::money($default)) {
-            $errors['default_value'] = ts('Please enter a valid number value.');
+            $errors['default_value'] = ts('Please enter a valid number.');
           }
           break;
 
@@ -895,7 +900,6 @@ AND    option_group_id = %2";
    * @param null
    *
    * @return void
-   * @access public
    */
   public function postProcess() {
     // store the submitted values in an array
@@ -1016,4 +1020,3 @@ SELECT id
     $this->ajaxResponse['customField'] = $customField->toArray();
   }
 }
-