3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Contact_Form_Search_Custom_FullText_Activity
extends CRM_Contact_Form_Search_Custom_FullText_AbstractPartialQuery
{
37 public function __construct() {
38 parent
::__construct('Activity', ts('Activities'));
41 public function isActive() {
42 return CRM_Core_Permission
::check('view all activities');
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 if (!empty($result['files'])) {
53 $this->moveFileIDs($toTable, 'activity_id', $result['files']);
59 * @param string $queryText
60 * @param string $entityIDTableName
61 * @return array list tables/queries (for runQueries)
63 public function prepareQueries($queryText, $entityIDTableName) {
64 // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
66 $contactSQL = array();
70 FROM civicrm_activity ca
71 INNER JOIN civicrm_activity_contact cat ON cat.activity_id = ca.id
72 INNER JOIN civicrm_contact c ON cat.contact_id = c.id
73 LEFT JOIN civicrm_email e ON cat.contact_id = e.contact_id
74 LEFT JOIN civicrm_option_group og ON og.name = 'activity_type'
75 LEFT JOIN civicrm_option_value ov ON ( ov.option_group_id = og.id )
77 ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
79 ({$this->matchText('civicrm_email e', 'email', $queryText)} AND ca.activity_type_id = ov.value AND ov.name IN ('Inbound Email', 'Email') )
81 AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
82 AND (c.is_deleted = 0 OR c.is_deleted IS NULL)
87 FROM civicrm_entity_tag et
88 INNER JOIN civicrm_tag t ON et.tag_id = t.id
89 INNER JOIN civicrm_activity ca ON et.entity_id = ca.id
90 WHERE et.entity_table = 'civicrm_activity'
92 AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
93 AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
99 FROM civicrm_activity ca
100 WHERE ({$this->matchText('civicrm_activity ca', array('subject', 'details'), $queryText)})
101 AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
107 'civicrm_activity' => array('fields' => array()),
109 'xparent_table' => 'civicrm_activity',
111 'sql' => $contactSQL,
115 $this->fillCustomInfo($tables, "( 'Activity' )");
119 public function moveIDs($fromTable, $toTable, $limit) {
121 INSERT INTO {$toTable}
122 ( table_name, activity_id, subject, details, contact_id, sort_name, record_type,
123 activity_type_id, case_id, client_id )
124 SELECT 'Activity', ca.id, substr(ca.subject, 1, 50), substr(ca.details, 1, 250),
125 c1.id, c1.sort_name, cac.record_type_id,
128 ccc.contact_id as client_id
129 FROM {$fromTable} eid
130 INNER JOIN civicrm_activity ca ON ca.id = eid.entity_id
131 INNER JOIN civicrm_activity_contact cac ON cac.activity_id = ca.id
132 INNER JOIN civicrm_contact c1 ON cac.contact_id = c1.id
133 LEFT JOIN civicrm_case_activity cca ON cca.activity_id = ca.id
134 LEFT JOIN civicrm_case_contact ccc ON ccc.case_id = cca.case_id
135 WHERE (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
137 {$this->toLimit($limit)}
139 CRM_Core_DAO
::executeQuery($sql);