当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Contact_BAO_SavedSearch::contactIDsSQL方法代码示例

本文整理汇总了PHP中CRM_Contact_BAO_SavedSearch::contactIDsSQL方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_SavedSearch::contactIDsSQL方法的具体用法?PHP CRM_Contact_BAO_SavedSearch::contactIDsSQL怎么用?PHP CRM_Contact_BAO_SavedSearch::contactIDsSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Contact_BAO_SavedSearch的用法示例。


在下文中一共展示了CRM_Contact_BAO_SavedSearch::contactIDsSQL方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: from

 function from()
 {
     //define table name
     $randomNum = md5(uniqid());
     $this->_tableName = "civicrm_temp_custom_{$randomNum}";
     //grab the contacts added in the date range first
     $sql = "CREATE TEMPORARY TABLE dates_{$this->_tableName} ( id int primary key, date_added date ) ENGINE=HEAP";
     if ($this->_debug > 0) {
         print "-- Date range query: <pre>";
         print "{$sql};";
         print "</pre>";
     }
     CRM_Core_DAO::executeQuery($sql);
     $startDate = CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::processDate($this->_formValues['start_date']));
     $endDateFix = NULL;
     if (!empty($this->_formValues['end_date'])) {
         $endDate = CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::processDate($this->_formValues['end_date']));
         # tack 11:59pm on to make search inclusive of the end date
         $endDateFix = "AND date_added <= '" . substr($endDate, 0, 10) . " 23:59:00'";
     }
     $dateRange = "INSERT INTO dates_{$this->_tableName} ( id, date_added )\n          SELECT\n              civicrm_contact.id,\n              min(civicrm_log.modified_date) AS date_added\n          FROM\n              civicrm_contact LEFT JOIN civicrm_log\n              ON (civicrm_contact.id = civicrm_log.entity_id AND\n                  civicrm_log.entity_table = 'civicrm_contact')\n          GROUP BY\n              civicrm_contact.id\n          HAVING\n              date_added >= '{$startDate}' \n              {$endDateFix}";
     if ($this->_debug > 0) {
         print "-- Date range query: <pre>";
         print "{$dateRange};";
         print "</pre>";
     }
     CRM_Core_DAO::executeQuery($dateRange, CRM_Core_DAO::$_nullArray);
     // Only include groups in the search query of one or more Include OR Exclude groups has been selected.
     // CRM-6356
     if ($this->_groups) {
         //block for Group search
         $smartGroup = array();
         require_once 'CRM/Contact/DAO/Group.php';
         $group = new CRM_Contact_DAO_Group();
         $group->is_active = 1;
         $group->find();
         while ($group->fetch()) {
             $allGroups[] = $group->id;
             if ($group->saved_search_id) {
                 $smartGroup[$group->saved_search_id] = $group->id;
             }
         }
         $includedGroups = implode(',', $allGroups);
         if (!empty($this->_includeGroups)) {
             $iGroups = implode(',', $this->_includeGroups);
         } else {
             //if no group selected search for all groups
             $iGroups = $includedGroups;
         }
         if (is_array($this->_excludeGroups)) {
             $xGroups = implode(',', $this->_excludeGroups);
         } else {
             $xGroups = 0;
         }
         $sql = "DROP TEMPORARY TABLE IF EXISTS Xg_{$this->_tableName}";
         CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         $sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $excludeGroup = "INSERT INTO  Xg_{$this->_tableName} ( contact_id )\n                  SELECT  DISTINCT civicrm_group_contact.contact_id\n                  FROM civicrm_group_contact, dates_{$this->_tableName} AS d\n                  WHERE \n                     d.id = civicrm_group_contact.contact_id AND \n                     civicrm_group_contact.status = 'Added' AND\n                     civicrm_group_contact.group_id IN( {$xGroups})";
             CRM_Core_DAO::executeQuery($excludeGroup, CRM_Core_DAO::$_nullArray);
             //search for smart group contacts
             foreach ($this->_excludeGroups as $keys => $values) {
                 if (in_array($values, $smartGroup)) {
                     $ssId = CRM_Utils_Array::key($values, $smartGroup);
                     $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
                     $smartSql = $smartSql . " AND contact_a.id NOT IN ( \n                              SELECT contact_id FROM civicrm_group_contact \n                              WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
                     $smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) {$smartSql}";
                     CRM_Core_DAO::executeQuery($smartGroupQuery, CRM_Core_DAO::$_nullArray);
                 }
             }
         }
         $sql = "DROP TEMPORARY TABLE IF EXISTS Ig_{$this->_tableName}";
         CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         $sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName}\n                ( id int PRIMARY KEY AUTO_INCREMENT,\n                  contact_id int,\n                  group_names varchar(64)) ENGINE=HEAP";
         if ($this->_debug > 0) {
             print "-- Include groups query: <pre>";
             print "{$sql};";
             print "</pre>";
         }
         CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         $includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n                 SELECT      d.id as contact_id, civicrm_group.name as group_name\n                 FROM        dates_{$this->_tableName} AS d\n                 INNER JOIN  civicrm_group_contact\n                 ON          civicrm_group_contact.contact_id = d.id\n                 LEFT JOIN   civicrm_group\n                 ON          civicrm_group_contact.group_id = civicrm_group.id";
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $includeGroup .= " LEFT JOIN        Xg_{$this->_tableName}\n                                          ON        d.id = Xg_{$this->_tableName}.contact_id";
         }
         $includeGroup .= " WHERE           \n                                     civicrm_group_contact.status = 'Added'  AND\n                                     civicrm_group_contact.group_id IN({$iGroups})";
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $includeGroup .= " AND  Xg_{$this->_tableName}.contact_id IS null";
         }
         if ($this->_debug > 0) {
             print "-- Include groups query: <pre>";
             print "{$includeGroup};";
             print "</pre>";
         }
         CRM_Core_DAO::executeQuery($includeGroup, CRM_Core_DAO::$_nullArray);
         //search for smart group contacts
         foreach ($this->_includeGroups as $keys => $values) {
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:DateAdded.php

示例2: from

 function from()
 {
     //define table name
     $randomNum = md5(uniqid());
     $this->_tableName = "civicrm_temp_custom_{$randomNum}";
     //block for Group search
     $smartGroup = array();
     $group = new CRM_Contact_DAO_Group();
     $group->is_active = 1;
     $group->find();
     while ($group->fetch()) {
         $allGroups[] = $group->id;
         if ($group->saved_search_id) {
             $smartGroup[$group->saved_search_id] = $group->id;
         }
     }
     $includedGroups = implode(',', $allGroups);
     if (!empty($this->_includeGroups)) {
         $iGroups = implode(',', $this->_includeGroups);
     } else {
         //if no group selected search for all groups
         $iGroups = $includedGroups;
     }
     if (is_array($this->_excludeGroups)) {
         $xGroups = implode(',', $this->_excludeGroups);
     } else {
         $xGroups = 0;
     }
     $sql = "DROP TEMPORARY TABLE IF EXISTS Xg_{$this->_tableName}";
     CRM_Core_DAO::executeQuery($sql);
     $sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
     CRM_Core_DAO::executeQuery($sql);
     //used only when exclude group is selected
     if ($xGroups != 0) {
         $excludeGroup = "INSERT INTO  Xg_{$this->_tableName} ( contact_id )\n              SELECT  DISTINCT civicrm_group_contact.contact_id\n              FROM civicrm_group_contact\n              WHERE \n                 civicrm_group_contact.status = 'Added' AND\n                 civicrm_group_contact.group_id IN ( {$xGroups} )";
         CRM_Core_DAO::executeQuery($excludeGroup);
         //search for smart group contacts
         foreach ($this->_excludeGroups as $keys => $values) {
             if (in_array($values, $smartGroup)) {
                 $ssId = CRM_Utils_Array::key($values, $smartGroup);
                 $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
                 $smartSql = $smartSql . " AND contact_a.id NOT IN ( \n                          SELECT contact_id FROM civicrm_group_contact \n                          WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
                 $smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) {$smartSql}";
                 CRM_Core_DAO::executeQuery($smartGroupQuery);
             }
         }
     }
     $sql = "DROP TEMPORARY TABLE IF EXISTS Ig_{$this->_tableName}";
     CRM_Core_DAO::executeQuery($sql);
     $sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName}\n            ( id int PRIMARY KEY AUTO_INCREMENT,\n              contact_id int,\n              group_names varchar(64)) ENGINE=HEAP";
     if ($this->_debug > 0) {
         print "-- Include groups query: <pre>";
         print "{$sql};";
         print "</pre>";
     }
     CRM_Core_DAO::executeQuery($sql);
     $includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n             SELECT      civicrm_group_contact.contact_id, civicrm_group.name as group_name\n             FROM        civicrm_group_contact\n             LEFT JOIN   civicrm_group\n             ON          civicrm_group_contact.group_id = civicrm_group.id";
     //used only when exclude group is selected
     if ($xGroups != 0) {
         $includeGroup .= " LEFT JOIN        Xg_{$this->_tableName}\n                                      ON        civicrm_group_contact.contact_id = Xg_{$this->_tableName}.contact_id";
     }
     $includeGroup .= " WHERE           \n                                 civicrm_group_contact.status = 'Added'  AND\n                                 civicrm_group_contact.group_id IN({$iGroups})";
     //used only when exclude group is selected
     if ($xGroups != 0) {
         $includeGroup .= " AND  Xg_{$this->_tableName}.contact_id IS null";
     }
     if ($this->_debug > 0) {
         print "-- Include groups query: <pre>";
         print "{$includeGroup};";
         print "</pre>";
     }
     CRM_Core_DAO::executeQuery($includeGroup);
     //search for smart group contacts
     foreach ($this->_includeGroups as $keys => $values) {
         if (in_array($values, $smartGroup)) {
             $ssId = CRM_Utils_Array::key($values, $smartGroup);
             $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
             $smartSql .= " AND contact_a.id NOT IN ( \n                               SELECT contact_id FROM civicrm_group_contact\n                               WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
             //used only when exclude group is selected
             if ($xGroups != 0) {
                 $smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM  Xg_{$this->_tableName})";
             }
             $smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id) \n                    {$smartSql}";
             CRM_Core_DAO::executeQuery($smartGroupQuery);
             $insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}\n                    SET group_names = (SELECT title FROM civicrm_group\n                        WHERE civicrm_group.id = {$values})\n                    WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL \n                        AND Ig_{$this->_tableName}.group_names IS NULL";
             CRM_Core_DAO::executeQuery($insertGroupNameQuery);
         }
     }
     $from = "FROM civicrm_contact contact_a";
     $fromTail = "LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id AND civicrm_email.is_primary = 1 )";
     $fromTail .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
     // now create a temp table to store the randomized contacts
     $sql = "DROP TEMPORARY TABLE IF EXISTS random_{$this->_tableName}";
     CRM_Core_DAO::executeQuery($sql);
     $sql = "CREATE TEMPORARY TABLE random_{$this->_tableName} ( id int primary key ) ENGINE=HEAP";
     CRM_Core_DAO::executeQuery($sql);
     if (substr($this->_segmentSize, -1) == '%') {
         $countSql = "SELECT DISTINCT contact_a.id {$from} {$fromTail}\n                         WHERE " . $this->where();
         $dao = CRM_Core_DAO::executeQuery($countSql);
         $totalSize = $dao->N;
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:RandomSegment.php

示例3: from

 function from()
 {
     //define table name
     $randomNum = md5(uniqid());
     $this->_tableName = "civicrm_temp_custom_{$randomNum}";
     //block for Group search
     $smartGroup = array();
     if ($this->_groups || $this->_allSearch) {
         require_once 'CRM/Contact/DAO/Group.php';
         $group = new CRM_Contact_DAO_Group();
         $group->is_active = 1;
         $group->find();
         while ($group->fetch()) {
             $allGroups[] = $group->id;
             if ($group->saved_search_id) {
                 $smartGroup[$group->saved_search_id] = $group->id;
             }
         }
         $includedGroups = implode(',', $allGroups);
         if (!empty($this->_includeGroups)) {
             $iGroups = implode(',', $this->_includeGroups);
         } else {
             //if no group selected search for all groups
             $iGroups = null;
         }
         if (is_array($this->_excludeGroups)) {
             $xGroups = implode(',', $this->_excludeGroups);
         } else {
             $xGroups = 0;
         }
         $sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql);
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $excludeGroup = "INSERT INTO  Xg_{$this->_tableName} ( contact_id )\n                  SELECT  DISTINCT civicrm_group_contact.contact_id\n                  FROM civicrm_group_contact, civicrm_contact                    \n                  WHERE \n                     civicrm_contact.id = civicrm_group_contact.contact_id AND \n                     civicrm_group_contact.status = 'Added' AND\n                     civicrm_group_contact.group_id IN( {$xGroups})";
             CRM_Core_DAO::executeQuery($excludeGroup);
             //search for smart group contacts
             foreach ($this->_excludeGroups as $keys => $values) {
                 if (in_array($values, $smartGroup)) {
                     $ssId = CRM_Utils_Array::key($values, $smartGroup);
                     $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
                     $smartSql = $smartSql . " AND contact_a.id NOT IN ( \n                              SELECT contact_id FROM civicrm_group_contact \n                              WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
                     $smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) {$smartSql}";
                     CRM_Core_DAO::executeQuery($smartGroupQuery);
                 }
             }
         }
         $sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,\n                                                                   contact_id int,\n                                                                   group_names varchar(64)) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql);
         if ($iGroups) {
             $includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n                 SELECT              civicrm_contact.id as contact_id, civicrm_group.title as group_name\n                 FROM                civicrm_contact\n                    INNER JOIN       civicrm_group_contact\n                            ON       civicrm_group_contact.contact_id = civicrm_contact.id\n                    LEFT JOIN        civicrm_group\n                            ON       civicrm_group_contact.group_id = civicrm_group.id";
         } else {
             $includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n                 SELECT              civicrm_contact.id as contact_id, ''\n                 FROM                civicrm_contact";
         }
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $includeGroup .= " LEFT JOIN        Xg_{$this->_tableName}\n                                          ON       civicrm_contact.id = Xg_{$this->_tableName}.contact_id";
         }
         if ($iGroups) {
             $includeGroup .= " WHERE           \n                                     civicrm_group_contact.status = 'Added'  AND\n                                     civicrm_group_contact.group_id IN({$iGroups})";
         } else {
             $includeGroup .= " WHERE ( 1 ) ";
         }
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $includeGroup .= " AND  Xg_{$this->_tableName}.contact_id IS null";
         }
         CRM_Core_DAO::executeQuery($includeGroup);
         //search for smart group contacts
         foreach ($this->_includeGroups as $keys => $values) {
             if (in_array($values, $smartGroup)) {
                 $ssId = CRM_Utils_Array::key($values, $smartGroup);
                 $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
                 $smartSql .= " AND contact_a.id NOT IN ( \n                              SELECT contact_id FROM civicrm_group_contact\n                              WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
                 //used only when exclude group is selected
                 if ($xGroups != 0) {
                     $smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM  Xg_{$this->_tableName})";
                 }
                 $smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id) \n                                     {$smartSql}";
                 CRM_Core_DAO::executeQuery($smartGroupQuery);
                 $insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}\n                                         SET group_names = (SELECT title FROM civicrm_group\n                                                            WHERE civicrm_group.id = {$values})\n                                         WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL \n                                         AND Ig_{$this->_tableName}.group_names IS NULL";
                 CRM_Core_DAO::executeQuery($insertGroupNameQuery);
             }
         }
     }
     //group contact search end here;
     //block for Tags search
     if ($this->_tags || $this->_allSearch) {
         //find all tags
         require_once 'CRM/Core/DAO/Tag.php';
         $tag = new CRM_Core_DAO_Tag();
         $tag->is_active = 1;
         $tag->find();
         while ($tag->fetch()) {
             $allTags[] = $tag->id;
         }
         $includedTags = implode(',', $allTags);
         if (!empty($this->_includeTags)) {
             $iTags = implode(',', $this->_includeTags);
         } else {
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Group.php

示例4: from

 function from()
 {
     $iGroups = $xGroups = $iTags = $xTags = 0;
     //define table name
     $randomNum = md5(uniqid());
     $this->_tableName = "civicrm_temp_custom_{$randomNum}";
     //block for Group search
     $smartGroup = array();
     if ($this->_groups || $this->_allSearch) {
         $group = new CRM_Contact_DAO_Group();
         $group->is_active = 1;
         $group->find();
         while ($group->fetch()) {
             $allGroups[] = $group->id;
             if ($group->saved_search_id) {
                 $smartGroup[$group->saved_search_id] = $group->id;
             }
         }
         $includedGroups = implode(',', $allGroups);
         if (!empty($this->_includeGroups)) {
             $iGroups = implode(',', $this->_includeGroups);
         } else {
             //if no group selected search for all groups
             $iGroups = NULL;
         }
         if (is_array($this->_excludeGroups)) {
             $xGroups = implode(',', $this->_excludeGroups);
         } else {
             $xGroups = 0;
         }
         $sql = "CREATE TEMPORARY TABLE Xg_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql);
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $excludeGroup = "INSERT INTO  Xg_{$this->_tableName} ( contact_id )\n                  SELECT  DISTINCT civicrm_group_contact.contact_id\n                  FROM civicrm_group_contact, civicrm_contact\n                  WHERE\n                     civicrm_contact.id = civicrm_group_contact.contact_id AND\n                     civicrm_group_contact.status = 'Added' AND\n                     civicrm_group_contact.group_id IN( {$xGroups})";
             CRM_Core_DAO::executeQuery($excludeGroup);
             //search for smart group contacts
             foreach ($this->_excludeGroups as $keys => $values) {
                 if (in_array($values, $smartGroup)) {
                     $ssId = CRM_Utils_Array::key($values, $smartGroup);
                     $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
                     $smartSql = $smartSql . " AND contact_a.id NOT IN (\n                              SELECT contact_id FROM civicrm_group_contact\n                              WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
                     $smartGroupQuery = " INSERT IGNORE INTO Xg_{$this->_tableName}(contact_id) {$smartSql}";
                     CRM_Core_DAO::executeQuery($smartGroupQuery);
                 }
             }
         }
         $sql = "CREATE TEMPORARY TABLE Ig_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,\n                                                                   contact_id int,\n                                                                   group_names varchar(64)) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql);
         if ($iGroups) {
             $includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n                 SELECT              civicrm_contact.id as contact_id, civicrm_group.title as group_name\n                 FROM                civicrm_contact\n                    INNER JOIN       civicrm_group_contact\n                            ON       civicrm_group_contact.contact_id = civicrm_contact.id\n                    LEFT JOIN        civicrm_group\n                            ON       civicrm_group_contact.group_id = civicrm_group.id";
         } else {
             $includeGroup = "INSERT INTO Ig_{$this->_tableName} (contact_id, group_names)\n                 SELECT              civicrm_contact.id as contact_id, ''\n                 FROM                civicrm_contact";
         }
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $includeGroup .= " LEFT JOIN        Xg_{$this->_tableName}\n                                          ON       civicrm_contact.id = Xg_{$this->_tableName}.contact_id";
         }
         if ($iGroups) {
             $includeGroup .= " WHERE\n                                     civicrm_group_contact.status = 'Added'  AND\n                                     civicrm_group_contact.group_id IN({$iGroups})";
         } else {
             $includeGroup .= " WHERE ( 1 ) ";
         }
         //used only when exclude group is selected
         if ($xGroups != 0) {
             $includeGroup .= " AND  Xg_{$this->_tableName}.contact_id IS null";
         }
         CRM_Core_DAO::executeQuery($includeGroup);
         //search for smart group contacts
         foreach ($this->_includeGroups as $keys => $values) {
             if (in_array($values, $smartGroup)) {
                 $ssId = CRM_Utils_Array::key($values, $smartGroup);
                 $smartSql = CRM_Contact_BAO_SavedSearch::contactIDsSQL($ssId);
                 $smartSql .= " AND contact_a.id NOT IN (\n                              SELECT contact_id FROM civicrm_group_contact\n                              WHERE civicrm_group_contact.group_id = {$values} AND civicrm_group_contact.status = 'Removed')";
                 //used only when exclude group is selected
                 if ($xGroups != 0) {
                     $smartSql .= " AND contact_a.id NOT IN (SELECT contact_id FROM  Xg_{$this->_tableName})";
                 }
                 $smartGroupQuery = " INSERT IGNORE INTO Ig_{$this->_tableName}(contact_id)\n                                     {$smartSql}";
                 CRM_Core_DAO::executeQuery($smartGroupQuery);
                 $insertGroupNameQuery = "UPDATE IGNORE Ig_{$this->_tableName}\n                                         SET group_names = (SELECT title FROM civicrm_group\n                                                            WHERE civicrm_group.id = {$values})\n                                         WHERE Ig_{$this->_tableName}.contact_id IS NOT NULL\n                                         AND Ig_{$this->_tableName}.group_names IS NULL";
                 CRM_Core_DAO::executeQuery($insertGroupNameQuery);
             }
         }
     }
     //group contact search end here;
     //block for Tags search
     if ($this->_tags || $this->_allSearch) {
         //find all tags
         $tag = new CRM_Core_DAO_Tag();
         $tag->is_active = 1;
         $tag->find();
         while ($tag->fetch()) {
             $allTags[] = $tag->id;
         }
         $includedTags = implode(',', $allTags);
         if (!empty($this->_includeTags)) {
             $iTags = implode(',', $this->_includeTags);
         } else {
             //if no group selected search for all groups
//.........这里部分代码省略.........
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:101,代码来源:Group.php


注:本文中的CRM_Contact_BAO_SavedSearch::contactIDsSQL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。