Merge pull request #4913 from colemanw/INFRA-132
[civicrm-core.git] / CRM / Event / Selector / Search.php
index 30f036211d962eef340cbfb9c3d391b0ae805081..15c618b55798902cc92503741dd1d6c08367144e 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -45,22 +45,19 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
    * This defines two actions- View and Edit.
    *
    * @var array
-   * @static
    */
   static $_links = NULL;
 
   /**
-   * we use desc to remind us what that column is, name is used in the tpl
+   * We use desc to remind us what that column is, name is used in the tpl
    *
    * @var array
-   * @static
    */
   static $_columnHeaders;
 
   /**
    * Properties of contact we're interested in displaying
    * @var array
-   * @static
    */
   static $_properties = array(
     'contact_id',
@@ -86,51 +83,45 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
   );
 
   /**
-   * are we restricting ourselves to a single contact
+   * Are we restricting ourselves to a single contact
    *
-   * @access protected
    * @var boolean
    */
   protected $_single = FALSE;
 
   /**
-   * are we restricting ourselves to a single contact
+   * Are we restricting ourselves to a single contact
    *
-   * @access protected
    * @var boolean
    */
   protected $_limit = NULL;
 
   /**
-   * what context are we being invoked from
+   * What context are we being invoked from
    *
-   * @access protected
    * @var string
    */
   protected $_context = NULL;
 
   /**
-   * what component context are we being invoked from
+   * What component context are we being invoked from
    *
-   * @access protected
    * @var string
    */
   protected $_compContext = NULL;
 
   /**
-   * queryParams is the array returned by exportValues called on
+   * QueryParams is the array returned by exportValues called on
    * the HTML_QuickForm_Controller for that page.
    *
    * @var array
-   * @access protected
    */
   public $_queryParams;
 
   /**
-   * represent the type of selector
+   * Represent the type of selector
    *
    * @var int
-   * @access protected
    */
   protected $_action;
 
@@ -151,29 +142,37 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
   /**
    * Class constructor
    *
-   * @param array   $queryParams array of parameters for query
-   * @param int     $action - action of search basic or advanced.
-   * @param string  $eventClause if the caller wants to further restrict the search (used in participations)
-   * @param boolean $single are we dealing only with one contact?
-   * @param int     $limit  how many participations do we want returned
+   * @param array $queryParams
+   *   Array of parameters for query.
+   * @param \const|int $action - action of search basic or advanced.
+   * @param string $eventClause
+   *   If the caller wants to further restrict the search (used in participations).
+   * @param bool $single
+   *   Are we dealing only with one contact?.
+   * @param int $limit
+   *   How many participations do we want returned.
    *
-   * @return CRM_Contact_Selector
+   * @param string $context
+   * @param null $compContext
+   *
+   * @return \CRM_Event_Selector_Search
    * @access public
    */
-  function __construct(&$queryParams,
-    $action      = CRM_Core_Action::NONE,
+  function __construct(
+    &$queryParams,
+    $action = CRM_Core_Action::NONE,
     $eventClause = NULL,
-    $single      = FALSE,
-    $limit       = NULL,
-    $context     = 'search',
+    $single = FALSE,
+    $limit = NULL,
+    $context = 'search',
     $compContext = NULL
   ) {
     // submitted form values
     $this->_queryParams = &$queryParams;
 
-    $this->_single      = $single;
-    $this->_limit       = $limit;
-    $this->_context     = $context;
+    $this->_single = $single;
+    $this->_limit = $limit;
+    $this->_context = $context;
     $this->_compContext = $compContext;
 
     $this->_eventClause = $eventClause;
@@ -191,16 +190,14 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
     $this->_query->_distinctComponentClause = " civicrm_participant.id";
     $this->_query->_groupByComponentClause = " GROUP BY civicrm_participant.id ";
   }
-  //end of constructor
 
   /**
    * Can be used to alter the number of participation returned from a buildForm hook
    *
-   * @param int     $limit  how many participations do we want returned
-   * @access public
-   *
+   * @param int $limit
+   *   How many participations do we want returned.
    */
-  function setLimit($limit) {
+  public function setLimit($limit) {
     $this->_limit = $limit;
   }
 
@@ -211,11 +208,13 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
    * - View
    * - Edit
    *
-   * @return array
-   * @access public
+   * @param null $qfKey
+   * @param null $context
+   * @param null $compContext
    *
+   * @return array
    */
-  static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
+  public static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
     $extraParams = NULL;
     if ($compContext) {
       $extraParams .= "&compContext={$compContext}";
@@ -228,7 +227,6 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
       $extraParams .= "&key={$qfKey}";
     }
 
-
     if (!(self::$_links)) {
       self::$_links = array(
         CRM_Core_Action::VIEW => array(
@@ -253,15 +251,14 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
     }
     return self::$_links;
   }
-  //end of function
 
   /**
-   * getter for array of the parameters required for creating pager.
+   * Getter for array of the parameters required for creating pager.
    *
-   * @param
-   * @access public
+   * @param $action
+   * @param array $params
    */
-  function getPagerParams($action, &$params) {
+  public function getPagerParams($action, &$params) {
     $params['status'] = ts('Event') . ' %%StatusMessage%%';
     $params['csvString'] = NULL;
     if ($this->_limit) {
@@ -274,17 +271,16 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
     $params['buttonTop'] = 'PagerTopButton';
     $params['buttonBottom'] = 'PagerBottomButton';
   }
-  //end of function
 
   /**
    * Returns total number of rows for the query.
    *
    * @param
    *
-   * @return int Total number of rows
-   * @access public
+   * @return int
+   *   Total number of rows
    */
-  function getTotalCount($action) {
+  public function getTotalCount($action) {
     return $this->_query->searchQuery(0, 0, NULL,
       TRUE, FALSE,
       FALSE, FALSE,
@@ -294,17 +290,23 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
   }
 
   /**
-   * returns all the rows in the given offset and rowCount
+   * 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 array  rows in the given offset and rowCount
+   * @return array
+   *   rows in the given offset and rowCount
    */
-  function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
+  public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort,
       FALSE, FALSE,
       FALSE, FALSE,
@@ -324,10 +326,10 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
     }
     $mask = CRM_Core_Action::mask($permissions);
 
-    $statusTypes      = CRM_Event_PseudoConstant::participantStatus();
-    $statusClasses    = CRM_Event_PseudoConstant::participantStatusClass();
+    $statusTypes = CRM_Event_PseudoConstant::participantStatus();
+    $statusClasses = CRM_Event_PseudoConstant::participantStatusClass();
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
-    $sep              = CRM_Core_DAO::VALUE_SEPARATOR;
+    $sep = CRM_Core_DAO::VALUE_SEPARATOR;
 
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
@@ -355,7 +357,7 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
 
       $row['showConfirmUrl'] = ($statusClass == 'Pending') ? TRUE : FALSE;
 
-      if (CRM_Utils_Array::value('participant_is_test', $row)) {
+      if (!empty($row['participant_is_test'])) {
         $row['participant_status'] .= ' (' . ts('test') . ')';
       }
 
@@ -365,12 +367,21 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
       if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
         $links[CRM_Core_Action::ADD] = array(
           'name' => ts('Record Payment'),
-          'url' => 'civicrm/payment/add',
+          'url' => 'civicrm/payment',
           'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
           'title' => ts('Record Payment'),
         );
       }
 
+      if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
+        $links[CRM_Core_Action::ADD] = array(
+          'name' => ts('Record Refund'),
+          'url' => 'civicrm/payment',
+          'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
+          'title' => ts('Record Refund'),
+        );
+      }
+
       $row['action'] = CRM_Core_Action::formLink($links,
         $mask,
         array(
@@ -385,14 +396,12 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
         $result->participant_id
       );
 
-
-      $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ?
-        $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id
+      $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id
       );
 
       $row['paid'] = CRM_Event_BAO_Event::isMonetary($row['event_id']);
 
-      if (CRM_Utils_Array::value('participant_fee_level', $row)) {
+      if (!empty($row['participant_fee_level'])) {
         CRM_Event_BAO_Participant::fixEventLevel($row['participant_fee_level']);
       }
 
@@ -416,42 +425,40 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
   }
 
   /**
-   *
-   * @return array              $qill         which contains an array of strings
-   * @access public
+   * @inheritDoc
    */
-
-  // the current internationalisation is bad, but should more or less work
-  // for most of "European" languages
   public function getQILL() {
     return $this->_query->qill();
   }
 
   /**
-   * returns the column headers as an array of tuples:
+   * 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
    */
   public function &getColumnHeaders($action = NULL, $output = NULL) {
     if (!isset(self::$_columnHeaders)) {
       self::$_columnHeaders = array(
-        array('name' => ts('Event'),
+        array(
+          'name' => ts('Event'),
           'sort' => 'event_title',
           'direction' => CRM_Utils_Sort::DONTCARE,
         ),
         array(
           'name' => ts('Fee Level'),
-          'sort' => 'fee_level',
+          'sort' => 'participant_fee_level',
           'direction' => CRM_Utils_Sort::DONTCARE,
         ),
         array(
           'name' => ts('Amount'),
-          'sort' => 'fee_amount',
+          'sort' => 'participant_fee_amount',
           'direction' => CRM_Utils_Sort::DONTCARE,
         ),
         array(
@@ -492,24 +499,30 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
     return self::$_columnHeaders;
   }
 
-  function alphabetQuery() {
+  /**
+   * @return mixed
+   */
+  public function alphabetQuery() {
     return $this->_query->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
   }
 
-  function &getQuery() {
+  /**
+   * @return string
+   */
+  public function &getQuery() {
     return $this->_query;
   }
 
   /**
-   * name of export file.
+   * 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 Event Search');
   }
 }
-//end of class
-