Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function storeToken(Token $token): void
$this->db->replace(
self::TABLE_NAME,
[
'token' => ['text', $token->getToken()]
'token' => [\ilDBConstants::T_TEXT, $token->getToken()]
],
[
'usr_id' => [\ilDBConstants::T_TEXT, $token->getUserId()],
Expand Down
3 changes: 0 additions & 3 deletions components/ILIAS/User/src/Profile/ChangeMail/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public function hasUserValidEmailConfirmationToken(\ilObjUser $user): bool;
/**
* This Function will check if the token is actually valid for the given user
* before returning the new email.
*
* @return string The new email a user wishes to be used or an empty string
* if validation failed or there is no usable entry.
*/
public function getTokenForTokenString(string $token_string, \ilObjUser $user): ?Token;
public function moveToNextStep(Token $token, int $now): Token;
Expand Down
15 changes: 7 additions & 8 deletions components/ILIAS/User/src/Profile/DataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ interface DataRepository
{
public function getDefault(): Data;
public function getSingle(int $id): Data;

/**
*
* @param array<int> $user_ids
* @return Generator<UserData>
* @param list<int> $user_ids
* @return \Generator<int, Data>
*/
public function getMultiple(array $user_ids): \Generator;
public function store(Data $user_data): void;
Expand All @@ -51,17 +49,18 @@ public function storeLoginFor(
public function storeLastVisitedFor(
int $usr_id,
array $last_visited
);
): void;
/**
* @return list<\ILIAS\User\Search\AutocompleteItem>
*/
public function searchUsers(
SettingsDataRepository $settings_data_repository,
ProfileFieldsConfigurationRepository $profile_fields_config_repo,
AutocompleteQuery $search_term
): array;

public function getProfileDataQuery(array $select_fields): DataQuery;

/**
* @return array{cnt: int, set: array{string, mixed}}
* @return array{cnt: int, set: list<array<string, mixed>>}
*/
public function getCountAndRecordsForQuery(
DataQuery $query,
Expand Down
10 changes: 2 additions & 8 deletions components/ILIAS/User/src/Profile/DatabaseDataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getSingle(int $id): Data

$base_data = $this->db->fetchObject($base_query);
if ($base_data === null) {
throw \InvalidArgumentException(
throw new \InvalidArgumentException(
'This user does not exist.'
);
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public function store(Data $user_data): void

public function deleteForFieldIdentifier(string $identifier): void
{
$this->db->manipulateF(
$this->db->manipulate(
'DELETE FROM ' . self::USER_VALUES_TABLE
. " WHERE field_id='{$this->db->quote($identifier, \ilDBConstants::T_TEXT)}'"
);
Expand Down Expand Up @@ -245,9 +245,6 @@ public function storeLastVisitedFor(
);
}

/**
* @return list<\ILIAS\User\Search\AutocompleteItem>
*/
public function searchUsers(
SettingsDataRepository $settings_data_repository,
ProfileFieldsConfigurationRepository $profile_fields_config_repo,
Expand Down Expand Up @@ -293,9 +290,6 @@ public function getProfileDataQuery(
);
}

/**
* @return array{cnt: int, set: array{string, mixed}}
*/
public function getCountAndRecordsForQuery(
DataQuery $query,
int $offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ class CachedConfigurationRepository implements ConfigurationRepository
{
private const string USER_FIELD_CONFIGURATION_TABLE = 'usr_field_config';
private const string UDF_DEFINITIONS_TABLE = 'udf_definition';
/**
* @var list<FieldDefinition>
*/
private array $available_profile_fields;

/**
*
* @var array<string, stdClass>
* @var array<string, \stdClass>
*/
private array $fields_data = [];

/**
* @param list<class-string<Custom\Type>> $available_custom_field_types
* @param list<FieldDefinition> $available_standard_profile_fields
*/
public function __construct(
private readonly \ilDBInterface $db,
private readonly UUIDFactory $uuid_factory,
Expand Down Expand Up @@ -159,7 +165,7 @@ public function storeConfiguration(Field $field): void
public function getCustomFieldTypes(): array
{
return array_map(
fn(string $v): Custom\Type => new $v(),
static fn(string $v): Custom\Type => new $v(),
$this->available_custom_field_types
);
}
Expand Down Expand Up @@ -189,6 +195,10 @@ public function deleteCustomField(Field $field): void
$this->available_profile_fields = $this->generateAvailableProfielFields();
}

/**
* @param list<class-string<Custom\Type>> $available_custom_field_types
* @return list<Custom\Custom>
*/
private function buildCustomFieldDefinitions(
array $available_custom_field_types
): array {
Expand All @@ -199,9 +209,10 @@ private function buildCustomFieldDefinitions(
$custom_field_definitions = [];
while (($field = $this->db->fetchObject($query_result)) !== null) {
$field_type = array_search($field->field_type, $available_custom_field_types);
if ($field_type === null) {
if ($field_type === false) {
continue;
}

$custom_field_definitions[] = new Custom\Custom(
$this->uuid_factory->fromString($field->field_id),
new $available_custom_field_types[$field_type](),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ interface ConfigurationRepository
public function hasMigrationBeenRun(): bool;

/**
* @return array<\ILIAS\User\Profile\Fields\Field>
* @return list<Field>
*/
public function get(): array;
public function getByIdentifier(string $identifier): ?Field;
public function getByClass(string $class): ?Field;
public function storeConfiguration(Field $field): void;

/**
* @return array<\ILIAS\User\Profile\Fields\FieldDefinition>
* @return list<Custom\Type>
*/
public function getCustomFieldTypes(): array;
public function getUnspecifiedCustomField(): Field;
Expand Down
19 changes: 13 additions & 6 deletions components/ILIAS/User/src/Profile/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@
interface Profile
{
/**
* @return array<\ILIAS\User\Profile\Fields\Field>
* @param list<\ILIAS\User\Profile\Fields\AvailableSections> $fields_to_skip
* @param list<class-string<\ILIAS\User\Profile\Fields\FieldDefinition>> $fields_to_skip
* @return array<string, ProfileField>
*/
public function getFields(
array $sections_to_skip = [],
array $fields_to_skip = []
): array;

/**
* @return array<\ILIAS\User\Profile\Fields\Field>
* @param list<\ILIAS\User\Profile\Fields\AvailableSections> $fields_to_skip
* @param list<class-string<\ILIAS\User\Profile\Fields\FieldDefinition>> $fields_to_skip
* @return array<int, ProfileField>
*/
public function getVisibleFields(
Context $context,
Expand All @@ -43,6 +47,9 @@ public function getVisibleFields(

public function getFieldByIdentifier(string $identifier): ?ProfileField;

/**
* @param list<class-string<\ILIAS\User\Profile\Fields\FieldDefinition>> $fields_to_skip
*/
public function addFieldsToForm(
\ilPropertyFormGUI $form,
Context $context,
Expand All @@ -64,7 +71,7 @@ public function getDataFor(
/**
*
* @param array $usr_ids
* @return \Generator<ILIAS\User\Profile\Data>
* @return \Generator<int, Data>
*/
public function getDataForMultiple(
array $usr_ids
Expand All @@ -79,18 +86,18 @@ public function userFieldVisibleToUser(
public function userFieldEditableByUser(string $definition_class): bool;

/**
* @return array<\ILIAS\User\Profile\Fields\Field>
* @return list<ProfileField>
*/
public function getIgnorableRequiredFields(): array;

/**
* @deprecated since version 11 will be removed with 13
* @return array<string, \ILIAS\User\Profile\Field>
* @return array<string, ProfileField>
*/
public function getAllUserDefinedFields(): array;
/**
* @deprecated since version 11 will be removed with 13
* @return array<string, \ILIAS\User\Profile\Field>
* @return array<string, ProfileField>
*/
public function getVisibleUserDefinedFields(
Context $context
Expand Down
33 changes: 13 additions & 20 deletions components/ILIAS/User/src/Profile/ProfileImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
use ILIAS\User\Profile\Fields\AvailableSections as AvailableProfileSections;
use ILIAS\User\Profile\Fields\ConfigurationRepository as FieldsConfigurationRepository;
use ILIAS\Language\Language;
use ILIAS\User\Profile\Fields\AvailableSections;

class ProfileImplementation implements Profile
{
/**
* @var list<ProfileField>
*/
private array $user_fields;

public function __construct(
Expand All @@ -38,16 +42,13 @@ public function __construct(
$this->user_fields = $this->profile_fields_repository->get();
}

/**
* @return array<\ILIAS\User\Profile\Fields\Field>
*/
public function getFields(
array $sections_to_skip = [],
array $fields_to_skip = []
): array {
return array_reduce(
$this->user_fields,
function (array $c, ProfileField $v) use ($sections_to_skip, $fields_to_skip): array {
static function (array $c, ProfileField $v) use ($sections_to_skip, $fields_to_skip): array {
if (!in_array($v->getSection(), $sections_to_skip)
&& !in_array(get_class($v->getDefinition()), $fields_to_skip)) {
$c[$v->getIdentifier()] = $v;
Expand All @@ -58,9 +59,6 @@ function (array $c, ProfileField $v) use ($sections_to_skip, $fields_to_skip): a
);
}

/**
* @return array<\ILIAS\User\Profile\Fields\Field>
*/
public function getVisibleFields(
Context $context,
?\ilObjUser $user = null,
Expand All @@ -69,7 +67,7 @@ public function getVisibleFields(
): array {
return array_filter(
$this->user_fields,
fn(ProfileField $v) => !in_array($v->getSection(), $sections_to_skip)
static fn(ProfileField $v) => !in_array($v->getSection(), $sections_to_skip)
&& !in_array($v->getDefinition()::class, $fields_to_skip)
&& $context->isFieldVisible($v, $user)
? true : false
Expand Down Expand Up @@ -174,7 +172,7 @@ public function userFieldEditableByUser(string $setting): bool
return $field->isVisibleToUser() && $field->isChangeableByUser();
}

public function getIgnorableRequiredFields(): array // Missing array type.
public function getIgnorableRequiredFields(): array
{
return array_reduce(
$this->user_fields,
Expand All @@ -192,15 +190,11 @@ static function (array $c, ProfileField $v): array {
);
}

/**
* @deprecated since version 11 will be removed with 13
* @return array<string, \ILIAS\User\Profile\Field>
*/
public function getAllUserDefinedFields(): array
{
return array_reduce(
$this->user_fields,
function (array $c, ProfileField $v): array {
static function (array $c, ProfileField $v): array {
if ($v->isCustom()) {
$c[$v->getIdentifier()] = $v;
}
Expand All @@ -210,16 +204,12 @@ function (array $c, ProfileField $v): array {
);
}

/**
* @deprecated since version 11 will be removed with 13
* @return array<string, \ILIAS\User\Profile\Field>
*/
public function getVisibleUserDefinedFields(
Context $context
): array {
return array_reduce(
$this->getVisibleFields($context),
function (array $c, ProfileField $v): array {
static function (array $c, ProfileField $v): array {
if ($v->isCustom()) {
$c[$v->getIdentifier()] = $v;
}
Expand All @@ -239,6 +229,9 @@ public function tempStorePicture(
->getDefinition()->tempStorePicture($form);
}

/**
* @return array<value-of<AvailableSections>, array<int, ProfileField>>
*/
private function getVisibleFieldsBySection(
Context $context,
?\ilObjUser $user,
Expand All @@ -247,7 +240,7 @@ private function getVisibleFieldsBySection(
return array_filter(
array_reduce(
$this->getVisibleFields($context, $user, [], $fields_to_skip),
function (array $c, ProfileField $v): array {
static function (array $c, ProfileField $v): array {
$c[$v->getSection()->value][] = $v;
return $c;
},
Expand Down
Loading