mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Fix saving of user profile country field value (#6937)
* Fix saving of user profile country field value * Search in user profile country full name by keyword * Update CHANGELOG.md
This commit is contained in:
parent
fabee82688
commit
fbe2bf61c2
@ -5,6 +5,7 @@ HumHub Changelog
|
||||
-----------------------
|
||||
- Enh #6899: Fix a missed module config file
|
||||
- Fix #6913: Fix API tests
|
||||
- Fix #6919: Fix saving of user profile country field value and enable a searching by country title
|
||||
|
||||
1.15.4 (March 20, 2024)
|
||||
-----------------------
|
||||
|
@ -44,6 +44,15 @@ abstract class AbstractActiveQueryContentContainer extends ActiveQuery
|
||||
*/
|
||||
abstract protected function getSearchableFields(): array;
|
||||
|
||||
/**
|
||||
* Returns a list of fields with its associative array of values and titles.
|
||||
* Only values of the fields are stored in DB, so we need to do a searching
|
||||
* in titles which may be translatable, e.g. counties list.
|
||||
* If additional tables are needed, they must be added via `joinWith`.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getSearchableFieldTitles(): array;
|
||||
|
||||
/**
|
||||
* Performs a container text search
|
||||
@ -98,6 +107,19 @@ abstract class AbstractActiveQueryContentContainer extends ActiveQuery
|
||||
$conditions[] = array_merge(['OR'], $subConditions);
|
||||
}
|
||||
|
||||
$fieldTitles = $this->getSearchableFieldTitles();
|
||||
foreach ($fieldTitles as $field => $titles) {
|
||||
$valueKeys = [];
|
||||
foreach ($titles as $key => $title) {
|
||||
if (stripos($title, $keyword) === 0) {
|
||||
$valueKeys[] = $key;
|
||||
}
|
||||
}
|
||||
if ($valueKeys !== []) {
|
||||
$conditions[] = ['IN', $field, $valueKeys];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->andWhere(array_merge(['OR'], $conditions));
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,14 @@ class ActiveQuerySpace extends AbstractActiveQueryContentContainer
|
||||
return ['space.name', 'space.description', 'contentcontainer.tags_cached'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inerhitdoc
|
||||
*/
|
||||
protected function getSearchableFieldTitles(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude blocked spaces for the given $user or for the current User
|
||||
*
|
||||
|
@ -12,6 +12,8 @@ use humhub\events\ActiveQueryEvent;
|
||||
use humhub\modules\admin\permissions\ManageUsers;
|
||||
use humhub\modules\content\components\AbstractActiveQueryContentContainer;
|
||||
use humhub\modules\user\models\fieldtype\BaseTypeVirtual;
|
||||
use humhub\modules\user\models\fieldtype\CountrySelect;
|
||||
use humhub\modules\user\models\fieldtype\Select;
|
||||
use humhub\modules\user\models\Group;
|
||||
use humhub\modules\user\models\GroupUser;
|
||||
use humhub\modules\user\models\ProfileField;
|
||||
@ -130,6 +132,30 @@ class ActiveQueryUser extends AbstractActiveQueryContentContainer
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inerhitdoc
|
||||
*/
|
||||
protected function getSearchableFieldTitles(): array
|
||||
{
|
||||
$this->joinWith('profile')->joinWith('contentContainerRecord');
|
||||
|
||||
$fields = [];
|
||||
|
||||
$profileFields = ProfileField::find()
|
||||
->where(['searchable' => 1])
|
||||
->andWhere(['IN', 'field_type_class', [CountrySelect::class, Select::class]]);
|
||||
|
||||
foreach ($profileFields->all() as $profileField) {
|
||||
/* @var ProfileField $profileField */
|
||||
$fieldType = $profileField->getFieldType();
|
||||
if ($fieldType instanceof Select) {
|
||||
$fields['profile.' . $profileField->internal_name] = $fieldType->getSelectItems();
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the query to a specified user group
|
||||
*
|
||||
|
@ -59,7 +59,7 @@ class CountrySelect extends Select
|
||||
$isoCodes = Iso3166Codes::$countries;
|
||||
|
||||
foreach ($isoCodes as $code => $value) {
|
||||
$items[Iso3166Codes::country($code)] = Iso3166Codes::country($code);
|
||||
$items[$code] = Iso3166Codes::country($code);
|
||||
}
|
||||
} else {
|
||||
foreach (explode(",", $this->options) as $code) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user