3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class is used to retrieve and display a range of
38 * contacts that match the given criteria (specifically for
39 * results of advanced search options.
42 class CRM_Event_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
45 * This defines two actions- View and Edit.
50 static $_links = NULL;
53 * We use desc to remind us what that column is, name is used in the tpl
58 static $_columnHeaders;
61 * Properties of contact we're interested in displaying
65 static $_properties = array(
70 'participant_status_id',
72 'participant_fee_level',
78 'participant_is_test',
79 'participant_role_id',
80 'participant_register_date',
81 'participant_fee_amount',
82 'participant_fee_currency',
85 'participant_campaign_id',
89 * Are we restricting ourselves to a single contact
93 protected $_single = FALSE;
96 * Are we restricting ourselves to a single contact
100 protected $_limit = NULL;
103 * What context are we being invoked from
107 protected $_context = NULL;
110 * What component context are we being invoked from
114 protected $_compContext = NULL;
117 * QueryParams is the array returned by exportValues called on
118 * the HTML_QuickForm_Controller for that page.
122 public $_queryParams;
125 * Represent the type of selector
132 * The additional clause that we restrict the search with
136 protected $_eventClause = NULL;
148 * @param array $queryParams array of parameters for query
149 * @param \const|int $action - action of search basic or advanced.
150 * @param string $eventClause if the caller wants to further restrict the search (used in participations)
151 * @param boolean $single are we dealing only with one contact?
152 * @param int $limit how many participations do we want returned
154 * @param string $context
155 * @param null $compContext
157 * @return \CRM_Event_Selector_Search
160 function __construct(&$queryParams,
161 $action = CRM_Core_Action
::NONE
,
168 // submitted form values
169 $this->_queryParams
= &$queryParams;
171 $this->_single
= $single;
172 $this->_limit
= $limit;
173 $this->_context
= $context;
174 $this->_compContext
= $compContext;
176 $this->_eventClause
= $eventClause;
179 $this->_action
= $action;
181 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
182 CRM_Event_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_EVENT
,
186 CRM_Contact_BAO_Query
::MODE_EVENT
188 $this->_query
->_distinctComponentClause
= " civicrm_participant.id";
189 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
193 * Can be used to alter the number of participation returned from a buildForm hook
195 * @param int $limit how many participations do we want returned
198 public function setLimit($limit) {
199 $this->_limit
= $limit;
203 * This method returns the links that are given for each search row.
204 * currently the links added for each row are
210 * @param null $context
211 * @param null $compContext
215 public static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
218 $extraParams .= "&compContext={$compContext}";
220 elseif ($context == 'search') {
221 $extraParams .= '&compContext=participant';
225 $extraParams .= "&key={$qfKey}";
229 if (!(self
::$_links)) {
230 self
::$_links = array(
231 CRM_Core_Action
::VIEW
=> array(
232 'name' => ts('View'),
233 'url' => 'civicrm/contact/view/participant',
234 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=event' . $extraParams,
235 'title' => ts('View Participation'),
237 CRM_Core_Action
::UPDATE
=> array(
238 'name' => ts('Edit'),
239 'url' => 'civicrm/contact/view/participant',
240 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
241 'title' => ts('Edit Participation'),
243 CRM_Core_Action
::DELETE
=> array(
244 'name' => ts('Delete'),
245 'url' => 'civicrm/contact/view/participant',
246 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
247 'title' => ts('Delete Participation'),
251 return self
::$_links;
255 * Getter for array of the parameters required for creating pager.
258 * @param array $params
261 public function getPagerParams($action, &$params) {
262 $params['status'] = ts('Event') . ' %%StatusMessage%%';
263 $params['csvString'] = NULL;
265 $params['rowCount'] = $this->_limit
;
268 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
271 $params['buttonTop'] = 'PagerTopButton';
272 $params['buttonBottom'] = 'PagerBottomButton';
276 * Returns total number of rows for the query.
280 * @return int Total number of rows
282 public function getTotalCount($action) {
283 return $this->_query
->searchQuery(0, 0, NULL,
292 * Returns all the rows in the given offset and rowCount
294 * @param enum $action the action being performed
295 * @param int $offset the row number to start from
296 * @param int $rowCount the number of rows to return
297 * @param string $sort the sql string that describes the sort order
298 * @param enum $output what should the result set include (web/email/csv)
300 * @return array rows in the given offset and rowCount
302 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
303 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
309 // process the result of the query
312 //lets handle view, edit and delete separately. CRM-4418
313 $permissions = array(CRM_Core_Permission
::VIEW
);
314 if (CRM_Core_Permission
::check('edit event participants')) {
315 $permissions[] = CRM_Core_Permission
::EDIT
;
317 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
318 $permissions[] = CRM_Core_Permission
::DELETE
;
320 $mask = CRM_Core_Action
::mask($permissions);
322 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
323 $statusClasses = CRM_Event_PseudoConstant
::participantStatusClass();
324 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
325 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
328 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
330 while ($result->fetch()) {
332 // the columns we are interested in
333 foreach (self
::$_properties as $property) {
334 if (isset($result->$property)) {
335 $row[$property] = $result->$property;
339 //carry campaign on selectors.
340 $row['campaign'] = CRM_Utils_Array
::value($result->participant_campaign_id
, $allCampaigns);
341 $row['campaign_id'] = $result->participant_campaign_id
;
343 // gross hack to show extra information for pending status
345 if ((isset($row['participant_status_id'])) &&
346 ($statusId = array_search($row['participant_status_id'], $statusTypes))
348 $statusClass = $statusClasses[$statusId];
351 $row['showConfirmUrl'] = ($statusClass == 'Pending') ?
TRUE : FALSE;
353 if (!empty($row['participant_is_test'])) {
354 $row['participant_status'] .= ' (' . ts('test') . ')';
357 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->participant_id
;
358 $links = self
::links($this->_key
, $this->_context
, $this->_compContext
);
360 if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
361 $links[CRM_Core_Action
::ADD
] = array(
362 'name' => ts('Record Payment'),
363 'url' => 'civicrm/payment',
364 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
365 'title' => ts('Record Payment'),
369 if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
370 $links[CRM_Core_Action
::ADD
] = array(
371 'name' => ts('Record Refund'),
372 'url' => 'civicrm/payment',
373 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
374 'title' => ts('Record Refund'),
378 $row['action'] = CRM_Core_Action
::formLink($links,
381 'id' => $result->participant_id
,
382 'cid' => $result->contact_id
,
383 'cxt' => $this->_context
,
387 'participant.selector.row',
389 $result->participant_id
393 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
394 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
397 $row['paid'] = CRM_Event_BAO_Event
::isMonetary($row['event_id']);
399 if (!empty($row['participant_fee_level'])) {
400 CRM_Event_BAO_Participant
::fixEventLevel($row['participant_fee_level']);
403 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
404 // add line item details if applicable
405 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
408 if (!empty($row['participant_role_id'])) {
409 $viewRoles = array();
410 foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
411 $viewRoles[] = $participantRoles[$v];
413 $row['participant_role_id'] = implode(', ', $viewRoles);
417 CRM_Core_Selector_Controller
::$_template->assign_by_ref('lineItems', $lineItems);
423 * FIXME: the current internationalisation is bad, but should more or less work
424 * on most of "European" languages
426 * @return array $qill which contains an array of strings
428 public function getQILL() {
429 return $this->_query
->qill();
433 * Returns the column headers as an array of tuples:
434 * (name, sortName (key to the sort array))
436 * @param string $action the action being performed
437 * @param enum $output what should the result set include (web/email/csv)
439 * @return array the column headers that need to be displayed
441 public function &getColumnHeaders($action = NULL, $output = NULL) {
442 if (!isset(self
::$_columnHeaders)) {
443 self
::$_columnHeaders = array(
444 array('name' => ts('Event'),
445 'sort' => 'event_title',
446 'direction' => CRM_Utils_Sort
::DONTCARE
,
449 'name' => ts('Fee Level'),
450 'sort' => 'participant_fee_level',
451 'direction' => CRM_Utils_Sort
::DONTCARE
,
454 'name' => ts('Amount'),
455 'sort' => 'participant_fee_amount',
456 'direction' => CRM_Utils_Sort
::DONTCARE
,
459 'name' => ts('Registered'),
460 'sort' => 'participant_register_date',
461 'direction' => CRM_Utils_Sort
::DESCENDING
,
464 'name' => ts('Event Date(s)'),
465 'sort' => 'event_start_date',
466 'direction' => CRM_Utils_Sort
::DESCENDING
,
469 'name' => ts('Status'),
470 'sort' => 'participant_status',
471 'direction' => CRM_Utils_Sort
::DONTCARE
,
474 'name' => ts('Role'),
475 'sort' => 'participant_role_id',
476 'direction' => CRM_Utils_Sort
::DONTCARE
,
478 array('desc' => ts('Actions')),
481 if (!$this->_single
) {
483 array('desc' => ts('Contact Type')),
485 'name' => ts('Participant'),
486 'sort' => 'sort_name',
487 'direction' => CRM_Utils_Sort
::DONTCARE
,
490 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
493 return self
::$_columnHeaders;
499 public function alphabetQuery() {
500 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
506 public function &getQuery() {
507 return $this->_query
;
511 * Name of export file.
513 * @param string $output type of output
515 * @return string name of the file
517 public function getExportFileName($output = 'csv') {
518 return ts('CiviCRM Event Search');