コード例 #1
0
 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=MyISAM";
         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)) {
                     $ssGroup = new CRM_Contact_DAO_Group();
                     $ssGroup->id = $values;
                     if (!$ssGroup->find(TRUE)) {
                         CRM_Core_Error::fatal();
                     }
                     CRM_Contact_BAO_GroupContactCache::load($ssGroup);
                     $smartSql = "\nSELECT gcc.contact_id\nFROM   civicrm_group_contact_cache gcc\nWHERE  gcc.group_id = {$ssGroup->id}\n";
                     $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=MyISAM";
         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)) {
                 $ssGroup = new CRM_Contact_DAO_Group();
                 $ssGroup->id = $values;
                 if (!$ssGroup->find(TRUE)) {
                     CRM_Core_Error::fatal();
                 }
                 CRM_Contact_BAO_GroupContactCache::load($ssGroup);
                 $smartSql = "\nSELECT gcc.contact_id\nFROM   civicrm_group_contact_cache gcc\nWHERE  gcc.group_id = {$ssGroup->id}\n";
                 //used only when exclude group is selected
                 if ($xGroups != 0) {
                     $smartSql .= " AND gcc.contact_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
             $iTags = NULL;
         }
         if (is_array($this->_excludeTags)) {
             $xTags = implode(',', $this->_excludeTags);
         } else {
             $xTags = 0;
         }
         $sql = "CREATE TEMPORARY TABLE Xt_{$this->_tableName} ( contact_id int primary key) ENGINE=MyISAM";
         CRM_Core_DAO::executeQuery($sql);
         //used only when exclude tag is selected
         if ($xTags != 0) {
             $excludeTag = "INSERT INTO  Xt_{$this->_tableName} ( contact_id )\n                  SELECT  DISTINCT civicrm_entity_tag.entity_id\n                  FROM civicrm_entity_tag, civicrm_contact\n                  WHERE\n                     civicrm_entity_tag.entity_table = 'civicrm_contact' AND\n                     civicrm_contact.id = civicrm_entity_tag.entity_id AND\n                     civicrm_entity_tag.tag_id IN( {$xTags})";
             CRM_Core_DAO::executeQuery($excludeTag);
         }
         $sql = "CREATE TEMPORARY TABLE It_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,\n                                                               contact_id int,\n                                                               tag_names varchar(64)) ENGINE=MyISAM";
         CRM_Core_DAO::executeQuery($sql);
         if ($iTags) {
             $includeTag = "INSERT INTO It_{$this->_tableName} (contact_id, tag_names)\n                 SELECT              civicrm_contact.id as contact_id, civicrm_tag.name as tag_name\n                 FROM                civicrm_contact\n                    INNER JOIN       civicrm_entity_tag\n                            ON       ( civicrm_entity_tag.entity_table = 'civicrm_contact' AND\n                                       civicrm_entity_tag.entity_id = civicrm_contact.id )\n                    LEFT JOIN        civicrm_tag\n                            ON       civicrm_entity_tag.tag_id = civicrm_tag.id";
         } else {
             $includeTag = "INSERT INTO It_{$this->_tableName} (contact_id, tag_names)\n                 SELECT              civicrm_contact.id as contact_id, ''\n                 FROM                civicrm_contact";
         }
         //used only when exclude tag is selected
         if ($xTags != 0) {
             $includeTag .= " LEFT JOIN        Xt_{$this->_tableName}\n                                       ON       civicrm_contact.id = Xt_{$this->_tableName}.contact_id";
         }
         if ($iTags) {
             $includeTag .= " WHERE   civicrm_entity_tag.tag_id IN({$iTags})";
         } else {
             $includeTag .= " WHERE ( 1 ) ";
         }
         //used only when exclude tag is selected
         if ($xTags != 0) {
             $includeTag .= " AND  Xt_{$this->_tableName}.contact_id IS null";
         }
         CRM_Core_DAO::executeQuery($includeTag);
     }
     $from = " FROM civicrm_contact contact_a";
     /*
      * CRM-10850 / CRM-10848
      * If we use include / exclude groups as smart groups for ACL's having the below causes
      * a cycle which messes things up. Hence commenting out for now
      * $this->buildACLClause('contact_a');
      */
     /*
      * check the situation and set booleans
      */
     $Ig = $iGroups != 0;
     $It = $iTags != 0;
     $Xg = $xGroups != 0;
     $Xt = $xTags != 0;
     //PICK UP FROM HERE
     if (!$this->_groups && !$this->_tags) {
         $this->_andOr = 1;
     }
     /*
      * Set from statement depending on array sel
      */
     $whereitems = array();
     foreach (array('Ig', 'It') as $inc) {
         if ($this->_andOr == 1) {
             if (${$inc}) {
                 $from .= " INNER JOIN {$inc}_{$this->_tableName} temptable{$inc} ON (contact_a.id = temptable{$inc}.contact_id)";
             }
         } else {
             if (${$inc}) {
                 $from .= " LEFT JOIN {$inc}_{$this->_tableName} temptable{$inc} ON (contact_a.id = temptable{$inc}.contact_id)";
             }
         }
         if (${$inc}) {
             $whereitems[] = "temptable{$inc}.contact_id IS NOT NULL";
         }
     }
     $this->_where = $whereitems ? "(" . implode(' OR ', $whereitems) . ')' : '(1)';
     foreach (array('Xg', 'Xt') as $exc) {
         if (${$exc}) {
             $from .= " LEFT JOIN {$exc}_{$this->_tableName} temptable{$exc} ON (contact_a.id = temptable{$exc}.contact_id)";
             $this->_where .= " AND temptable{$exc}.contact_id IS NULL";
         }
     }
     $from .= " LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id AND ( civicrm_email.is_primary = 1 OR civicrm_email.is_bulkmail = 1 ) ) {$this->_aclFrom}";
     if ($this->_aclWhere) {
         $this->_where .= " AND {$this->_aclWhere} ";
     }
     // also exclude all contacts that are deleted
     // CRM-11627
     $this->_where .= " AND (contact_a.is_deleted != 1) ";
     return $from;
 }
コード例 #2
0
ファイル: Tag.php プロジェクト: kcristiano/civicrm-core
 /**
  * Takes an associative array and creates a contact object.
  *
  * The function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  * @param array $ids
  *   (optional) the array that holds all the db ids - we are moving away from this in bao.
  * signatures
  *
  * @return object
  *   CRM_Core_DAO_Tag object on success, otherwise null
  */
 public static function add(&$params, $ids = array())
 {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('tag', $ids));
     if (!$id && !self::dataExists($params)) {
         return NULL;
     }
     $tag = new CRM_Core_DAO_Tag();
     // if parent id is set then inherit used for and is hidden properties
     if (!empty($params['parent_id'])) {
         // get parent details
         $params['used_for'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $params['parent_id'], 'used_for');
     }
     $tag->copyValues($params);
     $tag->id = $id;
     $hook = !$id ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'Tag', $tag->id, $params);
     // save creator id and time
     if (!$tag->id) {
         $session = CRM_Core_Session::singleton();
         $tag->created_id = $session->get('userID');
         $tag->created_date = date('YmdHis');
     }
     $tag->save();
     CRM_Utils_Hook::post($hook, 'Tag', $tag->id, $tag);
     // if we modify parent tag, then we need to update all children
     if ($tag->parent_id === 'null') {
         CRM_Core_DAO::executeQuery("UPDATE civicrm_tag SET used_for=%1 WHERE parent_id = %2", array(1 => array($params['used_for'], 'String'), 2 => array($tag->id, 'Integer')));
     }
     return $tag;
 }
コード例 #3
0
ファイル: Group.php プロジェクト: hampelm/Ginsberg-CiviDemo
 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 {
             //if no group selected search for all groups
             $iTags = null;
         }
         if (is_array($this->_excludeTags)) {
             $xTags = implode(',', $this->_excludeTags);
         } else {
             $xTags = 0;
         }
         $sql = "CREATE TEMPORARY TABLE Xt_{$this->_tableName} ( contact_id int primary key) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql);
         //used only when exclude tag is selected
         if ($xTags != 0) {
             $excludeTag = "INSERT INTO  Xt_{$this->_tableName} ( contact_id )\n                  SELECT  DISTINCT civicrm_entity_tag.entity_id\n                  FROM civicrm_entity_tag, civicrm_contact                    \n                  WHERE \n                     civicrm_entity_tag.entity_table = 'civicrm_contact' AND\n                     civicrm_contact.id = civicrm_entity_tag.entity_id AND \n                     civicrm_entity_tag.tag_id IN( {$xTags})";
             CRM_Core_DAO::executeQuery($excludeTag);
         }
         $sql = "CREATE TEMPORARY TABLE It_{$this->_tableName} ( id int PRIMARY KEY AUTO_INCREMENT,\n                                                               contact_id int,\n                                                               tag_names varchar(64)) ENGINE=HEAP";
         CRM_Core_DAO::executeQuery($sql);
         if ($iTags) {
             $includeTag = "INSERT INTO It_{$this->_tableName} (contact_id, tag_names)\n                 SELECT              civicrm_contact.id as contact_id, civicrm_tag.name as tag_name\n                 FROM                civicrm_contact\n                    INNER JOIN       civicrm_entity_tag\n                            ON       ( civicrm_entity_tag.entity_table = 'civicrm_contact' AND\n                                       civicrm_entity_tag.entity_id = civicrm_contact.id )\n                    LEFT JOIN        civicrm_tag\n                            ON       civicrm_entity_tag.tag_id = civicrm_tag.id";
         } else {
             $includeTag = "INSERT INTO It_{$this->_tableName} (contact_id, tag_names)\n                 SELECT              civicrm_contact.id as contact_id, ''\n                 FROM                civicrm_contact";
         }
         //used only when exclude tag is selected
         if ($xTags != 0) {
             $includeTag .= " LEFT JOIN        Xt_{$this->_tableName}\n                                       ON       civicrm_contact.id = Xt_{$this->_tableName}.contact_id";
         }
         if ($iTags) {
             $includeTag .= " WHERE   civicrm_entity_tag.tag_id IN({$iTags})";
         } else {
             $includeTag .= " WHERE ( 1 ) ";
         }
         //used only when exclude tag is selected
         if ($xTags != 0) {
             $includeTag .= " AND  Xt_{$this->_tableName}.contact_id IS null";
         }
         CRM_Core_DAO::executeQuery($includeTag);
     }
     $from = " FROM civicrm_contact contact_a";
     /*
      * check the situation and set booleans
      */
     if ($iGroups != 0) {
         $iG = true;
     } else {
         $iG = false;
     }
     if ($iTags != 0) {
         $iT = true;
     } else {
         $iT = false;
     }
     if ($xGroups != 0) {
         $xG = true;
     } else {
         $xG = false;
     }
     if ($xTags != 0) {
         $xT = true;
     } else {
         $xT = false;
     }
     if (!$this->_groups || !$this->_tags) {
         $this->_andOr = 1;
     }
     /*
      * Set from statement depending on array sel
      */
     if ($iG && $iT && $xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " INNER JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL )\n                    AND contact_a.id NOT IN(SELECT contact_id FROM Xg_{$this->_tableName})\n                    AND contact_a.id NOT IN(SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable3 ON (contact_a.id = temptable3.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable4 ON (contact_a.id = temptable4.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL OR\n                    temptable3.contact_id IS NOT NULL OR temptable4.contact_id IS NOT NULL)";
         }
     }
     if ($iG && $iT && $xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " INNER JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL )\n                    AND contact_a.id NOT IN(SELECT contact_id FROM Xg_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable3 ON (contact_a.id = temptable3.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL OR\n                    temptable3.contact_id IS NOT NULL)";
         }
     }
     if ($iG && $iT && !$xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " INNER JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL )\n                    AND contact_a.id NOT IN(SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable3 ON (contact_a.id = temptable3.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL OR\n                    temptable3.contact_id IS NOT NULL)";
         }
     }
     if ($iG && $iT && !$xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " INNER JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL )";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if ($iG && !$iT && $xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xg_{$this->_tableName}) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable3 ON (contact_a.id = temptable3.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL OR\n                    temptable3.contact_id IS NOT NULL)";
         }
     }
     if ($iG && !$iT && $xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xg_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if ($iG && !$iT && !$xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if ($iG && !$iT && !$xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL)";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && $iT && $xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xg_{$this->_tableName}) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable3 ON (contact_a.id = temptable3.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL OR\n                    temptable3.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && $iT && $xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xg_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && $iT && !$xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL) AND contact_a.id NOT IN(\n                    SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && $iT && !$xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL)";
         } else {
             $from .= " LEFT JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && !$iT && $xG && $xT) {
         if ($this->_andOr == 1) {
             $this->_where = "contact_a.id NOT IN(SELECT contact_id FROM Xg_{$this->_tableName})\n                    AND contact_a.id NOT IN(SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && !$iT && !$xG && $xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN It_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "contact_a.id NOT IN(SELECT contact_id FROM Xt_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Xt_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN It_{$this->_tableName} temptable2 ON (contact_a.id = temptable2.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL OR temptable2.contact_id IS NOT NULL)";
         }
     }
     if (!$iG && !$iT && $xG && !$xT) {
         if ($this->_andOr == 1) {
             $from .= " INNER JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "contact_a.id NOT IN(SELECT contact_id FROM Xg_{$this->_tableName})";
         } else {
             $from .= " LEFT JOIN Ig_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $from .= " LEFT JOIN Xg_{$this->_tableName} temptable1 ON (contact_a.id = temptable1.contact_id)";
             $this->_where = "( temptable1.contact_id IS NOT NULL)";
         }
     }
     $from .= " LEFT JOIN civicrm_email ON ( contact_a.id = civicrm_email.contact_id AND ( civicrm_email.is_primary = 1 OR civicrm_email.is_bulkmail = 1 ) )";
     return $from;
 }
コード例 #4
0
ファイル: Tag.php プロジェクト: bhirsch/voipdev
 /**
  * class constructor
  */
 function __construct()
 {
     parent::__construct();
 }
コード例 #5
0
ファイル: Tag.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields =& self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['tag'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
コード例 #6
0
ファイル: Tag.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /**
  * class constructor
  */
 function CRM_Core_BAO_Tag()
 {
     parent::CRM_Core_DAO_Tag();
 }
コード例 #7
0
ファイル: Tag.php プロジェクト: hampelm/Ginsberg-CiviDemo
 /**
  * takes an associative array and creates a contact object
  * 
  * The function extract all the params it needs to initialize the create a
  * contact object. the params array could contain additional unused name/value
  * pairs
  * 
  * @param array  $params         (reference) an assoc array of name/value pairs
  * @param array  $ids            (reference) the array that holds all the db ids
  * 
  * @return object    CRM_Core_DAO_Tag object on success, otherwise null
  * @access public
  * @static
  */
 static function add(&$params, &$ids)
 {
     if (!self::dataExists($params)) {
         return null;
     }
     $tag = new CRM_Core_DAO_Tag();
     // if parent id is set then inherit used for and is hidden properties
     if (CRM_Utils_Array::value('parent_id', $params)) {
         // get parent details
         $params['used_for'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $params['parent_id'], 'used_for');
     }
     $tag->copyValues($params);
     $tag->id = CRM_Utils_Array::value('tag', $ids);
     require_once 'CRM/Utils/Hook.php';
     $edit = $tag->id ? true : false;
     if ($edit) {
         CRM_Utils_Hook::pre('edit', 'Tag', $tag->id, $tag);
     } else {
         CRM_Utils_Hook::pre('create', 'Tag', null, $tag);
     }
     $tag->save();
     if ($edit) {
         CRM_Utils_Hook::post('edit', 'Tag', $tag->id, $tag);
     } else {
         CRM_Utils_Hook::post('create', 'Tag', null, $tag);
     }
     // if we modify parent tag, then we need to update all children
     if ($tag->parent_id === 'null') {
         CRM_Core_DAO::executeQuery("UPDATE civicrm_tag SET used_for=%1 WHERE parent_id = %2", array(1 => array($params['used_for'], 'String'), 2 => array($tag->id, 'Integer')));
     }
     return $tag;
 }
コード例 #8
0
ファイル: Tag.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CORE_DAO_TAG']['_export']) {
         $GLOBALS['_CRM_CORE_DAO_TAG']['_export'] = array();
         $fields =& CRM_Core_DAO_Tag::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CORE_DAO_TAG']['_export']['tag'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CORE_DAO_TAG']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CORE_DAO_TAG']['_export'];
 }