Merge pull request #4944 from civicrm/batch-5.part2
[civicrm-core.git] / CRM / Custom / Form / ChangeFieldType.php
index 08eb50c2bd42689a98576a28501c2a440def3dd6..06d26d3da630ff691563591e90a4bf8f11988728 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -42,7 +42,6 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
    * The field id
    *
    * @var int
-   * @access protected
    */
   protected $_id;
 
@@ -62,7 +61,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
    * @return void
    * @acess protected
    */
-  function preProcess() {
+  public function preProcess() {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive',
       $this, TRUE
     );
@@ -86,15 +85,14 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $session->pushUserContext($url);
 
     CRM_Utils_System::setTitle(ts('Change Field Type: %1',
-        array(1 => $this->_values['label'])
-      ));
+      array(1 => $this->_values['label'])
+    ));
   }
 
   /**
    * Build the form object
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
 
@@ -114,7 +112,8 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
       'dst_html_type',
       ts('New HTML Type'),
       array(
-        '' => ts('- select -')) + $this->_htmlTypeTransitions,
+        '' => ts('- select -')
+      ) + $this->_htmlTypeTransitions,
       TRUE
     );
 
@@ -137,7 +136,6 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
    * Process the form when submitted
    *
    * @return void
-   * @access public
    */
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
@@ -168,7 +166,11 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     $customField->find(TRUE);
 
     if ($dstHtmlType == 'Text' && in_array($srcHtmlType, array(
-      'Select', 'Radio', 'Autocomplete-Select'))) {
+        'Select',
+        'Radio',
+        'Autocomplete-Select'
+      ))
+    ) {
       $customField->option_group_id = "NULL";
       CRM_Core_BAO_CustomField::checkOptionGroup($this->_values['option_group_id']);
     }
@@ -191,8 +193,8 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
 
     CRM_Core_Session::setStatus(ts('Input type of custom field \'%1\' has been successfully changed to \'%2\'.',
-        array(1 => $this->_values['label'], 2 => $dstHtmlType)
-      ), ts('Field Type Changed'), 'success');
+      array(1 => $this->_values['label'], 2 => $dstHtmlType)
+    ), ts('Field Type Changed'), 'success');
   }
 
   /**
@@ -201,7 +203,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
    *
    * @return array|null
    */
-  static function fieldTypeTransitions($dataType, $htmlType) {
+  public static function fieldTypeTransitions($dataType, $htmlType) {
     // Text field is single value field,
     // can not be change to other single value option which contains option group
     if ($htmlType == 'Text') {
@@ -269,13 +271,14 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
   public function firstValueToFlatten($table, $column) {
     $selectSql = "SELECT id, $column FROM $table WHERE $column IS NOT NULL";
     $updateSql = "UPDATE $table SET $column = %1 WHERE id = %2";
-    $dao       = CRM_Core_DAO::executeQuery($selectSql);
+    $dao = CRM_Core_DAO::executeQuery($selectSql);
     while ($dao->fetch()) {
       if (!$dao->{$column}) {
         continue;
       }
       $value = CRM_Core_DAO::VALUE_SEPARATOR . $dao->{$column} . CRM_Core_DAO::VALUE_SEPARATOR;
-      $params = array(1 => array((string)$value, 'String'),
+      $params = array(
+        1 => array((string) $value, 'String'),
         2 => array($dao->id, 'Integer'),
       );
       CRM_Core_DAO::executeQuery($updateSql, $params);
@@ -289,10 +292,11 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
   public function flattenToFirstValue($table, $column) {
     $selectSql = "SELECT id, $column FROM $table WHERE $column IS NOT NULL";
     $updateSql = "UPDATE $table SET $column = %1 WHERE id = %2";
-    $dao       = CRM_Core_DAO::executeQuery($selectSql);
+    $dao = CRM_Core_DAO::executeQuery($selectSql);
     while ($dao->fetch()) {
       $values = self::explode($dao->{$column});
-      $params = array(1 => array((string)array_shift($values), 'String'),
+      $params = array(
+        1 => array((string) array_shift($values), 'String'),
         2 => array($dao->id, 'Integer'),
       );
       CRM_Core_DAO::executeQuery($updateSql, $params);
@@ -304,7 +308,7 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
    *
    * @return array
    */
-  static function explode($str) {
+  public static function explode($str) {
     if (empty($str) || $str == CRM_Core_DAO::VALUE_SEPARATOR . CRM_Core_DAO::VALUE_SEPARATOR) {
       return array();
     }
@@ -313,4 +317,3 @@ class CRM_Custom_Form_ChangeFieldType extends CRM_Core_Form {
     }
   }
 }
-