예제 #1
0
 /**
  * where / qill clause for smart groups
  *
  * @return void
  * @access public
  */
 function savedSearch()
 {
     $config =& CRM_Core_Config::singleton();
     $ssWhere = array();
     $group =& new CRM_Contact_BAO_Group();
     foreach (array_keys($this->_params['group']) as $group_id) {
         $group->id = $group_id;
         $group->find(true);
         if (isset($group->saved_search_id)) {
             require_once 'CRM/Contact/BAO/SavedSearch.php';
             if ($config->mysqlVersion >= 4.1) {
                 $sfv =& CRM_Contact_BAO_SavedSearch::getFormValues($group->saved_search_id);
                 $smarts =& CRM_Contact_BAO_Contact::searchQuery($sfv, 0, 0, null, false, false, false, true, true);
                 $ssWhere[] = " \n                            (civicrm_contact.id IN ({$smarts})  \n                            AND civicrm_contact.id NOT IN ( \n                            SELECT contact_id FROM civicrm_group_contact \n                            WHERE civicrm_group_contact.group_id = " . CRM_Utils_Type::escape($group_id, 'Integer') . " AND civicrm_group_contact.status = 'Removed'))";
             } else {
                 $ssw = CRM_Contact_BAO_SavedSearch::whereClause($group->saved_search_id, $this->_tables, $this->_whereTables);
                 /* FIXME: bug with multiple group searches */
                 $ssWhere[] = "({$ssw} AND\n                                   (civicrm_group_contact.id is null OR\n                                     (civicrm_group_contact.group_id = " . CRM_Utils_Type::escape($group_id, 'Integer') . " AND\n                                      civicrm_group_contact.status = 'Added')))";
             }
         }
         $group->reset();
         $group->selectAdd('*');
     }
     if (!empty($ssWhere)) {
         $this->_tables['civicrm_group_contact'] = "civicrm_contact.id = civicrm_group_contact.contact_id AND civicrm_group_contact.group_id IN (" . implode(',', array_keys($this->_params['group'])) . ')';
         $this->_whereTables['civicrm_group_contact'] = $this->_tables['civicrm_group_contact'];
         return implode(' OR ', $ssWhere);
     }
     return null;
 }