phpcs - Fix error, "Expected 1 newline at end of file; XXX found".
[civicrm-core.git] / CRM / Profile / Form.php
index 3fcc264132554517c2e2839d797c304d8ba07ba3..c0dee2b655c79c8c05d7d89e94dbaf0f35a40b95 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -42,7 +42,7 @@
  *
  */
 class CRM_Profile_Form extends CRM_Core_Form {
-  CONST
+  const
     MODE_REGISTER = 1,
     MODE_SEARCH   = 2,
     MODE_CREATE   = 4,
@@ -91,14 +91,14 @@ class CRM_Profile_Form extends CRM_Core_Form {
   protected $_title;
 
   /**
-   * the fields needed to build this form
+   * The fields needed to build this form
    *
    * @var array
    */
   public $_fields;
 
   /**
-   * to store contact details
+   * To store contact details
    *
    * @var array
    */
@@ -157,7 +157,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
   protected $_recordId = NULL;
 
   /**
-   * action for multi record profile (create/edit/delete)
+   * Action for multi record profile (create/edit/delete)
    *
    * @var string
    */
@@ -177,7 +177,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
   protected $_session       = NULL;
 
   /**
-   * pre processing work done here.
+   * Pre processing work done here.
    *
    * gets session variables for table name, id of entity in table, type of entity and stores them.
    *
@@ -185,9 +185,8 @@ class CRM_Profile_Form extends CRM_Core_Form {
    *
    * @return void
    *
-   * @access public
    */
-  function preProcess() {
+  public function preProcess() {
     $this->_id         = $this->get('id');
     $this->_profileIds = $this->get('profileIds');
     $this->_grid       = CRM_Utils_Request::retrieve('grid', 'Integer', $this);
@@ -357,7 +356,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
 
         } elseif (!empty($this->_multiRecordFields)
            && (!$this->_multiRecord || !in_array($this->_multiRecord, array(CRM_Core_Action::DELETE, CRM_Core_Action::UPDATE)) )) {
-          CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
+          CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header');
           //multirecord listing page
           $multiRecordFieldListing = TRUE;
           $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
@@ -406,14 +405,13 @@ class CRM_Profile_Form extends CRM_Core_Form {
   }
 
   /**
-   * 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
    *
-   * @access public
    *
    * @return void
    */
-  function setDefaultsValues() {
+  public function setDefaultsValues() {
     $this->_defaults = array();
     if ($this->_multiRecordProfile && ($this->_multiRecord == CRM_Core_Action::DELETE)) {
       return;
@@ -579,10 +577,9 @@ class CRM_Profile_Form extends CRM_Core_Form {
   }
 
   /**
-   * Function to actually build the form
+   * Build the form object
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
     $this->add('hidden', 'gid', $this->_gid);
@@ -683,21 +680,6 @@ class CRM_Profile_Form extends CRM_Core_Form {
       return FALSE;
     }
 
-    if (count($this->_submitValues)) {
-      $locationTypeId = null;
-      foreach ($this->_fields as $field) {
-        if (!empty($field['location_type_id'])) {
-          $locationTypeId = $field['location_type_id'];
-        }
-        if (array_key_exists("country-{$locationTypeId}", $this->_fields) &&
-          array_key_exists("state_province-{$locationTypeId}", $this->_fields) &&
-          !empty($this->_submitValues["country-{$locationTypeId}"])) {
-          $this->_fields["state_province-{$locationTypeId}"]['is_required'] =
-            CRM_Core_Payment_Form::checkRequiredStateProvince($this, "country-{$locationTypeId}");
-        }
-      }
-    }
-
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
@@ -814,6 +796,9 @@ class CRM_Profile_Form extends CRM_Core_Form {
       }
     }
 
+    //let's do set defaults for the profile
+    $this->setDefaultsValues();
+
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
     if ($this->_mode == self::MODE_CREATE) {
       CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
@@ -838,22 +823,16 @@ class CRM_Profile_Form extends CRM_Core_Form {
     }
   }
 
-  /*
-   * Function to validate profile and provided activity Id
-   *
-   * @params Integer $activityId Activity Id
-   * @params Integer $gid        Profile Id
-   *
-   * @return Array   $errors     Errors ( if any ).
-   */
   /**
-   * @param $activityId
-   * @param $contactId
-   * @param $gid
+   * Validate profile and provided activity Id
+   *
+   * @param int $activityId
+   * @param int $contactId
+   * @param int $gid
    *
    * @return array
    */
-  static function validateContactActivityProfile($activityId, $contactId, $gid) {
+  public static function validateContactActivityProfile($activityId, $contactId, $gid) {
     $errors = array();
     if (!$activityId) {
       $errors[] = 'Profile is using one or more activity fields, and is missing the activity Id (aid) in the URL.';
@@ -885,17 +864,16 @@ class CRM_Profile_Form extends CRM_Core_Form {
   }
 
   /**
-   * global form rule
+   * Global form rule
    *
    * @param array  $fields the input form values
    * @param array  $files  the uploaded files if any
-   * @param object $form   the form object
+   * @param CRM_Core_Form $form   the form object
    *
    * @return true if no errors, else array of errors
-   * @access public
    * @static
    */
-  static function formRule($fields, $files, $form) {
+  public static function formRule($fields, $files, $form) {
     CRM_Utils_Hook::validateProfile($form->_ufGroup['name']);
 
     $errors = array();
@@ -1067,7 +1045,6 @@ class CRM_Profile_Form extends CRM_Core_Form {
   /**
    * Process the user submitted custom data values.
    *
-   * @access public
    *
    * @return void
    */
@@ -1331,7 +1308,7 @@ class CRM_Profile_Form extends CRM_Core_Form {
    *
    * @return null|string
    */
-  function checkTemplateFileExists($suffix = NULL) {
+  public function checkTemplateFileExists($suffix = NULL) {
     if ($this->_gid) {
       $templateFile = "CRM/Profile/Form/{$this->_gid}/{$this->_name}.{$suffix}tpl";
       $template = CRM_Core_Form::getTemplate();
@@ -1355,12 +1332,11 @@ class CRM_Profile_Form extends CRM_Core_Form {
    * Use the form name to create the tpl file name
    *
    * @return string
-   * @access public
    */
   /**
    * @return string
    */
-  function getTemplateFileName() {
+  public function getTemplateFileName() {
     $fileName = $this->checkTemplateFileExists();
     return $fileName ? $fileName : parent::getTemplateFileName();
   }
@@ -1370,14 +1346,12 @@ class CRM_Profile_Form extends CRM_Core_Form {
    * i.e. we dont override
    *
    * @return string
-   * @access public
    */
   /**
    * @return string
    */
-  function overrideExtraTemplateFileName() {
+  public function overrideExtraTemplateFileName() {
     $fileName = $this->checkTemplateFileExists('extra.');
     return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
   }
 }
-