Merge pull request #5060 from eileenmcnaughton/api-comment-fixes
[civicrm-core.git] / CRM / Contact / Form / Search / Custom / FullText / Participant.php
CommitLineData
4f5de903
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
4f5de903
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
4f5de903
TO
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35class CRM_Contact_Form_Search_Custom_FullText_Participant extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
36
4b62bc4f
EM
37 /**
38 * Class constructor.
39 */
00be9182 40 public function __construct() {
4f5de903
TO
41 parent::__construct('Participant', ts('Participants'));
42 }
43
1cd3ffa9
EM
44 /**
45 * @return bool
46 */
00be9182 47 public function isActive() {
4f5de903
TO
48 $config = CRM_Core_Config::singleton();
49 return in_array('CiviEvent', $config->enableComponents) &&
353ffa53 50 CRM_Core_Permission::check('view event participants');
4f5de903
TO
51 }
52
53 /**
e7c15cb6 54 * @inheritDoc
4f5de903
TO
55 */
56 public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
180ed6f5
TO
57 $queries = $this->prepareQueries($queryText, $entityIDTableName);
58 $result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
613e5116 59 $this->moveIDs($entityIDTableName, $toTable, $detailLimit);
cac9c01d
TO
60 if (!empty($result['files'])) {
61 $this->moveFileIDs($toTable, 'participant_id', $result['files']);
62 }
180ed6f5 63 return $result;
4f5de903
TO
64 }
65
66 /**
100fef9d 67 * Get participant ids in entity tables.
4f5de903
TO
68 *
69 * @param string $queryText
180ed6f5 70 * @param string $entityIDTableName
a6c01b45
CW
71 * @return array
72 * list tables/queries (for runQueries)
4f5de903 73 */
00be9182 74 public function prepareQueries($queryText, $entityIDTableName) {
a04af6db
TO
75 // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
76
4f5de903
TO
77 $contactSQL = array();
78 $contactSQL[] = "
79SELECT distinct cp.id
80FROM civicrm_participant cp
81INNER JOIN civicrm_contact c ON cp.contact_id = c.id
a04af6db 82WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
4f5de903
TO
83";
84 $tables = array(
85 'civicrm_participant' => array(
86 'id' => 'id',
87 'fields' => array(
88 'source' => NULL,
89 'fee_level' => NULL,
a04af6db 90 'fee_amount' => 'Int',
4f5de903
TO
91 ),
92 ),
cac9c01d
TO
93 'file' => array(
94 'xparent_table' => 'civicrm_participant',
95 ),
4f5de903
TO
96 'sql' => $contactSQL,
97 'civicrm_note' => array(
98 'id' => 'entity_id',
99 'entity_table' => 'civicrm_participant',
100 'fields' => array(
101 'subject' => NULL,
102 'note' => NULL,
103 ),
104 ),
105 );
106
107 // get the custom data info
108 $this->fillCustomInfo($tables, "( 'Participant' )");
180ed6f5 109 return $tables;
4f5de903
TO
110 }
111
2e2605fe
EM
112 /**
113 * Move IDs.
114 * @param string $fromTable
115 * @param string $toTable
116 * @param int $limit
117 */
613e5116 118 public function moveIDs($fromTable, $toTable, $limit) {
4f5de903
TO
119 $sql = "
120INSERT INTO {$toTable}
121( table_name, contact_id, sort_name, participant_id, event_title, participant_fee_level, participant_fee_amount,
122participant_register_date, participant_source, participant_status, participant_role )
123 SELECT 'Participant', c.id, c.sort_name, cp.id, ce.title, cp.fee_level, cp.fee_amount, cp.register_date, cp.source,
124 participantStatus.label, cp.role_id
125 FROM {$fromTable} ct
126INNER JOIN civicrm_participant cp ON cp.id = ct.entity_id
127LEFT JOIN civicrm_contact c ON cp.contact_id = c.id
128LEFT JOIN civicrm_event ce ON ce.id = cp.event_id
129LEFT JOIN civicrm_participant_status_type participantStatus ON participantStatus.id = cp.status_id
7296606d 130{$this->toLimit($limit)}
4f5de903
TO
131";
132 CRM_Core_DAO::executeQuery($sql);
133 }
134
ef10e0b5 135}