Documentation

User_Profile
in package

User Profile

The User object is used for all user related operations.

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Thomas Daeppen thomas.daeppen@comvation.com

version
2.0.0
subpackage

lib_framework

uses
User_Profile_Attribute

Table of Contents

Constants

ADDRESS_LABEL_DB_TABLE  : string = 'access_user_profile_address_label'
Database table storing the address label assignments.
ADDRESS_PROFILE_ATTRIBUTE_DB_TABLE  : string = 'access_user_profile_address'
Database table storing address profile attribute values.

Properties

$arrAttributeHistories  : mixed
$arrNoAvatar  : array<string|int, mixed>
$arrNoPicture  : mixed
$arrUpdatedAttributeHistories  : mixed
$objAttribute  : User_Profile_Attribute
$addressLabelValuesLoaded  : array<string|int, int>
IDs of the users whose address label assignments have been loaded.
$addressProfileAttribute  : User_Profile_Attribute|null
Root address profile attribute definition.
$addressProfileAttributeChildren  : array<string, string>
Mapping of attribute child IDs to their database field names.
$addressProfileAttributeLabels  : array<string, array<string|int, mixed>>
Registry of the component provided address labels.

Methods

__construct()  : mixed
checkMandatoryCompliance()  : mixed
getAddressProfileAttribute()  : User_Profile_Attribute
Returns the root address profile attribute.
getAddressProfileAttributeChildren()  : array<string, string>
Returns the mapping of address attribute child IDs to database fields.
getProfileAddressByLabel()  : array<string|int, mixed>|null
Returns the user's profile address the supplied address label is assigned to.
loadAddressLabels()  : bool
Ensures the component provided address labels are initialized.
setProfile()  : mixed
createProfile()  : bool
Create a profile for the loaded user
deleteProfileAddressLabels()  : bool
Drops all label assignments of a deleted profile address.
enforceAddressLabelUniqueness()  : void
Enforces that each address label is only assigned to one address.
getProfileAddressHistoryIdByLabel()  : int
Returns the history ID of the user's profile address the supplied address label is assigned to.
initAddressProfileAttribute()  : void
Initializes the address profile attribute and resolves its child attributes.
loadCustomAttributeProfileData()  : bool
Load custom attribute profile data
loadProfileAddresses()  : void
Loads address profile attribute values for all currently loaded users.
loadProfileAddressLabels()  : void
Loads the address label assignments of all loaded users.
parseAttributeSearchConditions()  : array<string|int, mixed>
Enter description here... Matches single (scalar) or multiple (array) search terms against a number of fields. Generally, the term(s) are enclosed in percent signs ("%term%"), so any fields that contain them will match.
parseCoreAttributeFilterConditions()  : array<string|int, mixed>
Parse core attribute filter conditions
parseCustomAttributeFilterConditions()  : array<string|int, mixed>
Parse custom attribute filter conditions
storeProfile()  : mixed
storeProfileAddressLabel()  : bool
Persists the assignment of an address label.
initAttributes()  : mixed

Constants

ADDRESS_LABEL_DB_TABLE

Database table storing the address label assignments.

protected string ADDRESS_LABEL_DB_TABLE = 'access_user_profile_address_label'

ADDRESS_PROFILE_ATTRIBUTE_DB_TABLE

Database table storing address profile attribute values.

protected string ADDRESS_PROFILE_ATTRIBUTE_DB_TABLE = 'access_user_profile_address'

Properties

$arrNoAvatar

public static array<string|int, mixed> $arrNoAvatar = array('src' => '0_noavatar.gif', 'width' => 121, 'height' => 160)
Tags
access

private

$arrNoPicture

public static mixed $arrNoPicture = array('src' => '0_no_picture.gif', 'width' => 80, 'height' => 84)

$addressLabelValuesLoaded

IDs of the users whose address label assignments have been loaded.

protected array<string|int, int> $addressLabelValuesLoaded = []

$addressProfileAttributeChildren

Mapping of attribute child IDs to their database field names.

protected array<string, string> $addressProfileAttributeChildren = []

Address labels (see static::$addressProfileAttributeLabels) are not part of this mapping as they are not stored as table fields.

Example: [ 'address_data_city' => 'city', 'address_data_zip' => 'zip' ]

Methods

getAddressProfileAttributeChildren()

Returns the mapping of address attribute child IDs to database fields.

public getAddressProfileAttributeChildren() : array<string, string>

The mapping is built during initialization by static::initAddressProfileAttribute().

Example: [ 'address_data_city' => 'city', 'address_data_zip' => 'zip' ]

Return values
array<string, string>

Map of attribute child ID to database column name

getProfileAddressByLabel()

Returns the user's profile address the supplied address label is assigned to.

public getProfileAddressByLabel(string $component, string $key) : array<string|int, mixed>|null

Example: $arrAddress = $objUser->getProfileAddressByLabel('Shop', 'billing'); $city = $arrAddress['address_data_city'];

Parameters
$component : string

Name of the component that registered the label

$key : string

Key of the label (as registered by the component)

Return values
array<string|int, mixed>|null

The address as an array of the address profile attribute values (indexed by their attribute ID), extended by the element 'history_id'. NULL is returned in case the label is not assigned to any address of the user.

loadAddressLabels()

Ensures the component provided address labels are initialized.

public loadAddressLabels() : bool

This covers:

As the labels are provided by components (through the event ComponentController::ADDRESS_LABEL_EVENT), they cannot be collected before all components have been loaded. This method is therefore called by all label dependent functionalities, to ensure the labels do also get initialized on objects that have been instantiated early in the bootstrap process.

The method is idempotent.

Return values
bool

FALSE in case the label registrations cannot be collected yet, TRUE otherwise

setProfile()

public setProfile(mixed $arrProfile[, mixed $ignoreAccessPermissions = false ]) : mixed
Parameters
$arrProfile : mixed
$ignoreAccessPermissions : mixed = false

createProfile()

Create a profile for the loaded user

protected createProfile() : bool

This creates an entry in the dabase table contrexx_access_user_profile which is related to the entry in the table cotnrexx_access_users of the same user. This methode will be obsolete as soon as we're using InnoDB as storage engine.

Return values
bool

deleteProfileAddressLabels()

Drops all label assignments of a deleted profile address.

protected deleteProfileAddressLabels(int $historyId) : bool
Parameters
$historyId : int

History ID of the deleted address

Return values
bool

FALSE in case a database error occurred, TRUE otherwise

enforceAddressLabelUniqueness()

Enforces that each address label is only assigned to one address.

protected enforceAddressLabelUniqueness(array<string|int, mixed> $arrProfile) : void

In case the update (see static::setProfile()) did assign a label to more than one address, only the last assignment is kept.

Note that an assignment does move a label: when assigning a label (that is currently assigned to address A) to address B, the label gets removed from address A.

Parameters
$arrProfile : array<string|int, mixed>

The profile update data as passed to static::setProfile(). Used to identify the labels that have been part of the update.

Tags
todo

Make the uniqueness enforcement optional (chosen by the label registration) and provide it for any attribute, not only for addresses.

getProfileAddressHistoryIdByLabel()

Returns the history ID of the user's profile address the supplied address label is assigned to.

protected getProfileAddressHistoryIdByLabel(string $component, string $key) : int
Parameters
$component : string

Name of the component that registered the label

$key : string

Key of the label (as registered by the component)

Return values
int

The history ID of the assigned address, or 0 in case the label is not assigned to any address of the user

initAddressProfileAttribute()

Initializes the address profile attribute and resolves its child attributes.

protected initAddressProfileAttribute() : void

The method retrieves the root address attribute and builds a mapping of child attribute IDs to their corresponding database column names. Child attributes that represent component provided address labels are tracked separately (in static::$addressProfileAttributeLabels) as they are not stored as table fields.

Note: besides being called on object initialization, the method is invoked again (see static::loadAddressLabels()) once the component provided address labels have become available.

loadCustomAttributeProfileData()

Load custom attribute profile data

protected loadCustomAttributeProfileData([array<string|int, mixed> $arrAttributes = array() ]) : bool

Gets the data of the custom profile attributes from the database an puts it into the class variables $this->arrLoadedUsers and $this->arrCachedUsers. On the other hand it fills the class variables $this->arrAttributeHistories and $this->arrUpdataedAttributeHistories with the history IDs of each attribute. Returns FALSE if a database error had occurred, otherwise TRUE.

Parameters
$arrAttributes : array<string|int, mixed> = array()
Return values
bool

loadProfileAddresses()

Loads address profile attribute values for all currently loaded users.

protected loadProfileAddresses() : void

The method queries the address attribute table and populates:

Values are indexed by: [userId]['profile'][attributeId][historyId].

Early returns occur when:

  • No users are loaded
  • Address profile attributes are not initialized
  • Query execution fails or returns no rows

loadProfileAddressLabels()

Loads the address label assignments of all loaded users.

protected loadProfileAddressLabels() : void

The assignments are materialized as regular profile attribute values (indexed by [userId]['profile'][attributeId][historyId]) in:

An assigned label has the value 1, an unassigned label the empty string. The empty string (and not 0) is imperative, as it is what makes \Cx\Core_Modules\Access\Controller\AccessLib::parseAttribute() skip unassigned labels in view mode: its empty-value check ($value == '') does not match 0 (nor '0') on PHP 8.

Users whose assignments have been loaded already (tracked in static::$addressLabelValuesLoaded) are skipped.

parseAttributeSearchConditions()

Enter description here... Matches single (scalar) or multiple (array) search terms against a number of fields. Generally, the term(s) are enclosed in percent signs ("%term%"), so any fields that contain them will match.

protected parseAttributeSearchConditions(mixed $search[, unknown_type $core = false ][, unknown_type $attributeId = 0 ]) : array<string|int, mixed>

However, if the search parameter is a string and does contain a percent sign already, none will be added to the query. This allows searches using custom patterns, like "fields beginning with "a" ("a%"). (You might even want to extend this to work with arrays, too. Currently, only the shop module uses this feature.) -- RK 20100910

Parameters
$search : mixed

The term or array of terms

$core : unknown_type = false
$attributeId : unknown_type = 0
Return values
array<string|int, mixed>

The array of SQL snippets

parseCoreAttributeFilterConditions()

Parse core attribute filter conditions

protected parseCoreAttributeFilterConditions(array<string|int, mixed> $arrFilter) : array<string|int, mixed>

Generate conditions of the core attributes for the SQL WHERE statement. The filter conditions are defined through the two dimensional array $arrFilter. Each key-value pair represents an attribute and its associated condition to which it must fit to. The condition could either be a integer or string depending on the attributes type, or it could be a collection of integers or strings represented in an array.

Parameters
$arrFilter : array<string|int, mixed>
Return values
array<string|int, mixed>

parseCustomAttributeFilterConditions()

Parse custom attribute filter conditions

protected parseCustomAttributeFilterConditions(mixed $arrFilter[, string $forceTableIdx = null ][, bool $uniqueJoins = true ][, int &$joinIdx = 0 ]) : array<string|int, mixed>

Generate conditions of the custom attributes for the SQL WHERE statement. The filter conditions are defined through the two dimensional array $arrFilter. Each key-value pair represents an attribute and its associated condition to which it must fit to. The condition could either be a integer or string depending on the attributes type, or it could be a collection of integers or strings represented in an array.

Matches single (scalar) or multiple (array) search terms against a number of fields. Generally, the term(s) are enclosed in percent signs ("%term%"), so any fields that contain them will match. However, if the search parameter is a string and does contain a percent sign already, none will be added to the query. This allows searches using custom patterns, like "fields beginning with "a" ("a%"). (You might even want to extend this to work with arrays, too. Currently, only the shop module uses this feature.) -- RK 20100910

Parameters
$arrFilter : mixed

The term or array of terms

$forceTableIdx : string = null

Argument must not be used directly. Will internally be used for recursion (parsing child attributes of complex profile attributes like gender or country). If $forceTableIdx is set then its value will be used as prefix for the table alias of the SQL statement.

$uniqueJoins : bool = true

Whether the filter arguments shall be joined by separate unique JOINs or by a single common JOIN statement.

$joinIdx : int = 0

The current index used for separate unique JOINs.

Return values
array<string|int, mixed>

The array of SQL snippets

storeProfile()

protected storeProfile([mixed &$profileUpdated = null ]) : mixed
Parameters
$profileUpdated : mixed = null

If $profileUpdated is provided, then in case any profile changes are being flushed to the database, $profileUpdated will be set to TRUE, otherwise it'll be left untouched.

storeProfileAddressLabel()

Persists the assignment of an address label.

protected storeProfileAddressLabel(string $attributeId[, mixed &$profileUpdated = null ]) : bool

The assignment in the database is updated to reflect the current state of User::$arrLoadedUsers:

  • Assigned: the label is set (or moved) to the assigned address.
  • Explicitly unassigned (the previously assigned address has been updated to no longer hold the label): the assignment is removed.
  • Not assigned, but the previously assigned address is not part of the current state: the assignment is left untouched.

Note: the values are intentionally read from User::$arrLoadedUsers (instead of being passed by the caller), as static::deleteProfileAddressLabels() might drop values while static::storeProfile() is iterating over a (then outdated) snapshot of the profile data.

Parameters
$attributeId : string

Attribute ID of the address label

$profileUpdated : mixed = null

Set to TRUE in case a change has been flushed to the database, left untouched otherwise

Return values
bool

FALSE in case a database error occurred, TRUE otherwise

On this page

Search results