Commit | Line | Data |
---|---|---|
4f5de903 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.5 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2014 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Contact_Form_Search_Custom_FullText_Participant extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery { | |
36 | ||
37 | function __construct() { | |
38 | parent::__construct('Participant', ts('Participants')); | |
39 | } | |
40 | ||
41 | function isActive() { | |
42 | $config = CRM_Core_Config::singleton(); | |
43 | return in_array('CiviEvent', $config->enableComponents) && | |
44 | CRM_Core_Permission::check('view event participants'); | |
45 | } | |
46 | ||
47 | /** | |
48 | * {@inheritdoc} | |
49 | */ | |
50 | public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) { | |
180ed6f5 TO |
51 | $queries = $this->prepareQueries($queryText, $entityIDTableName); |
52 | $result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit); | |
4f5de903 | 53 | $this->moveParticipantIDs($entityIDTableName, $toTable, $detailLimit); |
180ed6f5 | 54 | return $result; |
4f5de903 TO |
55 | } |
56 | ||
57 | /** | |
58 | * get participant ids in entity tables. | |
59 | * | |
60 | * @param string $queryText | |
180ed6f5 TO |
61 | * @param string $entityIDTableName |
62 | * @return array list tables/queries (for runQueries) | |
4f5de903 | 63 | */ |
180ed6f5 | 64 | function prepareQueries($queryText, $entityIDTableName) { |
a04af6db TO |
65 | // Note: For available full-text indices, see CRM_Core_InnoDBIndexer |
66 | ||
4f5de903 TO |
67 | $contactSQL = array(); |
68 | $contactSQL[] = " | |
69 | SELECT distinct cp.id | |
70 | FROM civicrm_participant cp | |
71 | INNER JOIN civicrm_contact c ON cp.contact_id = c.id | |
a04af6db | 72 | WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)}) |
4f5de903 TO |
73 | "; |
74 | $tables = array( | |
75 | 'civicrm_participant' => array( | |
76 | 'id' => 'id', | |
77 | 'fields' => array( | |
78 | 'source' => NULL, | |
79 | 'fee_level' => NULL, | |
a04af6db | 80 | 'fee_amount' => 'Int', |
4f5de903 TO |
81 | ), |
82 | ), | |
83 | 'sql' => $contactSQL, | |
84 | 'civicrm_note' => array( | |
85 | 'id' => 'entity_id', | |
86 | 'entity_table' => 'civicrm_participant', | |
87 | 'fields' => array( | |
88 | 'subject' => NULL, | |
89 | 'note' => NULL, | |
90 | ), | |
91 | ), | |
92 | ); | |
93 | ||
94 | // get the custom data info | |
95 | $this->fillCustomInfo($tables, "( 'Participant' )"); | |
180ed6f5 | 96 | return $tables; |
4f5de903 TO |
97 | } |
98 | ||
99 | public function moveParticipantIDs($fromTable, $toTable, $limit) { | |
100 | $sql = " | |
101 | INSERT INTO {$toTable} | |
102 | ( table_name, contact_id, sort_name, participant_id, event_title, participant_fee_level, participant_fee_amount, | |
103 | participant_register_date, participant_source, participant_status, participant_role ) | |
104 | SELECT 'Participant', c.id, c.sort_name, cp.id, ce.title, cp.fee_level, cp.fee_amount, cp.register_date, cp.source, | |
105 | participantStatus.label, cp.role_id | |
106 | FROM {$fromTable} ct | |
107 | INNER JOIN civicrm_participant cp ON cp.id = ct.entity_id | |
108 | LEFT JOIN civicrm_contact c ON cp.contact_id = c.id | |
109 | LEFT JOIN civicrm_event ce ON ce.id = cp.event_id | |
110 | LEFT JOIN civicrm_participant_status_type participantStatus ON participantStatus.id = cp.status_id | |
7296606d | 111 | {$this->toLimit($limit)} |
4f5de903 TO |
112 | "; |
113 | CRM_Core_DAO::executeQuery($sql); | |
114 | } | |
115 | ||
116 | } |