INFRA-132 - Put "else" and "catch" on new line
[civicrm-core.git] / CRM / Profile / Page / Dynamic.php
index c5a5c71eb0832934b4ab1c6585b3f3045915267a..90d10a41e5d79b0338baa5c2c22893df6e05b0b7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -47,15 +47,13 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
    * The contact id of the person we are viewing
    *
    * @var int
-   * @access protected
    */
   protected $_id;
 
   /**
-   * the profile group are are interested in
+   * The profile group are are interested in
    *
    * @var int
-   * @access protected
    */
   protected $_gid;
 
@@ -63,7 +61,6 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
    * The profile types we restrict this page to display
    *
    * @var string
-   * @access protected
    */
   protected $_restrict;
 
@@ -71,7 +68,6 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
    * Should we bypass permissions
    *
    * @var boolean
-   * @access protected
    */
   protected $_skipPermission;
 
@@ -105,19 +101,20 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
   protected $_allFields = NULL;
 
   /**
-   * class constructor
+   * Class constructor
    *
-   * @param int $id the contact id
-   * @param int $gid the group id
+   * @param int $id
+   *   The contact id.
+   * @param int $gid
+   *   The group id.
    *
    * @param $restrict
    * @param bool $skipPermission
    * @param null $profileIds
    *
    * @return \CRM_Profile_Page_Dynamic
-   * @access public
    */
-  function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL) {
+  public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL) {
     parent::__construct();
 
     $this->_id = $id;
@@ -138,8 +135,7 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
     //specifies the action being done on a multi record field
     $multiRecordAction = CRM_Utils_Request::retrieve('multiRecord', 'String', $this);
 
-    $this->_multiRecord = (!is_numeric($multiRecordAction)) ?
-      CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction;
+    $this->_multiRecord = (!is_numeric($multiRecordAction)) ? CRM_Core_Action::resolve($multiRecordAction) : $multiRecordAction;
     if ($this->_multiRecord) {
       $this->set('multiRecord', $this->_multiRecord);
     }
@@ -172,7 +168,7 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
    * @return array $_actionLinks
    *
    */
-  function &actionLinks() {
+  public function &actionLinks() {
     return NULL;
   }
 
@@ -183,10 +179,9 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
    * type of action and executes that action.
    *
    * @return void
-   * @access public
    *
    */
-  function run() {
+  public function run() {
     $template = CRM_Core_Smarty::singleton();
     if ($this->_id && $this->_gid) {
 
@@ -305,7 +300,8 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
             $copyFields = $fields;
             CRM_Core_BAO_UFGroup::shiftMultiRecordFields($copyFields, $multiRecordFields);
             $fieldKey = key($multiRecordFields);
-          } else {
+          }
+          else {
             $fieldKey = key($fields);
           }
           if ($fieldID = CRM_Core_BAO_CustomField::getKeyID($fieldKey)) {
@@ -321,16 +317,18 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
       $profileFields = array();
       $labels = array();
 
-      //CRM-14338
-      $nullValueIndex = ' ';
       foreach ($fields as $name => $field) {
-        if ( isset($labels[$field['title']]) ) {
-          $labels[$field['title'].$nullValueIndex] = preg_replace('/\s+|\W+/', '_', $name);
-          $nullValueIndex .= $nullValueIndex;
+        //CRM-14338
+        // Create a unique, non-empty index for each field.
+        $index = $field['title'];
+        if ($index === '') {
+          $index = ' ';
         }
-        else {
-          $labels[$field['title']] = preg_replace('/\s+|\W+/', '_', $name);
+        while (array_key_exists($index, $labels)) {
+          $index .= ' ';
         }
+
+        $labels[$index] = preg_replace('/\s+|\W+/', '_', $name);
       }
 
       foreach ($values as $title => $value) {
@@ -357,7 +355,8 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
       $fieldId = CRM_Core_BAO_CustomField::getKeyID($fieldDetail['name']);
       $customGroupDetails = CRM_Core_BAO_CustomGroup::getGroupTitles(array($fieldId));
       $multiRecTitle = $customGroupDetails[$fieldId]['groupTitle'];
-    } else {
+    }
+    else {
       $title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
     }
 
@@ -387,7 +386,12 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
     return trim($template->fetch($this->getHookedTemplateFileName()));
   }
 
-  function checkTemplateFileExists($suffix = '') {
+  /**
+   * @param string $suffix
+   *
+   * @return null|string
+   */
+  public function checkTemplateFileExists($suffix = '') {
     if ($this->_gid) {
       $templateFile = "CRM/Profile/Page/{$this->_gid}/Dynamic.{$suffix}tpl";
       $template = CRM_Core_Page::getTemplate();
@@ -407,14 +411,30 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page {
     return NULL;
   }
 
-  function getTemplateFileName() {
+  /**
+   * Use the form name to create the tpl file name
+   *
+   * @return string
+   */
+  /**
+   * @return string
+   */
+  public function getTemplateFileName() {
     $fileName = $this->checkTemplateFileExists();
     return $fileName ? $fileName : parent::getTemplateFileName();
   }
 
-  function overrideExtraTemplateFileName() {
+  /**
+   * Default extra tpl file basically just replaces .tpl with .extra.tpl
+   * i.e. we dont override
+   *
+   * @return string
+   */
+  /**
+   * @return string
+   */
+  public function overrideExtraTemplateFileName() {
     $fileName = $this->checkTemplateFileExists('extra.');
     return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
   }
 }
-