INFRA-132 - Remove white space after an opening "(" or before a closing ")"
[civicrm-core.git] / CRM / Profile / Page / MultipleRecordFieldsListing.php
index 5327bf5ef49f98cf7a26c1df3f44ce28cad08694..00ad9c2876c7e9a8006849e31836ff92b6d68c54 100644 (file)
@@ -59,7 +59,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    *
    * @return string Classname of BAO.
    */
-  function getBAOName() {
+  public function getBAOName() {
     return '';
   }
 
@@ -68,7 +68,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    *
    * @return array (reference) of action links
    */
-  function &links() {
+  public function &links() {
     if (!(self::$_links[$this->_pageViewType])) {
       // helper variable for nicer formatting
       $links = array();
@@ -80,17 +80,17 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
       // names and titles
       $links[CRM_Core_Action::VIEW] = array(
         'name' => ts('View'),
-        'title' => ts('View %1', array( 1 => $this->_customGroupTitle . ' record')),
+        'title' => ts('View %1', array(1 => $this->_customGroupTitle . ' record')),
       );
 
       $links[CRM_Core_Action::UPDATE] = array(
         'name' => ts('Edit'),
-        'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle . ' record')),
+        'title' => ts('Edit %1', array(1 => $this->_customGroupTitle . ' record')),
       );
 
       $links[CRM_Core_Action::DELETE] = array(
         'name' => ts('Delete'),
-        'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle . ' record')),
+        'title' => ts('Delete %1', array(1 => $this->_customGroupTitle . ' record')),
       );
 
       // urls and queryStrings
@@ -118,7 +118,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
         // copy action
         $links[CRM_Core_Action::COPY] = array(
           'name' => ts('Copy'),
-          'title' => ts('Copy %1', array( 1 => $this->_customGroupTitle . ' record')),
+          'title' => ts('Copy %1', array(1 => $this->_customGroupTitle . ' record')),
           'url' => 'civicrm/contact/view/cd/edit',
           'qs' => 'reset=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%newCgCount%%&multiRecordDisplay=single&copyValueId=%%cgcount%%&mode=copy'
         );
@@ -137,10 +137,9 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    * method.
    *
    * @return void
-   * @access public
    *
    */
-  function run() {
+  public function run() {
     // get the requested action, default to 'browse'
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, FALSE);
 
@@ -168,9 +167,8 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    * Browse the listing
    *
    * @return void
-   * @access public
    */
-  function browse() {
+  public function browse() {
     $dateFields = NULL;
     $cgcount = 0;
     $dateFieldsVals = NULL;
@@ -182,7 +180,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
         NULL,
         CRM_Core_Permission::EDIT
       );
-      $multiRecordFields = array( );
+      $multiRecordFields = array();
       $fieldIDs = NULL;
       $result = NULL;
       $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
@@ -221,12 +219,12 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
       $this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
     }
     if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
-      $options = array( );
-      $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
+      $options = array();
+      $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format', 'default_value', 'is_required');
       foreach ($fieldIDs as $key => $fieldID) {
         $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
         $param = array('id' => $fieldIDs[$key]);
-        $returnValues = array( );
+        $returnValues = array();
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
         if ($returnValues['data_type'] == 'Date') {
           $dateFields[$fieldIDs[$key]] = 1;
@@ -241,6 +239,8 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
 
         $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
         $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
+        $options[$fieldIDs[$key]]['attributes']['is_required'] = !empty($returnValues['is_required']);
+        $options[$fieldIDs[$key]]['attributes']['default_value'] = CRM_Utils_Array::value('default_value', $returnValues);
 
         $options[$fieldIDs[$key]]['attributes']['format'] =
           $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
@@ -298,13 +298,53 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
                 // assign to $result
                 $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
               }
-              if (!$customValue) {
+              // FIXME: getDisplayValue should always return a string so why is this necessary?
+              if (!$customValue && $customValue !== '0') {
                 $customValue = "";
               }
 
+              // Set field attributes to support crmEditable
+              // Note that $fieldAttributes[data-type] actually refers to the html type not the sql data type
+              // TODO: Not all widget types and validation rules are supported by crmEditable so some fields will not be in-place editable
+              $fieldAttributes = array('class' => "crmf-custom_{$fieldId}_$recId");
+              $editable = FALSE;
+              if ($linkAction & CRM_Core_Action::UPDATE) {
+                $spec = $options[$fieldId]['attributes'];
+                switch ($spec['html_type']) {
+                  case 'Text':
+                    // Other data types like money would require some extra validation
+                    // FIXME: crmEditable currently does not support any validation rules :(
+                    $supportedDataTypes = array('Float', 'String', 'Int');
+                    $editable = in_array($spec['data_type'], $supportedDataTypes);
+                    break;
+
+                  case 'TextArea':
+                    $editable = TRUE;
+                    $fieldAttributes['data-type'] = 'textarea';
+                    break;
+
+                  case 'Radio':
+                  case 'Select':
+                  case 'Select Country':
+                  case 'Select State/Province':
+                    $editable = TRUE;
+                    $fieldAttributes['data-type'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select';
+                    if (!$spec['is_required']) {
+                      $fieldAttributes['data-empty-option'] = ts('- none -');
+                    }
+                    break;
+                }
+              }
+              if ($editable) {
+                $fieldAttributes['class'] .= ' crm-editable';
+              }
+              $attributes[$fieldId][$recId] = $fieldAttributes;
+
               $op = NULL;
               if ($this->_pageViewType == 'profileDataView') {
-                $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId,
+                $actionParams = array(
+                'recordId' => $recId,
+                'gid' => $this->_profileId,
                   'id' => $this->_contactId);
                 $op = 'profile.multiValue.row';
               }
@@ -349,18 +389,19 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
       }
     }
 
-    $headers = array(  );
+    $headers = array();
     if (!empty($fieldIDs)) {
       foreach ($fieldIDs as $fieldID) {
         $headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
       }
     }
     $this->assign('dateFields', $dateFields);
-    $this->assign('dateFieldsVals',$dateFieldsVals);
+    $this->assign('dateFieldsVals', $dateFieldsVals);
     $this->assign('cgcount', $cgcount);
     $this->assign('customGroupTitle', $this->_customGroupTitle);
     $this->assign('headers', $headers);
     $this->assign('records', $result);
+    $this->assign('attributes', $attributes);
   }
 
   /**
@@ -368,7 +409,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    *
    * @return string  classname of edit form
    */
-  function editForm() {
+  public function editForm() {
     return '';
   }
 
@@ -377,7 +418,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    *
    * @return string  name of this page
    */
-  function editName() {
+  public function editName() {
     return '';
   }
 
@@ -388,8 +429,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
    *
    * @return string  user context
    */
-  function userContext($mode = NULL) {
+  public function userContext($mode = NULL) {
     return '';
   }
 }
-