CRM-14765 - FullText - Consistently use function name "moveIDs"
[civicrm-core.git] / CRM / Contact / Form / Search / Custom / FullText / Contact.php
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_Contact extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery {
36
37 function __construct() {
38 parent::__construct('Contact', ts('Contacts'));
39 }
40
41 function isActive() {
42 return CRM_Core_Permission::check('view all contacts');
43 }
44
45 /**
46 * {@inheritdoc}
47 */
48 public function fillTempTable($queryText, $entityIDTableName, $toTable, $queryLimit, $detailLimit) {
49 $queries = $this->prepareQueries($queryText, $entityIDTableName);
50 $result = $this->runQueries($queryText, $queries, $entityIDTableName, $queryLimit);
51 $this->moveIDs($entityIDTableName, $toTable, $detailLimit);
52 return $result;
53 }
54
55 /**
56 * @param string $queryText
57 * @param string $entityIDTableName
58 * @return array list tables/queries (for runQueries)
59 */
60 function prepareQueries($queryText, $entityIDTableName) {
61 // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
62
63 $contactSQL = array();
64 $contactSQL[] = "
65 SELECT et.entity_id
66 FROM civicrm_entity_tag et
67 INNER JOIN civicrm_tag t ON et.tag_id = t.id
68 WHERE et.entity_table = 'civicrm_contact'
69 AND et.tag_id = t.id
70 AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
71 GROUP BY et.entity_id
72 ";
73
74 // lets delete all the deceased contacts from the entityID box
75 // this allows us to keep numbers in sync
76 // when we have acl contacts, the situation gets even more murky
77 $final = array();
78 $final[] = "DELETE FROM {$entityIDTableName} WHERE entity_id IN (SELECT id FROM civicrm_contact WHERE is_deleted = 1)";
79
80 $tables = array(
81 'civicrm_contact' => array(
82 'id' => 'id',
83 'fields' => array(
84 'sort_name' => NULL,
85 'nick_name' => NULL,
86 'display_name' => NULL,
87 ),
88 ),
89 'civicrm_address' => array(
90 'id' => 'contact_id',
91 'fields' => array(
92 'street_address' => NULL,
93 'city' => NULL,
94 'postal_code' => NULL,
95 ),
96 ),
97 'civicrm_email' => array(
98 'id' => 'contact_id',
99 'fields' => array('email' => NULL),
100 ),
101 'civicrm_phone' => array(
102 'id' => 'contact_id',
103 'fields' => array('phone' => NULL),
104 ),
105 'civicrm_note' => array(
106 'id' => 'entity_id',
107 'entity_table' => 'civicrm_contact',
108 'fields' => array(
109 'subject' => NULL,
110 'note' => NULL,
111 ),
112 ),
113 'sql' => $contactSQL,
114 'final' => $final,
115 );
116
117 // get the custom data info
118 $this->fillCustomInfo($tables,
119 "( 'Contact', 'Individual', 'Organization', 'Household' )"
120 );
121
122 return $tables;
123 }
124
125 public function moveIDs($fromTable, $toTable, $limit) {
126 $sql = "
127 INSERT INTO {$toTable}
128 ( id, contact_id, sort_name, display_name, table_name )
129 SELECT c.id, ct.entity_id, c.sort_name, c.display_name, 'Contact'
130 FROM {$fromTable} ct
131 INNER JOIN civicrm_contact c ON ct.entity_id = c.id
132 {$this->toLimit($limit)}
133 ";
134 CRM_Core_DAO::executeQuery($sql);
135 }
136
137 }