Commit | Line | Data |
---|---|---|
4f5de903 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
4f5de903 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
4f5de903 TO |
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 | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
4f5de903 TO |
32 | */ |
33 | class CRM_Contact_Form_Search_Custom_FullText_Participant extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery { | |
34 | ||
4b62bc4f EM |
35 | /** |
36 | * Class constructor. | |
37 | */ | |
00be9182 | 38 | public function __construct() { |
4f5de903 TO |
39 | parent::__construct('Participant', ts('Participants')); |
40 | } | |
41 | ||
1cd3ffa9 | 42 | /** |
5a409b50 | 43 | * Check if user has permission. |
44 | * | |
1cd3ffa9 EM |
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 |
5a409b50 | 71 | * |
a6c01b45 CW |
72 | * @return array |
73 | * list tables/queries (for runQueries) | |
4f5de903 | 74 | */ |
00be9182 | 75 | public function prepareQueries($queryText, $entityIDTableName) { |
a04af6db TO |
76 | // Note: For available full-text indices, see CRM_Core_InnoDBIndexer |
77 | ||
4f5de903 TO |
78 | $contactSQL = array(); |
79 | $contactSQL[] = " | |
80 | SELECT distinct cp.id | |
81 | FROM civicrm_participant cp | |
82 | INNER JOIN civicrm_contact c ON cp.contact_id = c.id | |
a04af6db | 83 | WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)}) |
4f5de903 TO |
84 | "; |
85 | $tables = array( | |
86 | 'civicrm_participant' => array( | |
87 | 'id' => 'id', | |
88 | 'fields' => array( | |
89 | 'source' => NULL, | |
90 | 'fee_level' => NULL, | |
a04af6db | 91 | 'fee_amount' => 'Int', |
4f5de903 TO |
92 | ), |
93 | ), | |
cac9c01d TO |
94 | 'file' => array( |
95 | 'xparent_table' => 'civicrm_participant', | |
96 | ), | |
4f5de903 TO |
97 | 'sql' => $contactSQL, |
98 | 'civicrm_note' => array( | |
99 | 'id' => 'entity_id', | |
100 | 'entity_table' => 'civicrm_participant', | |
101 | 'fields' => array( | |
102 | 'subject' => NULL, | |
103 | 'note' => NULL, | |
104 | ), | |
105 | ), | |
106 | ); | |
107 | ||
108 | // get the custom data info | |
109 | $this->fillCustomInfo($tables, "( 'Participant' )"); | |
180ed6f5 | 110 | return $tables; |
4f5de903 TO |
111 | } |
112 | ||
2e2605fe EM |
113 | /** |
114 | * Move IDs. | |
115 | * @param string $fromTable | |
116 | * @param string $toTable | |
117 | * @param int $limit | |
118 | */ | |
613e5116 | 119 | public function moveIDs($fromTable, $toTable, $limit) { |
4f5de903 TO |
120 | $sql = " |
121 | INSERT INTO {$toTable} | |
122 | ( table_name, contact_id, sort_name, participant_id, event_title, participant_fee_level, participant_fee_amount, | |
123 | participant_register_date, participant_source, participant_status, participant_role ) | |
124 | SELECT 'Participant', c.id, c.sort_name, cp.id, ce.title, cp.fee_level, cp.fee_amount, cp.register_date, cp.source, | |
125 | participantStatus.label, cp.role_id | |
126 | FROM {$fromTable} ct | |
127 | INNER JOIN civicrm_participant cp ON cp.id = ct.entity_id | |
128 | LEFT JOIN civicrm_contact c ON cp.contact_id = c.id | |
129 | LEFT JOIN civicrm_event ce ON ce.id = cp.event_id | |
130 | LEFT JOIN civicrm_participant_status_type participantStatus ON participantStatus.id = cp.status_id | |
7296606d | 131 | {$this->toLimit($limit)} |
4f5de903 TO |
132 | "; |
133 | CRM_Core_DAO::executeQuery($sql); | |
134 | } | |
135 | ||
ef10e0b5 | 136 | } |