From 04b61081767ee09aaf22831e745f20f55730db13 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 9 May 2016 08:23:46 +1000 Subject: [PATCH] Further changes to sync with 4.7 The changes affect 2 function signatures but in minor ways and add 2 functions --- CRM/Core/DAO.php | 65 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 02ba7a7661c6..12a920c427ec 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.6 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2015 | + | Copyright CiviCRM LLC (c) 2004-2016 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -29,7 +29,7 @@ * Our base DAO class. All DAO classes should inherit from this class. * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2015 + * @copyright CiviCRM LLC (c) 2004-2016 */ require_once 'PEAR.php'; @@ -217,8 +217,8 @@ protected function assignTestValue($fieldName, &$fieldDef, $counter) { case CRM_Utils_Type::T_TIME: CRM_Core_Error::fatal("T_TIME shouldn't be used."); - //$object->$dbName='000000'; - //break; + //$object->$dbName='000000'; + //break; case CRM_Utils_Type::T_CCNUM: $this->$dbName = '4111 1111 1111 1111'; break; @@ -1234,14 +1234,16 @@ public static function &singleValueQuery( } /** - * @param $query + * Compose the query by merging the parameters into it. + * + * @param string $query * @param array $params * @param bool $abort * * @return string * @throws Exception */ - public static function composeQuery($query, &$params, $abort = TRUE) { + public static function composeQuery($query, $params, $abort = TRUE) { $tr = array(); foreach ($params as $key => $item) { if (is_numeric($key)) { @@ -2266,7 +2268,7 @@ public function getFieldSpec($fieldName) { * a string is returned if $returnSanitisedArray is not set, otherwise and Array or NULL * depending on whether it is supported as yet */ - public static function createSQLFilter($fieldName, $filter, $type, $alias = NULL, $returnSanitisedArray = FALSE) { + public static function createSQLFilter($fieldName, $filter, $type = NULL, $alias = NULL, $returnSanitisedArray = FALSE) { foreach ($filter as $operator => $criteria) { if (in_array($operator, self::acceptedSQLOperators(), TRUE)) { switch ($operator) { @@ -2391,6 +2393,55 @@ public static function shortenSQLName($string, $length = 60, $makeRandom = FALSE public function setApiFilter(&$params) { } + /** + * Generates acl clauses suitable for adding to WHERE or ON when doing an api.get for this entity + * + * Return format is in the form of fieldname => clauses starting with an operator. e.g.: + * @code + * array( + * 'location_type_id' => array('IS NOT NULL', 'IN (1,2,3)') + * ) + * @endcode + * + * Note that all array keys must be actual field names in this entity. Use subqueries to filter on other tables e.g. custom values. + * + * @return array + */ + public function addSelectWhereClause() { + // This is the default fallback, and works for contact-related entities like Email, Relationship, etc. + $clauses = array(); + foreach ($this->fields() as $fieldName => $field) { + if (strpos($fieldName, 'contact_id') === 0 && CRM_Utils_Array::value('FKClassName', $field) == 'CRM_Contact_DAO_Contact') { + $clauses[$fieldName] = CRM_Utils_SQL::mergeSubquery('Contact'); + } + } + CRM_Utils_Hook::selectWhereClause($this, $clauses); + return $clauses; + } + + /** + * This returns the final permissioned query string for this entity + * + * With acls from related entities + additional clauses from hook_civicrm_selectWhereClause + * + * @param string $tableAlias + * @return array + */ + public static function getSelectWhereClause($tableAlias = NULL) { + $bao = new static(); + if ($tableAlias === NULL) { + $tableAlias = $bao->tableName(); + } + $clauses = array(); + foreach ((array) $bao->addSelectWhereClause() as $field => $vals) { + $clauses[$field] = NULL; + if ($vals) { + $clauses[$field] = "`$tableAlias`.`$field` " . implode(" AND `$tableAlias`.`$field` ", (array) $vals); + } + } + return $clauses; + } + /** * function to check valid db name containing only characters in [0-9,a-z,A-Z_] *