<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
*
* @var int
*/
- CONST
+ const
MODE_CONTACTS = 1,
MODE_CONTRIBUTE = 2,
MODE_MEMBER = 8,
* Function which actually does all the work for the constructor
*
* @return void
- * @access private
*/
- function initialize() {
+ public function initialize() {
$this->_select = array();
$this->_element = array();
$this->_tables = array();
$this->openedSearchPanes(TRUE);
}
- function buildParamsLookup() {
+ public function buildParamsLookup() {
// first fix and handle contact deletion nicely
// this code is primarily for search builder use case
// where different clauses can specify if they want deleted
* hack to make them part of the query
*
* @return void
- * @access public
*/
- function addSpecialFields() {
+ public function addSpecialFields() {
static $special = array('contact_type', 'contact_sub_type', 'sort_name', 'display_name');
foreach ($special as $name) {
if (!empty($this->_returnProperties[$name])) {
* in the params list
*
* @return void
- * @access public
*/
- function selectClause() {
+ public function selectClause() {
$this->addSpecialFields();
* the return values
*
* @return void
- * @access public
*/
- function addHierarchicalElements() {
+ public function addHierarchicalElements() {
if (empty($this->_returnProperties['location'])) {
return;
}
* the return values
*
* @return void
- * @access public
*/
- function addMultipleElements() {
+ public function addMultipleElements() {
if (empty($this->_returnProperties['website'])) {
return;
}
* @param boolean $onlyDeleted
*
* @return array sql query parts as an array
- * @access public
*/
- function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALSE, $onlyDeleted = FALSE) {
+ public function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALSE, $onlyDeleted = FALSE) {
// build permission clause
$this->generatePermissionClause($onlyDeleted, $count);
*
* @return null
*/
- function &getWhereValues($name, $grouping) {
+ public function &getWhereValues($name, $grouping) {
$result = NULL;
foreach ($this->_params as $values) {
if ($values[0] == $name && $values[3] == $grouping) {
* @param $from
* @param $to
*/
- static function fixDateValues($relative, &$from, &$to) {
+ public static function fixDateValues($relative, &$from, &$to) {
if ($relative) {
list($from, $to) = CRM_Utils_Date::getFromTo($relative, $from, $to);
}
*
* @return array
*/
- static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE) {
+ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE) {
$params = array();
if (empty($formValues)) {
return $params;
*
* @return array|null
*/
- static function &fixWhereValues($id, &$values, $wildcard = 0, $useEquals = FALSE) {
+ public static function &fixWhereValues($id, &$values, $wildcard = 0, $useEquals = FALSE) {
// skip a few search variables
static $skipWhere = NULL;
static $likeNames = NULL;
/**
* @param $values
*/
- function whereClauseSingle(&$values) {
+ public function whereClauseSingle(&$values) {
// do not process custom fields or prefixed contact ids or component params
if (CRM_Core_BAO_CustomField::getKeyID($values[0]) ||
(substr($values[0], 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) ||
* where clause
*
* @return string
- * @access public
*/
- function whereClause() {
+ public function whereClause() {
$this->_where[0] = array();
$this->_qill[0] = array();
*
* @throws Exception
*/
- function restWhere(&$values) {
+ public function restWhere(&$values) {
$name = CRM_Utils_Array::value(0, $values);
$op = CRM_Utils_Array::value(1, $values);
$value = CRM_Utils_Array::value(2, $values);
* @return array
* @throws Exception
*/
- static function getLocationTableName(&$where, &$locType) {
+ public static function getLocationTableName(&$where, &$locType) {
if (isset($locType[1]) && is_numeric($locType[1])) {
list($tbName, $fldName) = explode(".", $where);
*
* @return array values for this query
*/
- function store($dao) {
+ public function store($dao) {
$value = array();
foreach ($this->_element as $key => $dontCare) {
* Getter for tables array
*
* @return array
- * @access public
*/
- function tables() {
+ public function tables() {
return $this->_tables;
}
* logic may have eroded
* @return array
*/
- function whereTables() {
+ public function whereTables() {
return $this->_whereTables;
}
* @param boolean $strict
*
* @return string
- * @access public
* @static
*/
- static function getWhereClause($params, $fields, &$tables, &$whereTables, $strict = FALSE) {
+ public static function getWhereClause($params, $fields, &$tables, &$whereTables, $strict = FALSE) {
$query = new CRM_Contact_BAO_Query($params, NULL, $fields,
FALSE, $strict
);
* @param int $mode
*
* @return string the from clause
- * @access public
* @static
*/
- static function fromClause(&$tables, $inner = NULL, $right = NULL, $primaryLocation = TRUE, $mode = 1) {
+ public static function fromClause(&$tables, $inner = NULL, $right = NULL, $primaryLocation = TRUE, $mode = 1) {
$from = ' FROM civicrm_contact contact_a';
if (empty($tables)) {
*
* @return void
*/
- function deletedContacts($values) {
+ public function deletedContacts($values) {
list($_, $_, $value, $grouping, $_) = $values;
if ($value) {
// *prepend* to the relevant grouping as this is quite an important factor
* @param $values
*
* @return void
- * @access public
*/
- function contactType(&$values) {
+ public function contactType(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$subTypes = array();
* @param $values
*
* @return void
- * @access public
*/
- function contactSubType(&$values) {
+ public function contactSubType(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
- $this->includeContactSubTypes($value, $grouping);
+ $this->includeContactSubTypes($value, $grouping, $op);
}
/**
* @param $value
* @param $grouping
*/
- function includeContactSubTypes($value, $grouping) {
+ public function includeContactSubTypes($value, $grouping, $op = 'LIKE') {
$clause = array();
$alias = "contact_a.contact_sub_type";
+ $qillOperators = array('NOT LIKE' => ts('Not Like')) + CRM_Core_SelectValues::getSearchBuilderOperators();
- if (is_array($value)) {
+ $op = str_replace('IN', 'LIKE', $op);
+ $op = str_replace('=', 'LIKE', $op);
+ $op = str_replace('!', 'NOT ', $op);
+
+ if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) {
+ $this->_where[$grouping][] = self::buildClause($alias, $op, $value, 'String');
+ }
+ else if (is_array($value)) {
foreach ($value as $k => $v) {
if (!empty($k)) {
- $clause[$k] = "($alias like '%" . CRM_Core_DAO::VALUE_SEPARATOR . CRM_Utils_Type::escape($k, 'String') . CRM_Core_DAO::VALUE_SEPARATOR . "%')";
+ $clause[$k] = "($alias $op '%" . CRM_Core_DAO::VALUE_SEPARATOR . CRM_Utils_Type::escape($k, 'String') . CRM_Core_DAO::VALUE_SEPARATOR . "%')";
}
}
}
else {
- $clause[$value] = "($alias like '%" . CRM_Core_DAO::VALUE_SEPARATOR . CRM_Utils_Type::escape($value, 'String') . CRM_Core_DAO::VALUE_SEPARATOR . "%')";
+ $clause[$value] = "($alias $op '%" . CRM_Core_DAO::VALUE_SEPARATOR . CRM_Utils_Type::escape($value, 'String') . CRM_Core_DAO::VALUE_SEPARATOR . "%')";
}
if (!empty($clause)) {
$this->_where[$grouping][] = "( " . implode(' OR ', $clause) . " )";
- $this->_qill[$grouping][] = ts('Contact Subtype') . ' - ' . implode(' ' . ts('or') . ' ', array_keys($clause));
}
+ $this->_qill[$grouping][] = ts('Contact Subtype %1 ', array(1 => $qillOperators[$op])) . implode(' ' . ts('or') . ' ', array_keys($clause));
}
/**
* @param $values
*
* @return void
- * @access public
*/
- function group(&$values) {
+ public function group(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (count($value) > 1) {
*
* @return array
*/
- function getGroupsFromTypeCriteria($value){
+ public function getGroupsFromTypeCriteria($value){
$groupIds = array();
foreach ($value as $groupTypeValue) {
$groupList = CRM_Core_PseudoConstant::group($groupTypeValue);
* @param $values
*
* @return string|NULL
- * @access public
*/
- function savedSearch(&$values) {
+ public function savedSearch(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
return $this->addGroupContactCache(array_keys($value));
}
*
* @return null|string
*/
- function addGroupContactCache($groups, $tableAlias = NULL, $joinTable = "contact_a") {
+ public function addGroupContactCache($groups, $tableAlias = NULL, $joinTable = "contact_a") {
$config = CRM_Core_Config::singleton();
// Find all the groups that are part of a saved search.
$groupIDsFiltered = implode(',', $groupsFiltered);
if ($tableAlias == NULL) {
- $tableAlias = "civicrm_group_contact_cache_{$groupIDsFiltered}";
+ $tableAlias = "`civicrm_group_contact_cache_{$groupIDsFiltered}`";
}
- $this->_tables[$tableAlias] = $this->_whereTables[$tableAlias] = " LEFT JOIN civicrm_group_contact_cache `{$tableAlias}` ON {$joinTable}.id = `{$tableAlias}`.contact_id ";
+ $this->_tables[$tableAlias] = $this->_whereTables[$tableAlias] = " LEFT JOIN civicrm_group_contact_cache {$tableAlias} ON {$joinTable}.id = {$tableAlias}.contact_id ";
- return "`{$tableAlias}`.group_id IN (" . $groupIDsFiltered . ")";
+ return "{$tableAlias}.group_id IN (" . $groupIDsFiltered . ")";
}
return NULL;
* @param $values
*
* @return void
- * @access public
*/
- function ufUser(&$values) {
+ public function ufUser(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if ($value == 1) {
* @param $values
*
* @return void
- * @access public
*/
- function tagSearch(&$values) {
+ public function tagSearch(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$op = "LIKE";
* @param $values
*
* @return void
- * @access public
*/
- function tag(&$values) {
+ public function tag(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$tagNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
* @param $values
*
* @return void
- * @access public
*/
- function notes(&$values) {
+ public function notes(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$noteOptionValues = $this->getWhereValues('note_option', $grouping);
*
* @return bool
*/
- function nameNullOrEmptyOp($name, $op, $grouping) {
+ public function nameNullOrEmptyOp($name, $op, $grouping) {
switch ( $op ) {
case 'IS NULL':
case 'IS NOT NULL':
* @param $values
*
* @return void
- * @access public
*/
- function sortName(&$values) {
+ public function sortName(&$values) {
list($fieldName, $op, $value, $grouping, $wildcard) = $values;
// handle IS NULL / IS NOT NULL / IS EMPTY / IS NOT EMPTY
* @param $values
*
* @return void
- * @access public
*/
- function email(&$values) {
+ public function email(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$n = trim($value);
* @param $values
*
* @return void
- * @access public
*/
- function phone_numeric(&$values) {
+ public function phone_numeric(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
// Strip non-numeric characters; allow wildcards
$number = preg_replace('/[^\d%]/', '', $value);
* @param $values
*
* @return void
- * @access public
*/
- function phone_option_group($values) {
+ public function phone_option_group($values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$option = ($name == 'phone_phone_type_id' ? 'phone_type_id' : 'location_type_id');
$options = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', $option);
* @param $values
*
* @return void
- * @access public
*/
- function street_address(&$values) {
+ public function street_address(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (!$op) {
* @param $values
*
* @return void
- * @access public
*/
- function street_number(&$values) {
+ public function street_number(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (!$op) {
* @param $values
*
* @return void
- * @access public
*/
- function sortByCharacter(&$values) {
+ public function sortByCharacter(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$name = trim($value);
* Where / qill clause for including contact ids
*
* @return void
- * @access public
*/
- function includeContactIDs() {
+ public function includeContactIDs() {
if (!$this->_includeContactIds || empty($this->_params)) {
return;
}
* @param $values
*
* @return void
- * @access public
*/
- function postalCode(&$values) {
+ public function postalCode(&$values) {
// skip if the fields dont have anything to do with postal_code
if (empty($this->_fields['postal_code'])) {
return;
* @param null $status
*
* @return void
- * @access public
*/
- function locationType(&$values, $status = NULL) {
+ public function locationType(&$values, $status = NULL) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (is_array($value)) {
*
* @return array
*/
- function country(&$values, $fromStateProvince = TRUE) {
+ public function country(&$values, $fromStateProvince = TRUE) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (!$fromStateProvince) {
* @param null $status
*
* @return void
- * @access public
*/
- function county(&$values, $status = null) {
+ public function county(&$values, $status = null) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (! is_array($value)) {
* @param null $status
*
* @return void
- * @access public
*/
- function stateProvince(&$values, $status = NULL) {
+ public function stateProvince(&$values, $status = NULL) {
list($name, $op, $value, $grouping, $wildcard) = $values;
// quick escape for IS NULL
* @param $values
*
* @return void
- * @access public
*/
- function changeLog(&$values) {
+ public function changeLog(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$targetName = $this->getWhereValues('changed_by', $grouping);
/**
* @param $values
*/
- function modifiedDates($values) {
+ public function modifiedDates($values) {
$this->_useDistinct = TRUE;
// CRM-11281, default to added date if not set
/**
* @param $values
*/
- function demographics(&$values) {
+ public function demographics(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (($name == 'birth_date_low') || ($name == 'birth_date_high')) {
/**
* @param $values
*/
- function privacy(&$values) {
+ public function privacy(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
//fixed for profile search listing CRM-4633
if (strpbrk($value, "[")) {
/**
* @param $values
*/
- function privacyOptions($values) {
+ public function privacyOptions($values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if (empty($value) || !is_array($value)) {
/**
* @param $values
*/
- function preferredCommunication(&$values) {
+ public function preferredCommunication(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$pref = array();
* @param $values
*
* @return void
- * @access public
*/
- function relationship(&$values) {
+ public function relationship(&$values) {
list($name, $op, $value, $grouping, $wildcard) = $values;
if ($this->_relationshipValuesAdded){
return;
* @param array $where = array to add where clauses to, in case you are generating a temp table
* not the main query.
*/
- function addRelationshipDateClauses($grouping, &$where){
+ public function addRelationshipDateClauses($grouping, &$where){
$dateValues = array();
$dateTypes = array(
'start_date',
* @param int $mode
*
* @return array derault return properties
- * @access public
*/
- static function &defaultReturnProperties($mode = 1) {
+ public static function &defaultReturnProperties($mode = 1) {
if (!isset(self::$_defaultReturnProperties)) {
self::$_defaultReturnProperties = array();
}
* @param int $value
*
* @return string|NULL
- * @access public
*/
- static function getPrimaryCondition($value) {
+ public static function getPrimaryCondition($value) {
if (is_numeric($value)) {
$value = (int ) $value;
return ($value == 1) ? 'is_primary = 1' : 'is_primary = 0';
* @param bool $count
*
* @return string
- * @access public
*/
- static function getQuery($params = NULL, $returnProperties = NULL, $count = FALSE) {
+ public static function getQuery($params = NULL, $returnProperties = NULL, $count = FALSE) {
$query = new CRM_Contact_BAO_Query($params, $returnProperties);
list($select, $from, $where, $having) = $query->query();
*
*
* @return array
- * @access public
*/
static function apiQuery(
$params = NULL,
* @param bool $skipOrderAndLimit
*
* @return CRM_Core_DAO
- * @access public
*/
function searchQuery(
$offset = 0, $rowCount = 0, $sort = NULL,
* @param bool $includeContactIds
* @return CRM_Core_DAO
*/
- function getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds) {
+ public function getCachedContacts($cacheKey, $offset, $rowCount, $includeContactIds) {
$this->_includeContactIds = $includeContactIds;
$onlyDeleted = in_array(array('deleted_contacts', '=', '1', '0', '0'), $this->_params);
list($select, $from, $where) = $this->query(FALSE, FALSE, FALSE, $onlyDeleted);
*
* @return null
*/
- function generatePermissionClause($onlyDeleted = FALSE, $count = FALSE) {
+ public function generatePermissionClause($onlyDeleted = FALSE, $count = FALSE) {
if (!$this->_skipPermission) {
$this->_permissionWhereClause = CRM_ACL_API::whereClause(
CRM_Core_Permission::VIEW,
/**
* @param $val
*/
- function setSkipPermission($val) {
+ public function setSkipPermission($val) {
$this->_skipPermission = $val;
}
*
* @return array
*/
- function &summaryContribution($context = NULL) {
+ public function &summaryContribution($context = NULL) {
list($innerselect, $from, $where, $having) = $this->query(TRUE);
// hack $select
* Getter for the qill object
*
* @return string
- * @access public
*/
- function qill() {
+ public function qill() {
return $this->_qill;
}
* Default set of return default hier return properties
*
* @return array
- * @access public
*/
- static function &defaultHierReturnProperties() {
+ public static function &defaultHierReturnProperties() {
if (!isset(self::$_defaultHierReturnProperties)) {
self::$_defaultHierReturnProperties = array(
'home_URL' => 1,
* @param string $dataType data type of the field
*
* @return string where clause for the query
- * @access public
*/
- static function buildClause($field, $op, $value = NULL, $dataType = NULL) {
+ public static function buildClause($field, $op, $value = NULL, $dataType = NULL) {
$op = trim($op);
$clause = "$field $op";
*
* @return array
*/
- function openedSearchPanes($reset = FALSE) {
+ public function openedSearchPanes($reset = FALSE) {
if (!$reset || empty($this->_whereTables)) {
return self::$_openedPanes;
}
/**
* @param $operator
*/
- function setOperator($operator) {
+ public function setOperator($operator) {
$validOperators = array('AND', 'OR');
if (!in_array($operator, $validOperators)) {
$operator = 'AND';
/**
* @return string
*/
- function getOperator() {
+ public function getOperator() {
return $this->_operator;
}
* @param $where
* @param $having
*/
- function filterRelatedContacts(&$from, &$where, &$having) {
+ public function filterRelatedContacts(&$from, &$where, &$having) {
static $_rTypeProcessed = NULL;
static $_rTypeFrom = NULL;
static $_rTypeWhere = NULL;
*
* @return bool
*/
- static function caseImportant( $op ) {
+ public static function caseImportant( $op ) {
return
in_array($op, array('LIKE', 'IS NULL', 'IS NOT NULL', 'IS EMPTY', 'IS NOT EMPTY')) ? FALSE : TRUE;
}
*
* @return bool
*/
- static function componentPresent( &$returnProperties, $prefix ) {
+ public static function componentPresent( &$returnProperties, $prefix ) {
foreach ($returnProperties as $name => $dontCare ) {
if (substr($name, 0, strlen($prefix)) == $prefix) {
return TRUE;
* array of numeric values if string does match the pattern
* @static
*/
- static function parseSearchBuilderString($string, $dataType = 'Integer') {
+ public static function parseSearchBuilderString($string, $dataType = 'Integer') {
$string = trim($string);
if (substr($string, 0, 1) != '(' || substr($string, -1, 1) != ')') {
Return FALSE;
*
* @return array
*/
- function convertToPseudoNames(&$dao, $return = FALSE) {
+ public function convertToPseudoNames(&$dao, $return = FALSE) {
if (empty($this->_pseudoConstantsSelect)) {
return;
}
*
* @return array
*/
- function includePseudoFieldsJoin($sort) {
+ public function includePseudoFieldsJoin($sort) {
if (!$sort || empty($this->_pseudoConstantsSelect)) {
return;
}