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
149 * Array of parameters for query.
150 * @param \const|int $action - action of search basic or advanced.
151 * @param string $eventClause
152 * If the caller wants to further restrict the search (used in participations).
153 * @param bool $single
154 * Are we dealing only with one contact?.
156 * How many participations do we want returned.
158 * @param string $context
159 * @param null $compContext
161 * @return \CRM_Event_Selector_Search
164 function __construct(
166 $action = CRM_Core_Action
::NONE
,
173 // submitted form values
174 $this->_queryParams
= &$queryParams;
176 $this->_single
= $single;
177 $this->_limit
= $limit;
178 $this->_context
= $context;
179 $this->_compContext
= $compContext;
181 $this->_eventClause
= $eventClause;
184 $this->_action
= $action;
186 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
187 CRM_Event_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_EVENT
,
191 CRM_Contact_BAO_Query
::MODE_EVENT
193 $this->_query
->_distinctComponentClause
= " civicrm_participant.id";
194 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
198 * Can be used to alter the number of participation returned from a buildForm hook
201 * How many participations do we want returned.
203 public function setLimit($limit) {
204 $this->_limit
= $limit;
208 * This method returns the links that are given for each search row.
209 * currently the links added for each row are
215 * @param null $context
216 * @param null $compContext
220 public static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
223 $extraParams .= "&compContext={$compContext}";
225 elseif ($context == 'search') {
226 $extraParams .= '&compContext=participant';
230 $extraParams .= "&key={$qfKey}";
233 if (!(self
::$_links)) {
234 self
::$_links = array(
235 CRM_Core_Action
::VIEW
=> array(
236 'name' => ts('View'),
237 'url' => 'civicrm/contact/view/participant',
238 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=event' . $extraParams,
239 'title' => ts('View Participation'),
241 CRM_Core_Action
::UPDATE
=> array(
242 'name' => ts('Edit'),
243 'url' => 'civicrm/contact/view/participant',
244 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
245 'title' => ts('Edit Participation'),
247 CRM_Core_Action
::DELETE
=> array(
248 'name' => ts('Delete'),
249 'url' => 'civicrm/contact/view/participant',
250 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
251 'title' => ts('Delete Participation'),
255 return self
::$_links;
259 * Getter for array of the parameters required for creating pager.
262 * @param array $params
264 public function getPagerParams($action, &$params) {
265 $params['status'] = ts('Event') . ' %%StatusMessage%%';
266 $params['csvString'] = NULL;
268 $params['rowCount'] = $this->_limit
;
271 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
274 $params['buttonTop'] = 'PagerTopButton';
275 $params['buttonBottom'] = 'PagerBottomButton';
279 * Returns total number of rows for the query.
284 * Total number of rows
286 public function getTotalCount($action) {
287 return $this->_query
->searchQuery(0, 0, NULL,
296 * Returns all the rows in the given offset and rowCount
298 * @param string $action
299 * The action being performed.
301 * The row number to start from.
302 * @param int $rowCount
303 * The number of rows to return.
304 * @param string $sort
305 * The sql string that describes the sort order.
306 * @param string $output
307 * What should the result set include (web/email/csv).
310 * rows in the given offset and rowCount
312 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
313 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
319 // process the result of the query
322 //lets handle view, edit and delete separately. CRM-4418
323 $permissions = array(CRM_Core_Permission
::VIEW
);
324 if (CRM_Core_Permission
::check('edit event participants')) {
325 $permissions[] = CRM_Core_Permission
::EDIT
;
327 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
328 $permissions[] = CRM_Core_Permission
::DELETE
;
330 $mask = CRM_Core_Action
::mask($permissions);
332 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
333 $statusClasses = CRM_Event_PseudoConstant
::participantStatusClass();
334 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
335 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
338 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
340 while ($result->fetch()) {
342 // the columns we are interested in
343 foreach (self
::$_properties as $property) {
344 if (isset($result->$property)) {
345 $row[$property] = $result->$property;
349 //carry campaign on selectors.
350 $row['campaign'] = CRM_Utils_Array
::value($result->participant_campaign_id
, $allCampaigns);
351 $row['campaign_id'] = $result->participant_campaign_id
;
353 // gross hack to show extra information for pending status
355 if ((isset($row['participant_status_id'])) &&
356 ($statusId = array_search($row['participant_status_id'], $statusTypes))
358 $statusClass = $statusClasses[$statusId];
361 $row['showConfirmUrl'] = ($statusClass == 'Pending') ?
TRUE : FALSE;
363 if (!empty($row['participant_is_test'])) {
364 $row['participant_status'] .= ' (' . ts('test') . ')';
367 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->participant_id
;
368 $links = self
::links($this->_key
, $this->_context
, $this->_compContext
);
370 if ($statusTypes[$row['participant_status_id']] == 'Partially paid') {
371 $links[CRM_Core_Action
::ADD
] = array(
372 'name' => ts('Record Payment'),
373 'url' => 'civicrm/payment',
374 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
375 'title' => ts('Record Payment'),
379 if ($statusTypes[$row['participant_status_id']] == 'Pending refund') {
380 $links[CRM_Core_Action
::ADD
] = array(
381 'name' => ts('Record Refund'),
382 'url' => 'civicrm/payment',
383 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event',
384 'title' => ts('Record Refund'),
388 $row['action'] = CRM_Core_Action
::formLink($links,
391 'id' => $result->participant_id
,
392 'cid' => $result->contact_id
,
393 'cxt' => $this->_context
,
397 'participant.selector.row',
399 $result->participant_id
402 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
405 $row['paid'] = CRM_Event_BAO_Event
::isMonetary($row['event_id']);
407 if (!empty($row['participant_fee_level'])) {
408 CRM_Event_BAO_Participant
::fixEventLevel($row['participant_fee_level']);
411 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
412 // add line item details if applicable
413 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
416 if (!empty($row['participant_role_id'])) {
417 $viewRoles = array();
418 foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
419 $viewRoles[] = $participantRoles[$v];
421 $row['participant_role_id'] = implode(', ', $viewRoles);
425 CRM_Core_Selector_Controller
::$_template->assign_by_ref('lineItems', $lineItems);
433 public function getQILL() {
434 return $this->_query
->qill();
438 * Returns the column headers as an array of tuples:
439 * (name, sortName (key to the sort array))
441 * @param string $action
442 * The action being performed.
443 * @param string $output
444 * What should the result set include (web/email/csv).
447 * the column headers that need to be displayed
449 public function &getColumnHeaders($action = NULL, $output = NULL) {
450 if (!isset(self
::$_columnHeaders)) {
451 self
::$_columnHeaders = array(
453 'name' => ts('Event'),
454 'sort' => 'event_title',
455 'direction' => CRM_Utils_Sort
::DONTCARE
,
458 'name' => ts('Fee Level'),
459 'sort' => 'participant_fee_level',
460 'direction' => CRM_Utils_Sort
::DONTCARE
,
463 'name' => ts('Amount'),
464 'sort' => 'participant_fee_amount',
465 'direction' => CRM_Utils_Sort
::DONTCARE
,
468 'name' => ts('Registered'),
469 'sort' => 'participant_register_date',
470 'direction' => CRM_Utils_Sort
::DESCENDING
,
473 'name' => ts('Event Date(s)'),
474 'sort' => 'event_start_date',
475 'direction' => CRM_Utils_Sort
::DESCENDING
,
478 'name' => ts('Status'),
479 'sort' => 'participant_status',
480 'direction' => CRM_Utils_Sort
::DONTCARE
,
483 'name' => ts('Role'),
484 'sort' => 'participant_role_id',
485 'direction' => CRM_Utils_Sort
::DONTCARE
,
487 array('desc' => ts('Actions')),
490 if (!$this->_single
) {
492 array('desc' => ts('Contact Type')),
494 'name' => ts('Participant'),
495 'sort' => 'sort_name',
496 'direction' => CRM_Utils_Sort
::DONTCARE
,
499 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
502 return self
::$_columnHeaders;
508 public function alphabetQuery() {
509 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
515 public function &getQuery() {
516 return $this->_query
;
520 * Name of export file.
522 * @param string $output
528 public function getExportFileName($output = 'csv') {
529 return ts('CiviCRM Event Search');