Commit | Line | Data |
---|---|---|
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 | */ | |
35 | class CRM_Contact_Form_Search_Custom_FullText_Membership extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery { | |
36 | ||
00be9182 | 37 | public function __construct() { |
4f5de903 TO |
38 | parent::__construct('Membership', ts('Memberships')); |
39 | } | |
40 | ||
00be9182 | 41 | public function isActive() { |
4f5de903 TO |
42 | $config = CRM_Core_Config::singleton(); |
43 | return in_array('CiviMember', $config->enableComponents) && | |
353ffa53 | 44 | CRM_Core_Permission::check('access CiviMember'); |
4f5de903 TO |
45 | } |
46 | ||
47 | /** | |
e7c15cb6 | 48 | * @inheritDoc |
4f5de903 TO |
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); | |
613e5116 | 53 | $this->moveIDs($entityIDTableName, $toTable, $detailLimit); |
cac9c01d TO |
54 | if (!empty($result['files'])) { |
55 | $this->moveFileIDs($toTable, 'membership_id', $result['files']); | |
56 | } | |
180ed6f5 | 57 | return $result; |
4f5de903 TO |
58 | } |
59 | ||
60 | /** | |
100fef9d | 61 | * Get membership ids in entity tables. |
4f5de903 TO |
62 | * |
63 | * @param string $queryText | |
180ed6f5 | 64 | * @param string $entityIDTableName |
a6c01b45 CW |
65 | * @return array |
66 | * list tables/queries (for runQueries) | |
4f5de903 | 67 | */ |
00be9182 | 68 | public function prepareQueries($queryText, $entityIDTableName) { |
a04af6db TO |
69 | // Note: For available full-text indices, see CRM_Core_InnoDBIndexer |
70 | ||
4f5de903 TO |
71 | $contactSQL = array(); |
72 | $contactSQL[] = " | |
73 | SELECT distinct cm.id | |
74 | FROM civicrm_membership cm | |
75 | INNER JOIN civicrm_contact c ON cm.contact_id = c.id | |
a04af6db | 76 | WHERE ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)}) |
4f5de903 TO |
77 | "; |
78 | $tables = array( | |
79 | 'civicrm_membership' => array( | |
80 | 'id' => 'id', | |
81 | 'fields' => array('source' => NULL), | |
82 | ), | |
cac9c01d TO |
83 | 'file' => array( |
84 | 'xparent_table' => 'civicrm_membership', | |
85 | ), | |
4f5de903 TO |
86 | 'sql' => $contactSQL, |
87 | ); | |
88 | ||
89 | // get the custom data info | |
90 | $this->fillCustomInfo($tables, "( 'Membership' )"); | |
180ed6f5 | 91 | return $tables; |
4f5de903 TO |
92 | } |
93 | ||
613e5116 | 94 | public function moveIDs($fromTable, $toTable, $limit) { |
4f5de903 TO |
95 | $sql = " |
96 | INSERT INTO {$toTable} | |
97 | ( table_name, contact_id, sort_name, membership_id, membership_type, membership_fee, membership_start_date, | |
98 | membership_end_date, membership_source, membership_status ) | |
99 | SELECT 'Membership', c.id, c.sort_name, cm.id, cmt.name, cc.total_amount, cm.start_date, cm.end_date, cm.source, cms.name | |
100 | FROM {$fromTable} ct | |
101 | INNER JOIN civicrm_membership cm ON cm.id = ct.entity_id | |
102 | LEFT JOIN civicrm_contact c ON cm.contact_id = c.id | |
103 | LEFT JOIN civicrm_membership_type cmt ON cmt.id = cm.membership_type_id | |
104 | LEFT JOIN civicrm_membership_payment cmp ON cmp.membership_id = cm.id | |
105 | LEFT JOIN civicrm_contribution cc ON cc.id = cmp.contribution_id | |
106 | LEFT JOIN civicrm_membership_status cms ON cms.id = cm.status_id | |
7296606d | 107 | {$this->toLimit($limit)} |
4f5de903 TO |
108 | "; |
109 | CRM_Core_DAO::executeQuery($sql); | |
110 | } | |
111 | ||
ef10e0b5 | 112 | } |