Skip to content

Commit

Permalink
Further changes to sync with 4.7
Browse files Browse the repository at this point in the history
The changes affect 2 function signatures but in minor ways and add 2 functions
  • Loading branch information
eileenmcnaughton committed May 8, 2016
1 parent 62829d5 commit 04b6108
Showing 1 changed file with 58 additions and 7 deletions.
65 changes: 58 additions & 7 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
| |
Expand All @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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_]
*
Expand Down

0 comments on commit 04b6108

Please sign in to comment.