<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.7 |
+ | CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017 |
+ | Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* All DAO classes should inherit from this class.
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
*/
if (!defined('DB_DSN_MODE')) {
return $_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5];
}
+ /**
+ * Disables usage of the ONLY_FULL_GROUP_BY Mode if necessary
+ */
+ public static function disableFullGroupByMode() {
+ $currentModes = CRM_Utils_SQL::getSqlModes();
+ if (in_array('ONLY_FULL_GROUP_BY', $currentModes) && CRM_Utils_SQL::isGroupByModeInDefault()) {
+ $key = array_search('ONLY_FULL_GROUP_BY', $currentModes);
+ unset($currentModes[$key]);
+ CRM_Core_DAO::executeQuery("SET SESSION sql_mode = %1", array(1 => array(implode(',', $currentModes), 'String')));
+ }
+ }
+
+ /**
+ * Re-enables ONLY_FULL_GROUP_BY sql_mode as necessary..
+ */
+ public static function reenableFullGroupByMode() {
+ $currentModes = CRM_Utils_SQL::getSqlModes();
+ if (!in_array('ONLY_FULL_GROUP_BY', $currentModes) && CRM_Utils_SQL::isGroupByModeInDefault()) {
+ $currentModes[] = 'ONLY_FULL_GROUP_BY';
+ CRM_Core_DAO::executeQuery("SET SESSION sql_mode = %1", array(1 => array(implode(',', $currentModes), 'String')));
+ }
+ }
+
/**
* @param string $fieldName
* @param $fieldDef
*
* @param $componentIDs
* @param string $tableName
+ * @param string $idField
*
* @return array
*/
- public static function &getContactIDsFromComponent(&$componentIDs, $tableName) {
+ public static function getContactIDsFromComponent($componentIDs, $tableName, $idField = 'id') {
$contactIDs = array();
if (empty($componentIDs)) {
$query = "
SELECT contact_id
FROM $tableName
- WHERE id IN ( $IDs )
+ WHERE $idField IN ( $IDs )
";
$dao = CRM_Core_DAO::executeQuery($query);