(NFC) (dev/core#878) Simplify '@copyright' annotation
[civicrm-core.git] / CRM / Contact / Form / Search / Custom / FullText / Participant.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC https://civicrm.org/licensing
32 */
33 class CRM_Contact_Form_Search_Custom_FullText_Participant extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
34
35 /**
36 * Class constructor.
37 */
38 public function __construct() {
39 parent::__construct('Participant', ts('Participants'));
40 }
41
42 /**
43 * Check if user has permission.
44 *
45 * @return bool
46 */
47 public function isActive() {
48 $config = CRM_Core_Config::singleton();
49 return in_array('CiviEvent', $config->enableComponents) &&
50 CRM_Core_Permission::check('view event participants');
51 }
52
53 /**
54 * @inheritDoc
55 */
56 public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
57 $queries = $this->prepareQueries($queryText, $entityIDTableName);
58 $result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
59 $this->moveIDs($entityIDTableName, $toTable, $detailLimit);
60 if (!empty($result['files'])) {
61 $this->moveFileIDs($toTable, 'participant_id', $result['files']);
62 }
63 return $result;
64 }
65
66 /**
67 * Get participant ids in entity tables.
68 *
69 * @param string $queryText
70 * @param string $entityIDTableName
71 *
72 * @return array
73 * list tables/queries (for runQueries)
74 */
75 public function prepareQueries($queryText, $entityIDTableName) {
76 // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
77
78 $contactSQL = [];
79 $contactSQL[] = "
80 SELECT distinct cp.id
81 FROM civicrm_participant cp
82 INNER JOIN civicrm_contact c ON cp.contact_id = c.id
83 WHERE ({$this->matchText('civicrm_contact c', ['sort_name', 'display_name', 'nick_name'], $queryText)})
84 ";
85 $tables = [
86 'civicrm_participant' => [
87 'id' => 'id',
88 'fields' => [
89 'source' => NULL,
90 'fee_level' => NULL,
91 'fee_amount' => 'Int',
92 ],
93 ],
94 'file' => [
95 'xparent_table' => 'civicrm_participant',
96 ],
97 'sql' => $contactSQL,
98 'civicrm_note' => [
99 'id' => 'entity_id',
100 'entity_table' => 'civicrm_participant',
101 'fields' => [
102 'subject' => NULL,
103 'note' => NULL,
104 ],
105 ],
106 ];
107
108 // get the custom data info
109 $this->fillCustomInfo($tables, "( 'Participant' )");
110 return $tables;
111 }
112
113 /**
114 * Move IDs.
115 * @param string $fromTable
116 * @param string $toTable
117 * @param int $limit
118 */
119 public function moveIDs($fromTable, $toTable, $limit) {
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
131 {$this->toLimit($limit)}
132 ";
133 CRM_Core_DAO::executeQuery($sql);
134 }
135
136 }