The SuperUser Class

Getting, creating and manipulating users.

Functions

SuperUser::getUsernames

Definition

Name
getUsernames
Syntax
Array|False = SuperUser::getUsernames( Array $_options );

Description

Get usernames or specific username

Parameters

$_options
Array Filtering options
Options
username_id
Returns specific username
user_id
Returns all usernames for user
type
Values can be 'email' or 'mobile'. Requires user_id to be passed. Returns first username of type for user_id.

Return values

Array|False Returns username object containing id, user_id, username, type, verified, and verification_code. If several username objects are returned, they will be nested in an array. False on error or if no options are passed.

Examples

$UC = new SuperUser(); $username_id = 42; $result = $UC->getUsernames(["username_id" => $username_id]); $username = $result["username"];

Get username object with specific username_id and save the username string in $username.

$UC = new SuperUser(); $user_id = 7; $result = $UC->getUsernames(["user_id" => $user_id]); foreach ($result as $username) { $usernames[] = $username["username"]; }

Get all username objects for user_id, and save the username strings in $usernames.

$UC = new SuperUser(); $user_id = 7; $type = "email"; $result = $UC->getUsernames(["user_id" => $user_id, "type" => $type]); $email = $result["username"];

Get first username object of the type 'email' for user_id, and save the username string in $username.

Dependencies

PHP

None

Janitor
  • Query functions

SuperUser::getUnverifiedUsernames

Definition

Name
getUnverifiedUsernames
Syntax
Array|False = SuperUser::getUnverifiedUsernames( [Array $_options ] );

Description

Get all (or a subset of) unverified usernames;

Parameters

$_options
Array Optional filters
Options
type
Get unverified usernames of specific type. Can be "email" or "mobile".
user_id
Get unverified usernames for specific user

Return values

Array|False Returns array with one or more objects, each object containing user_id, username_id username, verification_code, nickname, created_at, reminded_at, and total_reminders. False on error.

Examples

$UC = new SuperUser(); $unverified_usernames = $UC->getUnverifiedUsernames();

Get all unverified usernames.

$UC = new SuperUser(); $unverified_emails = $UC->getUnverifiedUsernames(["type" => "email"]);

Get all unverified emails.

$UC = new SuperUser(); $user_id = 42; $unverified_emails = $UC->getUnverifiedUsernames(["type" => "email", "user_id" => $user_id]);

Get all unverified emails for specific user id.

$UC = new SuperUser(); $user_id = 42; $unverified_usernames = $UC->getUnverifiedUsernames(["user_id" => $user_id]);

Get all unverified usernames for specific user id.

Dependencies

PHP

None

Janitor
  • Query class

SuperUser::getVerificationStatus

Definition

Name
SuperUser::getVerificationStatus
Syntax
Array|False = SuperUser::getVerificationStatus( Integer $username_id Integer $user_id );

Description

Get verification status for username.

Parameters

$username_id
Integer The unique id of the username
$user_id
Integer The user_id to which the username_id belongs

Return values

Array|False Array with verification status and number of verification links that have been send. False on error.

Examples

$UC = new SuperUser; $username_id = 42; $user_id = 7; $verification_status = $UC->getVerificationStatus($username_id, $user_id);

Dependencies

PHP
  • count()
  • end()
Janitor
  • Query functions

SuperUser::setVerificationStatus

Definition

Name
SuperUser::setVerificationStatus
Syntax
Array|False = SuperUser::setVerificationStatus( Integer $username_id Integer $user_id Integer $verification_status );

Description

Set verification status for username

Parameters

$username_id
Integer The unique id of the username
$user_id
Integer The user_id to which the username_id belongs
$verification_status
Integer 1 for verified; 0 for unverified.

Return values

Array|False Array with status code indicating whether username is verified/not verified. False on error.

$UC = new SuperUser; $username_id = 42; $user_id = 7; $verification_status = 1; $verification_status = $UC->setVerificationStatus($username_id, $user_id, $verification_status);

Dependencies

PHP

None

Janitor
  • Query functions
  • Message functions

SuperUser::updateEmail

Definition

Name
SuperUser::updateEmail
Syntax
Array|True|False = SuperUser::updateEmail( String format [, Mixed timestamp ] );

Description

Update usernames from posted values.

Expects $email and $username_id from $_POST.

Parameters

$action
Array $username_id in $action[1].

Return values

Array|True|False Returns status code indicating whether email was updated/unchanged/already existing. Returns true if email was deleted (updated to blank). False on error.

Examples

$UC = new SuperUser; $username_id = 42; $result = $UC->updateEmail(["updateEmail", $username_id]);

Update $username to $email. $email is retrieved from $_POST.

Dependencies

PHP
  • count()
  • isset()
Janitor
  • Model::getProperty
  • getPost
  • SuperUser::getUsernames
  • SuperUser::getUsers
  • SuperUser::setVerificationStatus
  • Message functions
  • Query functions

SuperUser::cancel

Definition

Name
SuperUser::cancel
Syntax
Array|Boolean = SuperUser::cancel( Array $action );

Description

Deletes all information of a given user. Users with unpaid orders can not be deleted.

Parameters

$action
array action array
Action parameters
$action[0]
"cancel"|arbritary parameter
$action[1]
user_id of user to delete

Return values

Array with the value "error" => "unpaid_orders" if the user has unpaid orders. The user is not deleted.

False if the user was not deleted. (Exactly two action parameters were not received.)

True if the user was successfully deleted.

Examples

Example 1
$user = ( [id] => 26, [user_group_id] => 3, [firstname] => [lastname] => [nickname] => "e.haabegaard@gmail.com", [status] => 1, [language] => [created_at] => 2019-04-08 12:58:38, [modified_at] => [last_login_at] => 2019-04-10 14:56:59, [mobile] => [email] => e.haabegaard@gmail.com, [addresses] => [maillists] => [membership] => ) $UC = new SuperUser(); $result = $UC->cancel(["cancel", 26]);

Returns an array with information about the result of the function call. All account information of the user is deleted.

$result = true $user = ( id] => 26, [user_group_id] => NULL, [firstname] => NULL, [lastname] => NULL, [nickname] => NULL, [status] => -1, [language] => NULL, [created_at] => 2019-04-08 12:58:38, [modified_at] => [last_login_at] => 2019-04-10 14:56:59, [mobile] => NULL, [email] => NULL, [addresses] => NULL, [maillists] => NULL, [membership] => NULL )

Dependencies

PHP
  • count
  • defined
Janitor
  • Page::addLog
  • Payments::deleteGatewayUserId
  • Shop::getUnpaidOrders
  • SuperUser::flushUserSession
  • Query::sql