mirror of
https://github.com/friendica/friendica
synced 2025-04-26 02:30:11 +00:00
Move ProfileFieldRepository::updateCollectionFromForm()
This commit is contained in:
parent
6f692b857b
commit
f403851946
9 changed files with 320 additions and 177 deletions
|
@ -30,6 +30,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Profile\ProfileField\Collection\ProfileFields;
|
||||
use Friendica\Profile\ProfileField\Entity\ProfileField;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseSettings;
|
||||
|
@ -100,16 +101,13 @@ class Index extends BaseSettings
|
|||
$homepage = 'http://' . $homepage;
|
||||
}
|
||||
|
||||
$profileFields = DI::profileFieldNew()->selectByUserId(local_user());
|
||||
|
||||
$profileFields = DI::profileField()->updateCollectionFromForm(
|
||||
$profileFieldsNew = self::getProfileFieldsFromInput(
|
||||
local_user(),
|
||||
$profileFields,
|
||||
$_REQUEST['profile_field'],
|
||||
$_REQUEST['profile_field_order']
|
||||
);
|
||||
|
||||
DI::profileField()->saveCollection($profileFields);
|
||||
DI::profileFieldNew()->saveCollectionForUser(local_user(), $profileFieldsNew);
|
||||
|
||||
$result = Profile::update(
|
||||
[
|
||||
|
@ -265,6 +263,53 @@ class Index extends BaseSettings
|
|||
return $o;
|
||||
}
|
||||
|
||||
private static function getProfileFieldsFromInput(int $uid, array $profileFieldInputs, array $profileFieldOrder): ProfileFields
|
||||
{
|
||||
$profileFields = new ProfileFields();
|
||||
|
||||
// Returns an associative array of id => order values
|
||||
$profileFieldOrder = array_flip($profileFieldOrder);
|
||||
|
||||
// Creation of the new field
|
||||
if (!empty($profileFieldInputs['new']['label'])) {
|
||||
$permissionSet = DI::permissionSet()->selectOrCreate(DI::permissionSetFactory()->createFromString(
|
||||
$uid,
|
||||
$profileFieldInputs['new']['contact_allow'] ?? '',
|
||||
$profileFieldInputs['new']['group_allow'] ?? '',
|
||||
$profileFieldInputs['new']['contact_deny'] ?? '',
|
||||
$profileFieldInputs['new']['group_deny'] ?? ''
|
||||
));
|
||||
|
||||
$profileFields->append(DI::profileFieldFactory()->createFromString(
|
||||
$uid,
|
||||
$profileFieldOrder['new'],
|
||||
$profileFieldInputs['new']['label'],
|
||||
$profileFieldInputs['new']['value'],
|
||||
$permissionSet
|
||||
));
|
||||
}
|
||||
|
||||
foreach ($profileFieldInputs as $id => $profileFieldInput) {
|
||||
$permissionSet = DI::permissionSet()->selectOrCreate(DI::permissionSetFactory()->createFromString(
|
||||
$uid,
|
||||
$profileFieldInput['contact_allow'] ?? '',
|
||||
$profileFieldInput['group_allow'] ?? '',
|
||||
$profileFieldInput['contact_deny'] ?? '',
|
||||
$profileFieldInput['group_deny'] ?? ''
|
||||
));
|
||||
|
||||
$profileFields->append(DI::profileFieldFactory()->createFromString(
|
||||
$uid,
|
||||
$profileFieldOrder[$id],
|
||||
$profileFieldInput['label'],
|
||||
$profileFieldInput['value'],
|
||||
$permissionSet
|
||||
));
|
||||
}
|
||||
|
||||
return $profileFields;
|
||||
}
|
||||
|
||||
private static function cleanKeywords($keywords)
|
||||
{
|
||||
$keywords = str_replace(',', ' ', $keywords);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue