RdbAdmin Module

ActionsController extends AdminBaseController
in package
uses CommonDataTrait, ModulesTrait

Modules actions controller.

Tags
since
1.2.5

Table of Contents

Properties

$Input  : Input
$Languages  : Languages
$runnedCronResult  : array<string|int, mixed>
$totalLoggedInSessions  : int
$userSessionCookieData  : array<string|int, mixed>

Methods

__construct()  : mixed
{@inheritDoc}
doActionsAction()  : string
Doing a selected action on selected modules.
checkLogin()  : mixed
Check for logged in, if not then redirect to login page.
checkPermission()  : mixed
Check permission and (redirect OR response error message).
getConfigDb()  : array<string|int, mixed>
Get config from DB.
getModuleUrlsMethods()  : array<string|int, mixed>
Get URLs and methods about module's management pages.
getPageHtmlClasses()  : string
Get page HTML classes.
getPageHtmlTitle()  : string
Get page HTML title including site name if it was set.
getRdbAdminAssets()  : array<string|int, mixed>
Get RdbAdmin module's assets.
isUserLoggedIn()  : bool
Check if user is logged in.
maybeRunCron()  : mixed
Maybe run cron job if config is set to not use server cron.
responseJson()  : string
{@inheritDoc}
responseXml()  : string
{@inheritDoc}
sessionTraitLogoutAll()  : mixed
Logout all succeeded login sessions, lock user account, send login link to user's email.
setBasicConfig()  : mixed
Setup basic PHP configurations such as default timezone.
setCssAssets()  : mixed
Set CSS assets for common admin pages.
setHeaderAllowOrigin()  : mixed
Set header allow origin for CORS.
setJsAssetsAndObject()  : mixed
Set JS assets and its object for XHR common data.
doUpdateModule()  : array<string|int, mixed>
Do update the module.
isModuleExcute()  : bool
Check if current call is `Modules->execute()`
sessionsTraitCheckIsLoggedInFromContainer()  : array<string|int, mixed>
Check is logged in from container if exists.
sessionTraitLogoutPreviousSessions()  : mixed
Logout all sessions before latest succeeded login. (logout only succeeded login).
validateActions()  : array<string|int, mixed>
Validate form actions.

Properties

$runnedCronResult

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

Runned cron jobs result. This is for use in case that set cron job, cron tab to run by URL. The CronController will be call to this BaseController. So, it is no need to using Libraries\Cron class to run jobs again. Just get the run result from this property. This property will be set by maybeRunCron() method.

$totalLoggedInSessions

protected int $totalLoggedInSessions = 0

The number of sessions that found this user logged in. This property is able to access after called to isUserLoggedIn() method.

$userSessionCookieData

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

The cookie data of logged in user. This property is able to access after called to isUserLoggedIn() method.

Methods

__construct()

{@inheritDoc}

public __construct(Container $Container) : mixed
Parameters
$Container : Container

doActionsAction()

Doing a selected action on selected modules.

public doActionsAction() : string
Tags
since
1.2.5

It was doUpdateAction(), renamed to doActionsAction().

Return values
string

checkLogin()

Check for logged in, if not then redirect to login page.

protected checkLogin() : mixed

checkPermission()

Check permission and (redirect OR response error message).

protected checkPermission(string $moduleSystemName, string $page, string|array<string|int, mixed> $action[, array<string|int, mixed> $identity = [] ]) : mixed

This will be redirect user to /admin page if request from web page.
This will be response error message if request via REST API or AJAX.

Parameters
$moduleSystemName : string

The module (module system name or folder name) to check.

$page : string

The page name to check.

$action : string|array<string|int, mixed>

The action(s) on that page. Use string if check for single action, use array if check for multiple actions.
If checking for multiple actions, any single action matched with certain module, page will be return true.

$identity : array<string|int, mixed> = []

The associative array of identity.

Tags
see
UserPermissionsDb::checkPermission()

For reference.

getConfigDb()

Get config from DB.

protected getConfigDb() : array<string|int, mixed>

This will get commonly used between admin controllers with these data.

rdbadmin_SiteName,
rdbadmin_SiteTimezone,
rdbadmin_AdminItemsPerPage,
Return values
array<string|int, mixed>

getModuleUrlsMethods()

Get URLs and methods about module's management pages.

protected getModuleUrlsMethods() : array<string|int, mixed>
Return values
array<string|int, mixed>

Return associative array.

getPageHtmlClasses()

Get page HTML classes.

protected getPageHtmlClasses([array<string|int, mixed> $classes = [] ]) : string
Parameters
$classes : array<string|int, mixed> = []

The classes to set for this html page.

Tags
todo

[rdb] Remove auto generate class name rdba-page-, use new one rdba-pagehtml- to prevent duplicate use in many cases. Remove this in v2.0

todo

[rdb] Remove auto generate class name rdba-class-, use new one rdba-calledclass- to prevent duplicate use in many cases. Remove this in v2.0

Return values
string

Return generated html classes names.

getPageHtmlTitle()

Get page HTML title including site name if it was set.

protected getPageHtmlTitle(string $title[, string|null|false $siteName = false ]) : string
Parameters
$title : string

The site title.

$siteName : string|null|false = false

Site name should be string.
Set to empty string or null will not include the site name.
Set to false to automatic get the site name from config DB.

Tags
throws
InvalidArgumentException
Return values
string

getRdbAdminAssets()

Get RdbAdmin module's assets.

protected getRdbAdminAssets() : array<string|int, mixed>

These contain the assets that is required for admin page to work.

Return values
array<string|int, mixed>

Return associative array with 'css' and 'js' in keys.

isUserLoggedIn()

Check if user is logged in.

protected isUserLoggedIn([int $user_id = null ][, string $userlogin_session_key = '' ]) : bool

After called this method and it was true then you can access total sessions via totalLoggedInSessions property.
After called this method and cookie is valid then you can access cookie data via userSessionCookieData property.
If there is simultaneous login and user's setting is something that is not allowed (such as logout previous, logout all), it will be process here.

Parameters
$user_id : int = null

The user ID. Set to null (default) to auto detect from cookie.

$userlogin_session_key : string = ''

The logged in session key. Set to empty string (default) to auto detect from cookie.

Return values
bool

Return true if logged in, false for not.

maybeRunCron()

Maybe run cron job if config is set to not use server cron.

protected maybeRunCron() : mixed

responseJson()

{@inheritDoc}

protected responseJson(mixed $output) : string
Parameters
$output : mixed
Return values
string

responseXml()

{@inheritDoc}

protected responseXml(mixed $output) : string
Parameters
$output : mixed
Return values
string

sessionTraitLogoutAll()

Logout all succeeded login sessions, lock user account, send login link to user's email.

protected sessionTraitLogoutAll(int $user_id, UserLoginsDb $UserLoginsDb, UserFieldsDb $UserFieldsDb) : mixed

This method also set cache that email was sent recently.
This method was called from isUserLoggedIn().
This method was called from LoginController->doLogin().

Parameters
$user_id : int
$UserLoginsDb : UserLoginsDb
$UserFieldsDb : UserFieldsDb

setBasicConfig()

Setup basic PHP configurations such as default timezone.

protected setBasicConfig() : mixed

setCssAssets()

Set CSS assets for common admin pages.

protected setCssAssets(Assets $Assets, array<string|int, mixed> $assetsData) : mixed

This is required to make basic admin pages working correctly.

Parameters
$Assets : Assets

The Assets class.

$assetsData : array<string|int, mixed>

The assets data. Please read more on \Rdb\Modules\RdbAdmin\Libraries\Assets::addMultipleAssets().

setHeaderAllowOrigin()

Set header allow origin for CORS.

protected setHeaderAllowOrigin() : mixed

setJsAssetsAndObject()

Set JS assets and its object for XHR common data.

protected setJsAssetsAndObject(Assets $Assets, array<string|int, mixed> $assetsData) : mixed

This is required to make basic admin pages working correctly.

Parameters
$Assets : Assets

The Assets class.

$assetsData : array<string|int, mixed>

The assets data. Please read more on \Rdb\Modules\RdbAdmin\Libraries\Assets::addMultipleAssets().

doUpdateModule()

Do update the module.

private doUpdateModule(string $mname) : array<string|int, mixed>

This will run module update command and Installer->update() of selected module will be execute.
It is the same as running via command line php rdb system:module update --mname=xxx (where xxx is Module folder name).

Parameters
$mname : string

Module system name to be run with update command.

Tags
since
1.2.10
see
Module::executeUpdate()
Return values
array<string|int, mixed>

Return associative array:
formResultStatus (string) The form result error status. This key exists only when there is an error.
formResultMessage (string) The error message. This key exists only when there is an error.

isModuleExcute()

Check if current call is `Modules->execute()`

private isModuleExcute() : bool

This method was called from maybeRunCron(), __construct().

Tags
since
1.2.9
Return values
bool

Return true if it is, false if it is not.

sessionsTraitCheckIsLoggedInFromContainer()

Check is logged in from container if exists.

private sessionsTraitCheckIsLoggedInFromContainer() : array<string|int, mixed>

The check data in container must not older than N seconds.

Tags
since
1.2.9
Return values
array<string|int, mixed>

Return indexed array where first index is UsersSessionsTrait object in the container if exists. This value can be null.
Second index is result of "is logged in". This value can be null.

sessionTraitLogoutPreviousSessions()

Logout all sessions before latest succeeded login. (logout only succeeded login).

private sessionTraitLogoutPreviousSessions(int $user_id, UserLoginsDb $UserLoginsDb) : mixed

This method was called from isUserLoggedIn().

Parameters
$user_id : int
$UserLoginsDb : UserLoginsDb

validateActions()

Validate form actions.

private validateActions(string $module_ids, string $modulesystemnames, string $currentModule, string $action) : array<string|int, mixed>

This method was called from doActionsAction() method.

This method will be send out HTTP status if failed to validate.

Parameters
$module_ids : string

The selected module IDs as string (from the form).

$modulesystemnames : string

The selected module system names as string (from the from).

$currentModule : string

Current module folder name (usually RdbAdmin).

$action : string

The selected action.

Return values
array<string|int, mixed>

Return associative array with keys:
action The selected action.
module_ids The selected module IDs.
formResultStatus (optional) If contain any error, it also send out HTTP response code.
formResultMessage (optional) If contain any error, it also send out HTTP response code.
moduleIdsArray The module ids in array.
moduleSystemNameArray The module system names in array.
actionsFormOk The boolean value of form validation. It will be true if form validation passed, and will be false if it is not.


        
On this page

Search results