3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
94 protected $_single = FALSE;
97 * are we restricting ourselves to a single contact
102 protected $_limit = NULL;
105 * what context are we being invoked from
110 protected $_context = NULL;
113 * what component context are we being invoked from
118 protected $_compContext = NULL;
121 * queryParams is the array returned by exportValues called on
122 * the HTML_QuickForm_Controller for that page.
127 public $_queryParams;
130 * represent the type of selector
138 * The additional clause that we restrict the search with
142 protected $_eventClause = NULL;
154 * @param array $queryParams array of parameters for query
155 * @param int $action - action of search basic or advanced.
156 * @param string $eventClause if the caller wants to further restrict the search (used in participations)
157 * @param boolean $single are we dealing only with one contact?
158 * @param int $limit how many participations do we want returned
160 * @return CRM_Contact_Selector
163 function __construct(&$queryParams,
164 $action = CRM_Core_Action
::NONE
,
171 // submitted form values
172 $this->_queryParams
= &$queryParams;
174 $this->_single
= $single;
175 $this->_limit
= $limit;
176 $this->_context
= $context;
177 $this->_compContext
= $compContext;
179 $this->_eventClause
= $eventClause;
182 $this->_action
= $action;
184 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
185 CRM_Event_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_EVENT
,
189 CRM_Contact_BAO_Query
::MODE_EVENT
191 $this->_query
->_distinctComponentClause
= " civicrm_participant.id";
192 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_participant.id ";
197 * Can be used to alter the number of participation returned from a buildForm hook
199 * @param int $limit how many participations do we want returned
203 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
218 static function &links($qfKey = NULL, $context = NULL, $compContext = NULL) {
221 $extraParams .= "&compContext={$compContext}";
223 elseif ($context == 'search') {
224 $extraParams .= '&compContext=participant';
228 $extraParams .= "&key={$qfKey}";
232 if (!(self
::$_links)) {
233 self
::$_links = array(
234 CRM_Core_Action
::VIEW
=> array(
235 'name' => ts('View'),
236 'url' => 'civicrm/contact/view/participant',
237 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=event' . $extraParams,
238 'title' => ts('View Participation'),
240 CRM_Core_Action
::UPDATE
=> array(
241 'name' => ts('Edit'),
242 'url' => 'civicrm/contact/view/participant',
243 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
244 'title' => ts('Edit Participation'),
246 CRM_Core_Action
::DELETE
=> array(
247 'name' => ts('Delete'),
248 'url' => 'civicrm/contact/view/participant',
249 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
250 'title' => ts('Delete Participation'),
254 return self
::$_links;
259 * getter for array of the parameters required for creating pager.
264 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';
280 * Returns total number of rows for the query.
284 * @return int Total number of rows
287 function getTotalCount($action) {
288 return $this->_query
->searchQuery(0, 0, NULL,
297 * returns all the rows in the given offset and rowCount
299 * @param enum $action the action being performed
300 * @param int $offset the row number to start from
301 * @param int $rowCount the number of rows to return
302 * @param string $sort the sql string that describes the sort order
303 * @param enum $output what should the result set include (web/email/csv)
305 * @return array rows in the given offset and rowCount
307 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
308 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
314 // process the result of the query
317 //lets handle view, edit and delete separately. CRM-4418
318 $permissions = array(CRM_Core_Permission
::VIEW
);
319 if (CRM_Core_Permission
::check('edit event participants')) {
320 $permissions[] = CRM_Core_Permission
::EDIT
;
322 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
323 $permissions[] = CRM_Core_Permission
::DELETE
;
325 $mask = CRM_Core_Action
::mask($permissions);
327 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
328 $statusClasses = CRM_Event_PseudoConstant
::participantStatusClass();
329 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
330 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
333 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
335 while ($result->fetch()) {
337 // the columns we are interested in
338 foreach (self
::$_properties as $property) {
339 if (isset($result->$property)) {
340 $row[$property] = $result->$property;
344 //carry campaign on selectors.
345 $row['campaign'] = CRM_Utils_Array
::value($result->participant_campaign_id
, $allCampaigns);
346 $row['campaign_id'] = $result->participant_campaign_id
;
348 // gross hack to show extra information for pending status
350 if ((isset($row['participant_status_id'])) &&
351 ($statusId = array_search($row['participant_status_id'], $statusTypes))
353 $statusClass = $statusClasses[$statusId];
356 $row['showConfirmUrl'] = ($statusClass == 'Pending') ?
TRUE : FALSE;
358 if (CRM_Utils_Array
::value('participant_is_test', $row)) {
359 $row['participant_status'] .= ' (' . ts('test') . ')';
362 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->participant_id
;
364 $row['action'] = CRM_Core_Action
::formLink(self
::links($this->_key
, $this->_context
, $this->_compContext
),
367 'id' => $result->participant_id
,
368 'cid' => $result->contact_id
,
369 'cxt' => $this->_context
,
373 'participant.selector.row',
375 $result->participant_id
379 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
380 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
383 $row['paid'] = CRM_Event_BAO_Event
::isMonetary($row['event_id']);
385 if (CRM_Utils_Array
::value('participant_fee_level', $row)) {
386 CRM_Event_BAO_Participant
::fixEventLevel($row['participant_fee_level']);
389 if (CRM_Event_BAO_Event
::usesPriceSet($row['event_id'])) {
390 // add line item details if applicable
391 $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem
::getLineItems($row['participant_id']);
394 if (!empty($row['participant_role_id'])) {
395 $viewRoles = array();
396 foreach (explode($sep, $row['participant_role_id']) as $k => $v) {
397 $viewRoles[] = $participantRoles[$v];
399 $row['participant_role_id'] = implode(', ', $viewRoles);
403 CRM_Core_Selector_Controller
::$_template->assign_by_ref('lineItems', $lineItems);
410 * @return array $qill which contains an array of strings
414 // the current internationalisation is bad, but should more or less work
415 // for most of "European" languages
416 public function getQILL() {
417 return $this->_query
->qill();
421 * returns the column headers as an array of tuples:
422 * (name, sortName (key to the sort array))
424 * @param string $action the action being performed
425 * @param enum $output what should the result set include (web/email/csv)
427 * @return array the column headers that need to be displayed
430 public function &getColumnHeaders($action = NULL, $output = NULL) {
431 if (!isset(self
::$_columnHeaders)) {
432 self
::$_columnHeaders = array(
433 array('name' => ts('Event'),
434 'sort' => 'event_title',
435 'direction' => CRM_Utils_Sort
::DONTCARE
,
438 'name' => ts('Fee Level'),
439 'sort' => 'fee_level',
440 'direction' => CRM_Utils_Sort
::DONTCARE
,
443 'name' => ts('Amount'),
444 'sort' => 'fee_amount',
445 'direction' => CRM_Utils_Sort
::DONTCARE
,
448 'name' => ts('Registered'),
449 'sort' => 'participant_register_date',
450 'direction' => CRM_Utils_Sort
::DESCENDING
,
453 'name' => ts('Event Date(s)'),
454 'sort' => 'event_start_date',
455 'direction' => CRM_Utils_Sort
::DESCENDING
,
458 'name' => ts('Status'),
459 'sort' => 'participant_status',
460 'direction' => CRM_Utils_Sort
::DONTCARE
,
463 'name' => ts('Role'),
464 'sort' => 'participant_role_id',
465 'direction' => CRM_Utils_Sort
::DONTCARE
,
467 array('desc' => ts('Actions')),
470 if (!$this->_single
) {
472 array('desc' => ts('Contact Type')),
474 'name' => ts('Participant'),
475 'sort' => 'sort_name',
476 'direction' => CRM_Utils_Sort
::DONTCARE
,
479 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
482 return self
::$_columnHeaders;
485 function alphabetQuery() {
486 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
489 function &getQuery() {
490 return $this->_query
;
494 * name of export file.
496 * @param string $output type of output
498 * @return string name of the file
500 function getExportFileName($output = 'csv') {
501 return ts('CiviCRM Event Search');