INFRA-132 - Batch #7
[civicrm-core.git] / CRM / Profile / Selector / Listings.php
index 5f366043c0243ef88176884bd14ee49bd6bd218c..9a48e63a7becfe30b9354456dd6e43ff5ce4af1d 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -45,7 +45,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * Array of supported links, currenly view and edit
    *
    * @var array
-   * @static
    */
   static $_links = NULL;
 
@@ -53,7 +52,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * We use desc to remind us what that column is, name is used in the tpl
    *
    * @var array
-   * @static
    */
   static $_columnHeaders;
 
@@ -61,7 +59,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * The sql params we use to get the list of contacts
    *
    * @var string
-   * @access protected
    */
   protected $_params;
 
@@ -69,7 +66,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * The public visible fields to be shown to the user
    *
    * @var array
-   * @access protected
    */
   protected $_fields;
 
@@ -77,7 +73,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * The custom fields for this domain
    *
    * @var array
-   * @access protected
    */
   protected $_customFields;
 
@@ -85,7 +80,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * Cache the query object
    *
    * @var object
-   * @access protected
    */
   protected $_query;
 
@@ -93,7 +87,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * Cache the expanded options list if any
    *
    * @var object
-   * @access protected
    */
   protected $_options;
 
@@ -136,18 +129,16 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
   /**
    * Class constructor
    *
-   * @param array $params
-   * @param $customFields
-   * @param string params the params for the where clause
-   *
+   * @param array $params the params for the where clause
+   * @param array $customFields
+   * @param array $ufGroupIds
    * @param bool $map
    * @param bool $editLink
    * @param bool $linkToUF
    *
    * @return \CRM_Profile_Selector_Listings
-  @access public
    */
-  function __construct(
+  public function __construct(
     &$params,
     &$customFields,
     $ufGroupIds = NULL,
@@ -166,7 +157,7 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
       $this->_gid = $ufGroupIds;
     }
 
-    $this->_map      = $map;
+    $this->_map = $map;
     $this->_editLink = $editLink;
     $this->_linkToUF = $linkToUF;
 
@@ -200,8 +191,8 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
     $returnProperties['contact_sub_type'] = 1;
     $returnProperties['sort_name'] = 1;
 
-    $queryParams    = CRM_Contact_BAO_Query::convertFormValues($this->_params, 1);
-    $this->_query   = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $this->_fields);
+    $queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_params, 1);
+    $this->_query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, $this->_fields);
 
     //the below is done for query building for multirecord custom field listing
     //to show all the custom field multi valued records of a particular contact
@@ -219,9 +210,8 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * @param null $gids
    *
    * @return array
-   * @access public
    */
-  static function &links($map = FALSE, $editLink = FALSE, $ufLink = FALSE, $gids = NULL) {
+  public static function &links($map = FALSE, $editLink = FALSE, $ufLink = FALSE, $gids = NULL) {
     if (!self::$_links) {
       self::$_links = array();
 
@@ -281,15 +271,12 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    *
    * @param $action
    * @param array $params
-   *
-   * @access public
    */
-  function getPagerParams($action, &$params) {
-    $status =
-      CRM_Utils_System::isNull($this->_multiRecordTableName) ? ts('Contact %%StatusMessage%%') : ts('Contact Multi Records %%StatusMessage%%');
-    $params['status']    = $status;
+  public function getPagerParams($action, &$params) {
+    $status = CRM_Utils_System::isNull($this->_multiRecordTableName) ? ts('Contact %%StatusMessage%%') : ts('Contact Multi Records %%StatusMessage%%');
+    $params['status'] = $status;
     $params['csvString'] = NULL;
-    $params['rowCount']  = CRM_Utils_Pager::ROWCOUNT;
+    $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
 
     $params['buttonTop'] = 'PagerTopButton';
     $params['buttonBottom'] = 'PagerBottomButton';
@@ -299,19 +286,22 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * Returns the column headers as an array of tuples:
    * (name, sortName (key to the sort array))
    *
-   * @param string $action the action being performed
-   * @param enum   $output what should the result set include (web/email/csv)
+   * @param string $action
+   *   The action being performed.
+   * @param string $output
+   *   What should the result set include (web/email/csv).
    *
-   * @return array the column headers that need to be displayed
-   * @access public
+   * @return array
+   *   the column headers that need to be displayed
    */
-  function &getColumnHeaders($action = NULL, $output = NULL) {
+  public function &getColumnHeaders($action = NULL, $output = NULL) {
     static $skipFields = array('group', 'tag');
     $multipleFields = array('url');
-    $direction      = CRM_Utils_Sort::ASCENDING;
-    $empty          = TRUE;
+    $direction = CRM_Utils_Sort::ASCENDING;
+    $empty = TRUE;
     if (!isset(self::$_columnHeaders)) {
-      self::$_columnHeaders = array(array('name' => ''),
+      self::$_columnHeaders = array(
+        array('name' => ''),
         array(
           'name' => ts('Name'),
           'sort' => 'sort_name',
@@ -333,10 +323,10 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
         ) {
 
           if (strpos($name, '-') !== FALSE) {
-            $value     = explode('-', $name);
+            $value = explode('-', $name);
             $fieldName = CRM_Utils_Array::value(0, $value);
-            $lType     = CRM_Utils_Array::value(1, $value);
-            $type      = CRM_Utils_Array::value(2, $value);
+            $lType = CRM_Utils_Array::value(1, $value);
+            $type = CRM_Utils_Array::value(2, $value);
 
             if (!in_array($fieldName, $multipleFields)) {
               if ($lType == 'Primary') {
@@ -347,7 +337,10 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
               }
 
               if (in_array($fieldName, array(
-                'phone', 'im', 'email'))) {
+                'phone',
+                'im',
+                'email',
+              ))) {
                 if ($type) {
                   $name = "`$locationTypeName-$fieldName-$type`";
                 }
@@ -393,16 +386,17 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    *
    * @param
    *
-   * @return int Total number of rows
-   * @access public
+   * @return int
+   *   Total number of rows
    */
-  function getTotalCount($action) {
+  public function getTotalCount($action) {
     $additionalWhereClause = 'contact_a.is_deleted = 0';
     $additionalFromClause = NULL;
     $returnQuery = NULL;
 
     if ($this->_multiRecordTableName &&
-        !array_key_exists($this->_multiRecordTableName, $this->_query->_whereTables)) {
+      !array_key_exists($this->_multiRecordTableName, $this->_query->_whereTables)
+    ) {
       $additionalFromClause = CRM_Utils_Array::value($this->_multiRecordTableName, $this->_query->_tables);
       $returnQuery = TRUE;
     }
@@ -425,24 +419,29 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    * Return the qill for this selector
    *
    * @return string
-   * @access public
    */
-  function getQill() {
+  public function getQill() {
     return $this->_query->qill();
   }
 
   /**
    * Returns all the rows in the given offset and rowCount
    *
-   * @param enum   $action   the action being performed
-   * @param int    $offset   the row number to start from
-   * @param int    $rowCount the number of rows to return
-   * @param string $sort     the sql string that describes the sort order
-   * @param enum   $output   what should the result set include (web/email/csv)
+   * @param string $action
+   *   The action being performed.
+   * @param int $offset
+   *   The row number to start from.
+   * @param int $rowCount
+   *   The number of rows to return.
+   * @param string $sort
+   *   The sql string that describes the sort order.
+   * @param string $output
+   *   What should the result set include (web/email/csv).
    *
-   * @return int   the total number of rows for this action
+   * @return int
+   *   the total number of rows for this action
    */
-  function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $extraWhereClause = NULL) {
+  public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $extraWhereClause = NULL) {
 
     $multipleFields = array('url');
     //$sort object processing for location fields
@@ -450,9 +449,9 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
       $vars = $sort->_vars;
       $varArray = array();
       foreach ($vars as $key => $field) {
-        $field      = $vars[$key];
+        $field = $vars[$key];
         $fieldArray = explode('-', $field['name']);
-        $fieldType  = CRM_Utils_Array::value('2', $fieldArray);
+        $fieldType = CRM_Utils_Array::value('2', $fieldArray);
         if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) {
           if (!in_array($fieldType, $multipleFields)) {
             $locationType = new CRM_Core_DAO_LocationType();
@@ -491,7 +490,7 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
 
     if ($returnQuery) {
       $resQuery = preg_replace('/GROUP BY contact_a.id[\s]+ORDER BY/', ' ORDER BY', $result);
-      $result   = CRM_Core_DAO::executeQuery($resQuery);
+      $result = CRM_Core_DAO::executeQuery($resQuery);
     }
 
     // process the result of the query
@@ -528,10 +527,10 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
         !in_array($key, $skipFields)
       ) {
         if (strpos($key, '-') !== FALSE) {
-          $value     = explode('-', $key);
+          $value = explode('-', $key);
           $fieldName = CRM_Utils_Array::value(0, $value);
-          $id        = CRM_Utils_Array::value(1, $value);
-          $type      = CRM_Utils_Array::value(2, $value);
+          $id = CRM_Utils_Array::value(1, $value);
+          $type = CRM_Utils_Array::value(2, $value);
 
           if (!in_array($fieldName, $multipleFields)) {
             $locationTypeName = NULL;
@@ -549,7 +548,10 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
             }
             $locationTypeName = str_replace(' ', '_', $locationTypeName);
             if (in_array($fieldName, array(
-              'phone', 'im', 'email'))) {
+              'phone',
+              'im',
+              'email',
+            ))) {
               if ($type) {
                 $names[] = "{$locationTypeName}-{$fieldName}-{$type}";
               }
@@ -574,7 +576,6 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
       }
     }
 
-
     $multipleSelectFields = array('preferred_communication_method' => 1);
     $multiRecordTableId = NULL;
     if ($this->_multiRecordTableName) {
@@ -592,10 +593,9 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
         $i18n = CRM_Core_I18n::singleton();
         $result->country = $i18n->translate($result->country);
       }
-      $row   = array();
+      $row = array();
       $empty = TRUE;
-      $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ?
-        $result->contact_sub_type : $result->contact_type,
+      $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type,
         FALSE,
         $result->contact_id,
         $showProfileOverlay
@@ -619,8 +619,8 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
         elseif (substr($name, -4) == '-url' &&
           !empty($result->$name)
         ) {
-          $url      = CRM_Utils_System::fixURL($result->$name);
-          $typeId   = substr($name, 0, -4) . "-website_type_id";
+          $url = CRM_Utils_System::fixURL($result->$name);
+          $typeId = substr($name, 0, -4) . "-website_type_id";
           $typeName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_Website', 'website_type_id', $result->$typeId);
           if ($typeName) {
             $row[] = "<a href=\"$url\">{$result->$name} (${typeName})</a>";
@@ -643,9 +643,9 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
         }
         elseif (strpos($name, '-im')) {
           if (!empty($result->$name)) {
-            $providerId   = $name . "-provider_id";
+            $providerId = $name . "-provider_id";
             $providerName = CRM_Core_PseudoConstant::getLabel('CRM_Core_DAO_IM', 'provider_id', $result->$providerId);
-            $row[]        = $result->$name . " ({$providerName})";
+            $row[] = $result->$name . " ({$providerName})";
           }
           else {
             $row[] = '';
@@ -661,12 +661,17 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
           }
         }
         elseif (in_array($name, array(
-          'addressee', 'email_greeting', 'postal_greeting'))) {
+          'addressee',
+          'email_greeting',
+          'postal_greeting',
+        ))) {
           $dname = $name . '_display';
           $row[] = $result->$dname;
         }
         elseif (in_array($name, array(
-          'birth_date', 'deceased_date'))) {
+          'birth_date',
+          'deceased_date',
+        ))) {
           $row[] = CRM_Utils_Date::customFormat($result->$name);
         }
         elseif (isset($result->$name)) {
@@ -689,7 +694,7 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
 
       // pass record id param to view url for multi record view
       if ($multiRecordTableId && $newLinks) {
-        if ($result->$multiRecordTableId){
+        if ($result->$multiRecordTableId) {
           if ($newLinks[CRM_Core_Action::VIEW]['url'] == 'civicrm/profile/view') {
             $newLinks[CRM_Core_Action::VIEW]['qs'] .= "&multiRecord=view&recordId=%%recordId%%&allFields=1";
             $params['recordId'] = $result->$multiRecordTableId;
@@ -727,11 +732,13 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
   /**
    * Name of export file.
    *
-   * @param string $output type of output
+   * @param string $output
+   *   Type of output.
    *
-   * @return string name of the file
+   * @return string
+   *   name of the file
    */
-  function getExportFileName($output = 'csv') {
+  public function getExportFileName($output = 'csv') {
     return ts('CiviCRM Profile Listings');
   }
 
@@ -739,9 +746,9 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
    *  set the _multiRecordTableName to display the result set
    *  according to multi record custom field values
    */
-  function setMultiRecordTableName($fields) {
-   $customGroupId = $multiRecordTableName = NULL;
-   $selectorSet = FALSE;
+  public function setMultiRecordTableName($fields) {
+    $customGroupId = $multiRecordTableName = NULL;
+    $selectorSet = FALSE;
 
     foreach ($fields as $field => $properties) {
       if (!CRM_Core_BAO_CustomField::getKeyID($field)) {
@@ -762,10 +769,10 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
           }
 
           if ($isSubmitted) {
-            $this->_multiRecordTableName = $multiRecordTableName =
-              CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name');
+            $this->_multiRecordTableName
+              = $multiRecordTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name');
             if ($multiRecordTableName) {
-              return;
+              return NULL;
             }
           }
 
@@ -777,15 +784,14 @@ class CRM_Profile_Selector_Listings extends CRM_Core_Selector_Base implements CR
     }
 
     if (!isset($customGroupId) || !$customGroupId) {
-      return;
+      return NULL;
     }
 
     //if the field is in selector and not a searchable field
     //get the proper customvalue table name
     if ($selectorSet) {
-      $this->_multiRecordTableName = $multiRecordTableName =
-        CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name');
+      $this->_multiRecordTableName
+        = $multiRecordTableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name');
     }
   } //func close
 }
-