3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 function __construct() {
38 parent
::__construct('Activity', ts('Activities'));
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->moveActivityIDs($entityIDTableName, $toTable, $detailLimit);
56 * @param string $queryText
57 * @param string $entityIDTableName
58 * @return array list tables/queries (for runQueries)
60 function prepareQueries($queryText, $entityIDTableName) {
61 // Note: For available full-text indices, see CRM_Core_InnoDBIndexer
63 $contactSQL = array();
67 FROM civicrm_activity ca
68 INNER JOIN civicrm_activity_contact cat ON cat.activity_id = ca.id
69 INNER JOIN civicrm_contact c ON cat.contact_id = c.id
70 LEFT JOIN civicrm_email e ON cat.contact_id = e.contact_id
71 LEFT JOIN civicrm_option_group og ON og.name = 'activity_type'
72 LEFT JOIN civicrm_option_value ov ON ( ov.option_group_id = og.id )
74 ({$this->matchText('civicrm_contact c', array('sort_name', 'display_name', 'nick_name'), $queryText)})
76 ({$this->matchText('civicrm_email e', 'email', $queryText)} AND ca.activity_type_id = ov.value AND ov.name IN ('Inbound Email', 'Email') )
78 AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
79 AND (c.is_deleted = 0 OR c.is_deleted IS NULL)
84 FROM civicrm_entity_tag et
85 INNER JOIN civicrm_tag t ON et.tag_id = t.id
86 INNER JOIN civicrm_activity ca ON et.entity_id = ca.id
87 WHERE et.entity_table = 'civicrm_activity'
89 AND ({$this->matchText('civicrm_tag t', 'name', $queryText)})
90 AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
96 FROM civicrm_activity ca
97 WHERE ({$this->matchText('civicrm_activity ca', array('subject', 'details'), $queryText)})
98 AND (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
104 'civicrm_activity' => array('fields' => array()),
105 'sql' => $contactSQL,
109 $this->fillCustomInfo($tables, "( 'Activity' )");
113 public function moveActivityIDs($fromTable, $toTable, $limit) {
115 INSERT INTO {$toTable}
116 ( table_name, activity_id, subject, details, contact_id, sort_name, record_type,
117 activity_type_id, case_id, client_id )
118 SELECT 'Activity', ca.id, substr(ca.subject, 1, 50), substr(ca.details, 1, 250),
119 c1.id, c1.sort_name, cac.record_type_id,
122 ccc.contact_id as client_id
123 FROM {$fromTable} eid
124 INNER JOIN civicrm_activity ca ON ca.id = eid.entity_id
125 INNER JOIN civicrm_activity_contact cac ON cac.activity_id = ca.id
126 INNER JOIN civicrm_contact c1 ON cac.contact_id = c1.id
127 LEFT JOIN civicrm_case_activity cca ON cca.activity_id = ca.id
128 LEFT JOIN civicrm_case_contact ccc ON ccc.case_id = cca.case_id
129 WHERE (ca.is_deleted = 0 OR ca.is_deleted IS NULL)
131 {$this->toLimit($limit)}
133 CRM_Core_DAO
::executeQuery($sql);