PHP Class FOF30\Controller\DataController

Inheritance: extends Controller
Mostra file Open project: akeeba/fof Class Usage Examples

Protected Properties

Property Type Description
$cacheParams false | array Variables that should be taken in account while working with the cache. You can set them in Controller constructor or inside onBefore* methods
$cacheableTasks array The tasks for which caching should be enabled by default
$defaultsForAdd array An indexed array of default values for the add task. Since the add task resets the model you can't set these values directly to the model. Instead, the defaultsForAdd values will be fed to model's bind() after it's reset and before the session-stored item data is bound to the model object.
$hasForm boolean Do we have a valid XML form?
$taskPrivileges array You can use the notation '@task' which means 'apply the same privileges as "task"'. If you create a reference back to yourself (e.g. 'mytask' => array('@mytask')) it will return TRUE.

Public Methods

Method Description
__construct ( Container $container, array $config = [] ) Public constructor of the Controller class. You can pass the following variables in the $config array, on top of what you already have in the base Controller class:
add ( ) : void Single record add. The form layout is used to present a blank page.
apply ( ) : void Save the incoming data and then return to the Edit task
archive ( ) : void Archive (set enabled = 2) an item.
browse ( ) : void Implements a default browse task, i.e. read a bunch of records and send them to the browser.
cancel ( ) : void Cancel the edit, check in the record and return to the Browse task
checkin ( ) : void Check in (unlock) items
copy ( ) : void Duplicates selected items
edit ( ) : void Single record edit. The ID set in the request is passed to the model, then the form layout is used to edit the result.
execute ( string $task ) : null | boolean Executes a given controller task. The onBefore and onAfter methods are called automatically if they exist.
forceRemove ( ) : void Deletes the selected item(s). Unlike remove() this method will force delete the record (completely removed from database)
getIDsFromRequest ( DataModel &$model, boolean $loadRecord = true ) : array Gets the list of IDs from the request data
getItemidURLSuffix ( ) : string Gets a URL suffix with the Itemid parameter. If it's not the front-end of the site, or if there is no Itemid set it returns an empty string.
getModel ( string $name = null, array $config = [] ) : DataModel Returns a named Model object. Makes sure that the Model is a database-aware model, throwing an exception otherwise, when $name is null.
getView ( string $name = null, array $config = [] ) : View Returns a named View object
loadhistory ( ) : boolean Method to load a row from version history
orderdown ( ) : void Moves selected items one position down the ordering list
orderup ( ) : void Moves selected items one position up the ordering list
publish ( ) : void Publish (set enabled = 1) an item.
read ( ) : void Single record read. The id set in the request is passed to the model and then the item layout is used to render the result.
remove ( ) : void Delete or trash selected item(s). The model's softDelete flag determines if the items should be trashed (enabled state changed to -2) or deleted (completely removed from database)
save ( ) : void Save the incoming data and then return to the Browse task
savenew ( ) : boolean Save the incoming data and then return to the Add task
saveorder ( ) : void Saves the order of the items
trash ( ) : void Trash (set enabled = -2) an item.
unpublish ( ) : void Unpublish (set enabled = 0) an item.

Protected Methods

Method Description
applySave ( ) : boolean Common method to handle apply and save tasks
checkACL ( string $area ) : boolean Checks if the current user has enough privileges for the requested ACL area. This overridden method supports asset tracking as well.
deleteOrTrash ( $forceDelete = false )
getACLForApplySave ( ) : boolean | string Gets the applicable ACL privilege for the apply and save tasks. The value returned is: - @add if the record's ID is empty / record doesn't exist - True if the ACL privilege of the edit task (@edit) is allowed - @editown if the owner of the record (field user_id, userid or user) is the same as the logged in user - False if the record is not owned by the logged in user and the user doesn't have the @edit privilege
getCrudTask ( ) : string Determines the CRUD task to use based on the view name and HTTP verb used in the request.
onAfterExecute ( string $task ) : boolean Deal with JSON format: no redirects needed

Method Details

__construct() public method

taskPrivileges array ACL privileges for each task cacheableTasks array The cache-enabled tasks
public __construct ( Container $container, array $config = [] )
$container FOF30\Container\Container The application container
$config array The configuration array

add() public method

Single record add. The form layout is used to present a blank page.
public add ( ) : void
return void

apply() public method

Save the incoming data and then return to the Edit task
public apply ( ) : void
return void

applySave() protected method

Common method to handle apply and save tasks
protected applySave ( ) : boolean
return boolean True on success

archive() public method

Archive (set enabled = 2) an item.
public archive ( ) : void
return void

browse() public method

Implements a default browse task, i.e. read a bunch of records and send them to the browser.
public browse ( ) : void
return void

cancel() public method

Cancel the edit, check in the record and return to the Browse task
public cancel ( ) : void
return void

checkACL() protected method

Checks if the current user has enough privileges for the requested ACL area. This overridden method supports asset tracking as well.
protected checkACL ( string $area ) : boolean
$area string The ACL area, e.g. core.manage
return boolean True if the user has the ACL privilege specified

checkin() public method

Check in (unlock) items
public checkin ( ) : void
return void

copy() public method

Duplicates selected items
public copy ( ) : void
return void

deleteOrTrash() protected method

protected deleteOrTrash ( $forceDelete = false )

edit() public method

Single record edit. The ID set in the request is passed to the model, then the form layout is used to edit the result.
public edit ( ) : void
return void

execute() public method

If $task == 'default' we will determine the CRUD task to use based on the view name and HTTP verb in the request, overriding the routing.
public execute ( string $task ) : null | boolean
$task string The task to execute, e.g. "browse"
return null | boolean False on execution failure

forceRemove() public method

Deletes the selected item(s). Unlike remove() this method will force delete the record (completely removed from database)
public forceRemove ( ) : void
return void

getACLForApplySave() protected method

Gets the applicable ACL privilege for the apply and save tasks. The value returned is: - @add if the record's ID is empty / record doesn't exist - True if the ACL privilege of the edit task (@edit) is allowed - @editown if the owner of the record (field user_id, userid or user) is the same as the logged in user - False if the record is not owned by the logged in user and the user doesn't have the @edit privilege
protected getACLForApplySave ( ) : boolean | string
return boolean | string

getCrudTask() protected method

Determines the CRUD task to use based on the view name and HTTP verb used in the request.
protected getCrudTask ( ) : string
return string The CRUD task (browse, read, edit, delete)

getIDsFromRequest() public method

Gets the list of IDs from the request data
public getIDsFromRequest ( DataModel &$model, boolean $loadRecord = true ) : array
$model FOF30\Model\DataModel The model where the record will be loaded
$loadRecord boolean When true, the record matching the *first* ID found will be loaded into $model
return array

getItemidURLSuffix() public method

Gets a URL suffix with the Itemid parameter. If it's not the front-end of the site, or if there is no Itemid set it returns an empty string.
public getItemidURLSuffix ( ) : string
return string The &Itemid=123 URL suffix, or an empty string if Itemid is not applicable

getModel() public method

Returns a named Model object. Makes sure that the Model is a database-aware model, throwing an exception otherwise, when $name is null.
public getModel ( string $name = null, array $config = [] ) : DataModel
$name string The Model name. If null we'll use the modelName variable or, if it's empty, the same name as the Controller
$config array Configuration parameters to the Model. If skipped we will use $this->config
return FOF30\Model\DataModel The instance of the Model known to this Controller

getView() public method

Returns a named View object
public getView ( string $name = null, array $config = [] ) : View
$name string The Model name. If null we'll use the modelName variable or, if it's empty, the same name as the Controller
$config array Configuration parameters to the Model. If skipped we will use $this->config
return FOF30\View\View The instance of the Model known to this Controller

loadhistory() public method

Method to load a row from version history
Since: 2.2
public loadhistory ( ) : boolean
return boolean True if the content history is reverted, false otherwise

onAfterExecute() protected method

Deal with JSON format: no redirects needed
protected onAfterExecute ( string $task ) : boolean
$task string The task being executed
return boolean True if everything went well

orderdown() public method

Moves selected items one position down the ordering list
public orderdown ( ) : void
return void

orderup() public method

Moves selected items one position up the ordering list
public orderup ( ) : void
return void

publish() public method

Publish (set enabled = 1) an item.
public publish ( ) : void
return void

read() public method

Single record read. The id set in the request is passed to the model and then the item layout is used to render the result.
public read ( ) : void
return void

remove() public method

Delete or trash selected item(s). The model's softDelete flag determines if the items should be trashed (enabled state changed to -2) or deleted (completely removed from database)
public remove ( ) : void
return void

save() public method

Save the incoming data and then return to the Browse task
public save ( ) : void
return void

savenew() public method

Save the incoming data and then return to the Add task
public savenew ( ) : boolean
return boolean

saveorder() public method

Saves the order of the items
public saveorder ( ) : void
return void

trash() public method

Trash (set enabled = -2) an item.
public trash ( ) : void
return void

unpublish() public method

Unpublish (set enabled = 0) an item.
public unpublish ( ) : void
return void

Property Details

$cacheParams protected_oe property

Variables that should be taken in account while working with the cache. You can set them in Controller constructor or inside onBefore* methods
protected false|array $cacheParams
return false | array

$cacheableTasks protected_oe property

The tasks for which caching should be enabled by default
protected array $cacheableTasks
return array

$defaultsForAdd protected_oe property

An indexed array of default values for the add task. Since the add task resets the model you can't set these values directly to the model. Instead, the defaultsForAdd values will be fed to model's bind() after it's reset and before the session-stored item data is bound to the model object.
protected array $defaultsForAdd
return array

$hasForm protected_oe property

Do we have a valid XML form?
protected bool $hasForm
return boolean

$taskPrivileges protected_oe property

You can use the notation '@task' which means 'apply the same privileges as "task"'. If you create a reference back to yourself (e.g. 'mytask' => array('@mytask')) it will return TRUE.
protected array $taskPrivileges
return array