PHP Class Habari\User

Inheritance: extends QueryRecord, implements habari\FormStorage, implements IsContent
显示文件 Open project: habari/system Class Usage Examples

Protected Properties

Property Type Description
$url_args

Public Methods

Method Description
__construct ( array $paramarray = [] ) Constructor for the User class
__get ( string $name ) : mixed Capture requests for the info object so that it can be initialized properly when the constructor is bypassed (see PDO::FETCH_CLASS pecularities). Passes all other requests to parent.
add_to_group ( integer | string | UserGroup $group ) : null function add_to_group
anonymous ( ) : object Build and return the anonymous user
authenticate ( string $who, string $pw ) : User | boolean Check a user's credentials to see if they are legit -- calls all auth plugins BEFORE checking local database.
can ( string $token, string $access = 'any' ) : boolean Determine if a user has a specific token permission
can_any ( array $token_access = [] ) : boolean Determine if a user has any of a set of tokens
cannot ( string $token ) : boolean Determine if a user has been denied access to a specific token
commenter ( ) : Array Returns an array of information about the commenter If this is a logged-in user, then return details from their user profile.
content_type ( ) : array Returns the content type of the object instance
count_posts ( $status = false ) : integer Returns the number of posts written by this user
create ( $paramarray ) : User Creates a new user object and saves it to the database
default_fields ( ) : array Get default fields for this record.
delete ( ) Delete a user account
deny ( $tokens ) Deny permissions to one or more tokens to this user
field_load ( string $key ) : mixed Loads form values from an object
field_save ( string $key, mixed $value ) Stores a form value into the object
forget ( boolean $redirect = true ) Delete the user id from the session
get ( mixed $who ) : object Fetch a user from the database by name, ID, or email address.
get_by_email ( string $email ) : User Select a user from the database by its email address
get_by_id ( integer $id ) : User Select a user from the database by its id
get_by_name ( string $username ) : User Select a user from the database by its username
get_id ( mixed $user ) : integer Return the id of a user
get_url_args ( ) : array Returns a set of properties used by URL::get to create URLs
grant ( $tokens, $access = 'full' ) Assign permissions to one or more new tokens to this user
identify ( ) : User Check for the existence of a cookie, and return a user object of the user, if successful
in_group ( integer | string $group ) : boolean function in_group Whether or not this user is is in the specified group
insert ( ) Save a new user to the users table
remember ( ) Save the user id into the session
remove_from_group ( integer | string | UserGroup $group ) : null function remove_from_group removes this user from a group
revoke ( $tokens ) Remove permissions to one or more tokens from a user
update ( ) Updates an existing user in the users table

Private Methods

Method Description
get_info ( ) : UserInfo function get_info Gets the info object for this user, which contains data from the userinfo table related to this user.
list_groups ( $refresh = false ) : Array Returns an array of groups to which this user belongs

Method Details

__construct() public method

Constructor for the User class
public __construct ( array $paramarray = [] )
$paramarray array an associative array of initial User fields

__get() public method

Capture requests for the info object so that it can be initialized properly when the constructor is bypassed (see PDO::FETCH_CLASS pecularities). Passes all other requests to parent.
public __get ( string $name ) : mixed
$name string requested field name
return mixed the requested field value

add_to_group() public method

function add_to_group
public add_to_group ( integer | string | UserGroup $group ) : null
$group integer | string | UserGroup A group ID, name, or UserGroup instance
return null

anonymous() public static method

Build and return the anonymous user
public static anonymous ( ) : object
return object user object

authenticate() public static method

Check a user's credentials to see if they are legit -- calls all auth plugins BEFORE checking local database.
public static authenticate ( string $who, string $pw ) : User | boolean
$who string A username
$pw string A password
return User | boolean a User object, or false

can() public method

Determine if a user has a specific token permission
public can ( string $token, string $access = 'any' ) : boolean
$token string The name of the token for which to check permission
$access string The type of access to check for (read, write, full, etc.)
return boolean True if this user has the requested access, false if not

can_any() public method

Determine if a user has any of a set of tokens
public can_any ( array $token_access = [] ) : boolean
$token_access array An array of tokens and the permissions to check for each of them.
return boolean True if this user has the requested access, false if not

cannot() public method

Determine if a user has been denied access to a specific token
public cannot ( string $token ) : boolean
$token string The name of the token to detect
return boolean True if this user has been denied access to the requested token, false if not

commenter() public static method

If this is a returning commenter, then return details from their cookie otherwise return empty strings.
public static commenter ( ) : Array
return Array an array of name, email and URL

content_type() public method

Returns the content type of the object instance
public content_type ( ) : array
return array An array of content types that this object represents, starting with the most specific

count_posts() public method

Returns the number of posts written by this user
public count_posts ( $status = false ) : integer
return integer The number of posts written by this user

create() public static method

Creates a new user object and saves it to the database
public static create ( $paramarray ) : User
return User the User object that was created

default_fields() public static method

Get default fields for this record.
public static default_fields ( ) : array
return array an array of the fields used in the User table

delete() public method

Delete a user account
public delete ( )

deny() public method

Deny permissions to one or more tokens to this user
public deny ( $tokens )

field_load() public method

Loads form values from an object
public field_load ( string $key ) : mixed
$key string The name of a form component that will be loaded
return mixed The stored value returned

field_save() public method

Stores a form value into the object
public field_save ( string $key, mixed $value )
$key string The name of a form component that will be stored
$value mixed The value of the form component to store

forget() public method

Delete the user id from the session
public forget ( boolean $redirect = true )
$redirect boolean Redirect the user to base_url after destroying session?

get() public static method

This is a wrapper function that will invoke the appropriate get_by_* method.
public static get ( mixed $who ) : object
$who mixed user ID, username, or e-mail address
return object User object, or false

get_by_email() public static method

Select a user from the database by its email address
public static get_by_email ( string $email ) : User
$email string The email address of a user
return User The User object of the specified user

get_by_id() public static method

Select a user from the database by its id
public static get_by_id ( integer $id ) : User
$id integer The id of a user
return User The User object of the specified user

get_by_name() public static method

Select a user from the database by its username
public static get_by_name ( string $username ) : User
$username string The name of a user
return User The User object of the specified user

get_id() public static method

Return the id of a user
public static get_id ( mixed $user ) : integer
$user mixed The id, name, or email address of a user
return integer The id of the specified user or false if that user doesn't exist

get_url_args() public method

Returns a set of properties used by URL::get to create URLs
public get_url_args ( ) : array
return array Properties of this post used to build a URL

grant() public method

Assign permissions to one or more new tokens to this user
public grant ( $tokens, $access = 'full' )

identify() public static method

Check for the existence of a cookie, and return a user object of the user, if successful
public static identify ( ) : User
return User user object, or false if no valid cookie exists

in_group() public method

function in_group Whether or not this user is is in the specified group
public in_group ( integer | string $group ) : boolean
$group integer | string a group ID or name
return boolean Whether or not this user is in the specified group

insert() public method

Save a new user to the users table
public insert ( )

remember() public method

Save the user id into the session
public remember ( )

remove_from_group() public method

function remove_from_group removes this user from a group
public remove_from_group ( integer | string | UserGroup $group ) : null
$group integer | string | UserGroup A group ID, name, or UserGroup instance
return null

revoke() public method

Remove permissions to one or more tokens from a user
public revoke ( $tokens )

update() public method

Updates an existing user in the users table
public update ( )

Property Details

$url_args protected_oe property

protected $url_args