3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Contact_Form_Search_Custom_FullText_Contact
extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery
{
38 public function __construct() {
39 parent
::__construct('Contact', ts('Contacts'));
43 * Check if search is permitted.
47 public function isActive() {
48 return CRM_Core_Permission
::check('view all contacts');
54 public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
55 $queries = $this->prepareQueries($queryText, $entityIDTableName);
56 $result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
57 $this->moveIDs($entityIDTableName, $toTable, $detailLimit);
58 if (!empty($result['files'])) {
59 $this->moveFileIDs($toTable, 'contact_id', $result['files']);
65 * @param string $queryText
66 * @param string $entityIDTableName
68 * list tables/queries (for runQueries)
70 public function prepareQueries($queryText, $entityIDTableName) {
71 // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
73 $contactSQL = array();
76 FROM civicrm_entity_tag et
77 INNER JOIN civicrm_tag t ON et.tag_id = t.id
78 WHERE et.entity_table = 'civicrm_contact'
80 AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
84 // lets delete all the deceased contacts from the entityID box
85 // this allows us to keep numbers in sync
86 // when we have acl contacts, the situation gets even more murky
88 $final[] = "DELETE FROM {$entityIDTableName} WHERE entity_id IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)";
91 'civicrm_contact' => array(
96 'display_name' => NULL,
99 'civicrm_address' => array(
100 'id' => 'contact_id',
102 'street_address' => NULL,
104 'postal_code' => NULL,
107 'civicrm_email' => array(
108 'id' => 'contact_id',
109 'fields' => array('email' => NULL),
111 'civicrm_phone' => array(
112 'id' => 'contact_id',
113 'fields' => array('phone' => NULL),
115 'civicrm_note' => array(
117 'entity_table' => 'civicrm_contact',
124 'xparent_table' => 'civicrm_contact',
126 'sql' => $contactSQL,
130 // get the custom data info
131 $this->fillCustomInfo($tables,
132 "( 'Contact', 'Individual', 'Organization', 'Household' )"
145 public function moveIDs($fromTable, $toTable, $limit) {
147 INSERT INTO {$toTable}
148 ( id, contact_id, sort_name, display_name, table_name )
149 SELECT c.id, ct.entity_id, c.sort_name, c.display_name, 'Contact'
151 INNER JOIN civicrm_contact c ON ct.entity_id = c.id
152 {$this->toLimit($limit)}
154 CRM_Core_DAO
::executeQuery($sql);