Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/unacms/una
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Dec 17, 2024
2 parents b1e8906 + a02e9cf commit 294c9a3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
77 changes: 70 additions & 7 deletions inc/classes/BxDolGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ protected function _getDataSql ($sFilter, $sOrderField, $sOrderDir, $iStart, $iP
return $aResults;

// add filter condition
$sQuery = $this->_modifyDataSqlWhereClause($sQuery, $sFilter, $sOrderByFilter);

// add custom filter condition and order
$sOrderByFilter = '';
$sQuery .= $this->_getDataSqlWhereClause($sFilter, $sOrderByFilter);

Expand All @@ -468,10 +471,10 @@ protected function _getDataSqlCounter($sQuery, $sFilter)
return array_sum($oDb->getColumn($sQuery));
}

protected function _getDataSqlWhereClause($sFilter, &$sOrderByFilter)
protected function _modifyDataSqlWhereClause($sQuery, $sFilter, &$sOrderByFilter)
{
if(!$sFilter || (empty($this->_aOptions['filter_fields']) && empty($this->_aOptions['filter_fields_translatable'])))
return '';
return $sQuery;

$oDb = BxDolDb::getInstance();

Expand All @@ -480,6 +483,7 @@ protected function _getDataSqlWhereClause($sFilter, &$sOrderByFilter)
$sMode = getParam('useLikeOperator') ? 'like' : 'fulltext';

$sCond = '';
$sJoin = '';
if('like' == $sMode) { // LIKE search

// condition for regular fields
Expand All @@ -495,8 +499,10 @@ protected function _getDataSqlWhereClause($sFilter, &$sOrderByFilter)

$sCondFields = rtrim($sCondFields, ' OR ');

if ($sCondFields)
$sCond .= $oDb->prepareAsString("(SELECT 1 FROM `sys_localization_strings` AS `s` INNER JOIN `sys_localization_keys` AS `k` ON (`k`.`ID` = `s`.`IDKey`) WHERE `s`.`string` LIKE ? AND ($sCondFields) LIMIT 1) OR ", '%' . $sFilter . '%');
if ($sCondFields) {
$sJoin .= " INNER JOIN `sys_localization_strings` AS `s` INNER JOIN `sys_localization_keys` AS `k` ON (`k`.`ID` = `s`.`IDKey`) ";
$sCond .= $oDb->prepareAsString("`s`.`string` LIKE ? AND ($sCondFields) ", '%' . $sFilter . '%');
}
}

$sCond = rtrim($sCond, ' OR ');
Expand Down Expand Up @@ -527,15 +533,72 @@ protected function _getDataSqlWhereClause($sFilter, &$sOrderByFilter)
foreach ($this->_aOptions['filter_fields_translatable'] as $sField)
$sCondFields .= "`k`.`Key` = `{$sField}` OR ";

$sCondFields = rtrim($sCondFields, ' OR ');
$sCondFields = rtrim($sCondFields, ',');

if ($sCondFields)
$sCond .= $oDb->prepareAsString("(SELECT 1 FROM `sys_localization_strings` AS `s` INNER JOIN `sys_localization_keys` AS `k` ON (`k`.`ID` = `s`.`IDKey`) WHERE MATCH (`s`.`string`) AGAINST (?) AND ($sCondFields) LIMIT 1) OR ", $sFilter);
if ($sCondFields) {
$sJoin .= " INNER JOIN `sys_localization_strings` AS `s` INNER JOIN `sys_localization_keys` AS `k` ON (`k`.`ID` = `s`.`IDKey`) ";
$sCond .= $oDb->prepareAsString(" (MATCH (`s`.`string`) AGAINST (?) AND ($sCondFields)) OR ", $sFilter);
}
}

$sCond = rtrim($sCond, ' OR ');
}

/**
* @hooks
* @hookdef hook-grid-get_data_by_filter 'grid', 'get_data_by_filter' - hook to override the data to be shown in the grid
* - $unit_name - equals `grid`
* - $action - equals `get_data_by_filter`
* - $object_id - not used
* - $sender_id - not used
* - $extra_params - array of additional params with the following array keys:
* - `object` - [string] grid object name
* - `options` - [array] grid options array as key&value pairs
* - `markers` - [array] markers array as key&value pairs
* - `filter` - [string] filter value
* - `browse_params` - [array] additional browse params array as key&value pairs
* - `conditions` - [string] by ref, 'where' part of SQL query in accordance with provided filter(s), can be overridden in hook processing
* @hook @ref hook-grid-get_data_by_filter
*/
bx_alert('grid', 'get_data_by_filter', 0, false, [
'object' => $this->_sObject,
'options' => $this->_aOptions,
'markers' => $this->_aMarkers,
'filter' => $sFilter,
'browse_params' => $this->_aBrowseParams,
'query' => &$sQuery,
'conditions' => &$sCond,
'join' => &$sJoin,
]);

// add WHERE for searching in translatable fields
$sQuery .= $sCond ? ' AND (' . $sCond . ')' : $sCond;

if (!empty($this->_aOptions['filter_fields_translatable'])) {

// add JOIN for searching in translatable fields
$sQuery = str_replace('WHERE', "$sJoin WHERE", $sQuery);

// change SELECT * to include table name
$sQuery = ltrim($sQuery);
if (preg_match("/^SELECT\s\*\sFROM\s`(.*?)`/i", $sQuery)) {
$sQuery = preg_replace("/^SELECT\s\*\sFROM\s`(.*?)`/i", "SELECT $1.* FROM `$1`", $sQuery);
}

// add DISTINCT for searching in translatable fields to remove duplicates
if (false === mb_stripos($sQuery, 'DISTINCT')) {
$sQuery = preg_replace('/^SELECT/i', 'SELECT DISTINCT', $sQuery);
}
}

return $sQuery;
}

protected function _getDataSqlWhereClause($sFilter, &$sOrderByFilter)
{
if(!$sFilter || (empty($this->_aOptions['filter_fields']) && empty($this->_aOptions['filter_fields_translatable'])))
return '';

/**
* @hooks
* @hookdef hook-grid-get_data_by_filter 'grid', 'get_data_by_filter' - hook to override the data to be shown in the grid
Expand Down
1 change: 1 addition & 0 deletions modules/base/profile/classes/BxBaseModProfileModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,7 @@ public function decodeDataAPI($aData, $aParams = [])
if(getParam('sys_api_conn_in_prof_units') == 'on' && $oProfile !== false) {
$iProfileId = $oProfile->id();
$aResult['title'] = $oProfile->getDisplayName();
$aResult['online'] = $oProfile->isOnline();
if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends')) !== false && isset($CNF['URI_VIEW_FRIENDS'])) {
$aResult['friends_count'] = $oConnection->getConnectedContentCount($iProfileId, true);
$aResult['friends_list'] = $oConnection->getConnectedListAPI($iProfileId, true, BX_CONNECTIONS_CONTENT_TYPE_CONTENT);
Expand Down
5 changes: 3 additions & 2 deletions template/scripts/BxBasePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ public function getPageAPI ($aBlocks = [])
'get_avatar' => 'getAvatarBig',
'with_info' => true
]);

$oProfile = BxDolProfile::getInstance($this->_aProfileInfo['id']);
$aProfileInfo['online'] = $oProfile->isOnline();
unset($aProfileInfo['info']['profile_email']);
unset($aProfileInfo['info']['profile_last_active']);
unset($aProfileInfo['info']['profile_ip']);
Expand All @@ -577,7 +578,7 @@ public function getPageAPI ($aBlocks = [])
'profile' => $aProfileInfo,
'actions_menu' => '',
'meta_menu' => '',
'badges' => BxDolProfile::getInstance($this->_aProfileInfo['id'])->getBadges(),
'badges' => $oProfile->getBadges(),
'cover' => $oProfileModule->serviceGetCover($this->_aProfileInfo['content_id']),
'allow_edit' => $oProfileModule->checkAllowedChangeCover($aProfileContentInfo) === CHECK_ACTION_RESULT_ALLOWED
];
Expand Down

0 comments on commit 294c9a3

Please sign in to comment.