Documentation

ViewGenerator
in package

Description of ViewGenerator

Tags
author

ritt0r

todo

Refactor

todo

Currently, composite primary keys cannot be handled

Table of Contents

Constants

VIEW_FORM  = 1
Detail view - Shows a form to add/edit/copy an entity
VIEW_LIST  = 0
Overview view - Lists all entities in form of a table
VIEW_SHOW  = 2
Readonly view - Displays of a single entity

Properties

$componentOptions  : array<string|int, mixed>
$currentView  : int
One of {@see static::VIEW_LIST}, {@see static::VIEW_FORM} or {@see static::VIEW_SHOW} which represents the view the ViewGenerator is currently rendering.
$cx  : Cx
$filterableFields  : array<string|int, mixed>
$formGenerator  : FormGenerator
$increment  : int
$listingController  : ListingController
$object  : object
$options  : array<string|int, mixed>
$viewId  : int

Methods

__construct()  : mixed
__toString()  : string
Creates a string out of the ViewGenerator object
callCallbackByInfo()  : mixed
Calls the given callback with the given arguments
getCopyUrl()  : Url
Get the Url to copy an entry in this VG instance
getCreateUrl()  : Url
Get the Url to create an entry in this VG instance
getCurrentView()  : int
Get info about the view currently being rendered.
getDeleteUrl()  : Url
Get the Url to delete an entry of this VG instance
getEditUrl()  : Url
Get the Url to edit an entry of this VG instance
getExtendedSearchUrl()  : Url
Get the Url to perform extended search in this VG instance
getObject()  : object
This function will return the object of the ViewGenerator
getPagingUrl()  : Url
Get the Url to a paging position in the entries in this VG instance
getParam()  : array<string|int, mixed>|string
Extracts values for a VG instance from a combined VG-style variable
getSearchUrl()  : Url
Get the Url to perform search in this VG instance
getSessionIdx()  : string
Get index for session storage access for this VG-instance
getSessionIdxParts()  : array<string|int, mixed>
Get VG-instance identifiers
getShowUrl()  : Url
Get the Url to show an entry of this VG instance
getSortUrl()  : Url
Get the Url to sort entries in this VG instance
getVgAddUrl()  : Url
Get the Url to add an entry of a VG instance
getVgCopyUrl()  : Url
Get the Url to copy an entry of a VG instance
getVgCreateUrl()  : Url
Get the Url to create an entry in a VG instance
getVgDeleteUrl()  : Url
Get the Url to delete an entry of a VG instance
getVgEditUrl()  : Url
Get the Url to edit an entry of a VG instance
getVgExtendedSearchUrl()  : Url
Get the Url to perform extended search in a VG instance
getVgPagingUrl()  : Url
Get the Url to a paging position in the entries in this VG instance
getVgSearchUrl()  : Url
Get the Url to perform search in a VG instance
getVgShowUrl()  : Url
Get the Url to show an entry of a VG instance
getVgSortUrl()  : Url
Get the Url to sort entries in a VG instance
getViewId()  : int
Get view id
render()  : string
This function finds out what we want to render and then renders the form
appendVgParam()  : mixed
Appends a VG-style parameter to an Url object
callPostCallback()  : mixed
Call a callback after the entity has already been saved.
callStorecallback()  : mixed
Use custom callback to store an attribute
checkBlankPostRequest()  : bool
This function checks if a post request contains any data besides csrf
findEntityClass()  : string
This function is used to find the namespace of a passed object This sets $this->object
getBaseUrl()  : Url
Gets the Url object used to build Urls for this VG
getEntryId()  : int
This function returns the EntryId which was sent over get or post (if both are set it will take get)
getFieldList()  : array<string|int, mixed>
Returns the list of fields for the current render object(s), including custom fields
getId()  : string
Parses the mixed type $entryOrId param for all the get...Url methods
getListingController()  : ListingController
Returns the listing controller for this ViewGenerator
getListingControllerOptions()  : array<string|int, mixed>
Initializes the options to pass to the listing controller
getPagingControl()  : string
assumes paging is enabled This renders the template for paging control element
getRenderOptions()  : array<string|int, mixed>
Get updated renderObject, renderArray, entityClassWithNS, entityId and actionUrl.
getShowId()  : string
Parses the mixed type $entryOrId param for all the get...Url methods
getSortOrder()  : array<string|int, mixed>
Returns the validated sort order array for this view
getVgParam()  : array<string|int, mixed>|string
Extracts values for this VG instance from a combined VG-style variable
initializeColumnSorting()  : mixed
Initializes values for "sort by column" function
initializeDragNDropSorting()  : mixed
Initialize the manual (/drag'n'drop) sorting functionality
initializeOptions()  : mixed
Initializes local options based on all supplied options This sets $this->options
initializeSorting()  : mixed
Initializes sort options
initializeStatusOption()  : mixed
Initialize the row status functionality
orderData()  : array<string|int, mixed>
Order an array by a given list
removeEntries()  : mixed
For each id in $deleteIds, call removeEntry to delete the entry.
removeEntry()  : mixed
This function is used to delete an entry
renderFormForEntry()  : string
This function will render the form for a given entry by id. If id is null, an empty form will be loaded
saveEntries()  : mixed
Save multiple entities.
saveEntry()  : bool
This function saves an entity to the database
savePropertiesToClass()  : mixed
This function saves the data of an entity to its class.
setProperCancelUrl()  : mixed
Sets the cancel url for the given param
storeSingleValuedAssociation()  : mixed
Adds/sets a foreign entity (1:1 or n:1)
validateForm()  : bool
This function checks if a form is valid

Constants

VIEW_FORM

Detail view - Shows a form to add/edit/copy an entity

public int VIEW_FORM = 1

VIEW_LIST

Overview view - Lists all entities in form of a table

public int VIEW_LIST = 0

Properties

$componentOptions

protected array<string|int, mixed> $componentOptions

component options

$currentView

One of {@see static::VIEW_LIST}, {@see static::VIEW_FORM} or {@see static::VIEW_SHOW} which represents the view the ViewGenerator is currently rendering.

protected int $currentView = 0

Initial view is static::VIEW_LIST.

$filterableFields

protected array<string|int, mixed> $filterableFields = array()

List of fields that are filterable

$increment

protected static int $increment = 0

This ID is used to store the next free $viewId

$viewId

protected int $viewId

This ID is used as html id for the view so we can load more than one view

Methods

__construct()

public __construct(mixed $object[, array<string|int, mixed> $options = array() ]) : mixed
Parameters
$object : mixed

Array, instance of DataSet, instance of EntityBase, object

$options : array<string|int, mixed> = array()

component options

Tags
global

array $_ARRAYLANG array containing the language variables

throws
ViewGeneratorException

if there is any error in try catch statement

__toString()

Creates a string out of the ViewGenerator object

public __toString() : string
Tags
access

public

Return values
string

the object ViewGenerator as string

callCallbackByInfo()

Calls the given callback with the given arguments

public static callCallbackByInfo(array<string|int, mixed> $info, array<string|int, mixed> $arguments[, bool $throwIfNoCallback = false ]) : mixed

If the callback is a JsonAdapter, $info must have the indexes "adapter" and "method" set.

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

Callable or JsonAdapter

$arguments : array<string|int, mixed>

Associative array of arguments

$throwIfNoCallback : bool = false

If set to true, throws an exception on error

Tags
throws
ViewGeneratorException

If $throwIfNoCallback is true and an error happens

getCopyUrl()

Get the Url to copy an entry in this VG instance

public getCopyUrl(int|string|array<string|int, mixed>|object $entryOrId[, Url $url = null ]) : Url
Parameters
$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with copy arguments

getCreateUrl()

Get the Url to create an entry in this VG instance

public getCreateUrl([Url $url = null ]) : Url
Parameters
$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with create arguments

getCurrentView()

Get info about the view currently being rendered.

public getCurrentView() : int
Return values
int

One of static::VIEW_LIST, static::VIEW_FORM or static::VIEW_SHOW.

getDeleteUrl()

Get the Url to delete an entry of this VG instance

public getDeleteUrl(int|string|array<string|int, mixed>|object $entryOrId) : Url
Parameters
$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

Return values
Url

URL with delete arguments

getEditUrl()

Get the Url to edit an entry of this VG instance

public getEditUrl(int|string|array<string|int, mixed>|object $entryOrId[, Url $url = null ]) : Url
Parameters
$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with edit arguments

getExtendedSearchUrl()

Get the Url to perform extended search in this VG instance

public getExtendedSearchUrl(array<string|int, mixed> $criteria[, Url $url = null ]) : Url
Parameters
$criteria : array<string|int, mixed>

field=>value type array

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with extended search arguments

getObject()

This function will return the object of the ViewGenerator

public getObject() : object
Tags
access

public

Return values
object

the object of ViewGenerator

getPagingUrl()

Get the Url to a paging position in the entries in this VG instance

public getPagingUrl(int $pos[, Url $url = null ]) : Url
Parameters
$pos : int

Position offset number

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with sort arguments

getParam()

Extracts values for a VG instance from a combined VG-style variable

public static getParam(mixed $vgId, string $param) : array<string|int, mixed>|string
Parameters
$vgId : mixed
$param : string

VG-style param

Tags
see
getEntryId()

for a description of VG-style variable format

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

The relevant contents of the supplied parameter

getSearchUrl()

Get the Url to perform search in this VG instance

public getSearchUrl(string $term[, Url $url = null ]) : Url
Parameters
$term : string

Search term

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with search arguments

getSessionIdx()

Get index for session storage access for this VG-instance

public getSessionIdx() : string
Return values
string

Index to be used for session storage

getSessionIdxParts()

Get VG-instance identifiers

public getSessionIdxParts() : array<string|int, mixed>

Use to get the identifying parts for this VG-instance to be used for session storage access. Do use this to set the option sessionIdx in $_SESSION['vgOptions'].

Return values
array<string|int, mixed>

List of VG-instance identifiers

getShowUrl()

Get the Url to show an entry of this VG instance

public getShowUrl(int|string|array<string|int, mixed>|object $entryOrId[, Url $url = null ]) : Url
Parameters
$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with edit arguments

getSortUrl()

Get the Url to sort entries in this VG instance

public getSortUrl(array<string|int, mixed> $sort[, Url $url = null ]) : Url
Parameters
$sort : array<string|int, mixed>

field=>SORT_ASC|SORT_DESC type array

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with sort arguments

getVgAddUrl()

Get the Url to add an entry of a VG instance

public static getVgAddUrl(int $vgId[, Url $url = null ]) : Url
Parameters
$vgId : int

ViewGenerator id

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with copy arguments

getVgCopyUrl()

Get the Url to copy an entry of a VG instance

public static getVgCopyUrl(int $vgId, int|string|array<string|int, mixed>|object $entryOrId[, Url $url = null ]) : Url
Parameters
$vgId : int

ViewGenerator id

$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with copy arguments

getVgCreateUrl()

Get the Url to create an entry in a VG instance

public static getVgCreateUrl(int $vgId[, Url $url = null ]) : Url
Parameters
$vgId : int

ID of the VG for the parameter

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with create arguments

getVgDeleteUrl()

Get the Url to delete an entry of a VG instance

public static getVgDeleteUrl(int $vgId, int|string|array<string|int, mixed>|object $entryOrId) : Url
Parameters
$vgId : int

ID of the VG for the parameter

$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

Return values
Url

URL with delete arguments

getVgEditUrl()

Get the Url to edit an entry of a VG instance

public static getVgEditUrl(int $vgId, int|string|array<string|int, mixed>|object $entryOrId[, Url $url = null ]) : Url
Parameters
$vgId : int

ViewGenerator id

$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with edit arguments

getVgExtendedSearchUrl()

Get the Url to perform extended search in a VG instance

public static getVgExtendedSearchUrl(int $vgId, array<string|int, mixed> $criteria[, Url $url = null ]) : Url
Parameters
$vgId : int

ID of the VG for the parameter

$criteria : array<string|int, mixed>

field=>value type array

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with extended search arguments

getVgPagingUrl()

Get the Url to a paging position in the entries in this VG instance

public static getVgPagingUrl(int $vgId, int $pos[, Url $url = null ]) : Url
Parameters
$vgId : int

ID of the VG for the parameter

$pos : int

Position offset number

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with sort arguments

getVgSearchUrl()

Get the Url to perform search in a VG instance

public static getVgSearchUrl(int $vgId, string $term[, Url $url = null ]) : Url
Parameters
$vgId : int

ID of the VG for the parameter

$term : string

Search term

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with search arguments

getVgShowUrl()

Get the Url to show an entry of a VG instance

public static getVgShowUrl(int $vgId, int|string|array<string|int, mixed>|object $entryOrId[, Url $url = null ]) : Url
Parameters
$vgId : int

ViewGenerator id

$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with edit arguments

getVgSortUrl()

Get the Url to sort entries in a VG instance

public static getVgSortUrl(int $vgId, array<string|int, mixed> $sort[, Url $url = null ]) : Url
Parameters
$vgId : int

ID of the VG for the parameter

$sort : array<string|int, mixed>

field=>ASC|DESC type array

$url : Url = null

(optional) If supplied necessary params are applied

Return values
Url

URL with sort arguments

getViewId()

Get view id

public getViewId() : int
Return values
int

ViewGenerator id

render()

This function finds out what we want to render and then renders the form

public render([bool &$isSingle = false ]) : string
Parameters
$isSingle : bool = false

if we only render one entry

Tags
access

public

Return values
string

rendered view

appendVgParam()

Appends a VG-style parameter to an Url object

protected static appendVgParam(Url $url, int $vgId, string $name, string $value) : mixed

VG-style means: {<vgIncrementNumber>,(=)}(,...)

Parameters
$url : Url

Url object to apply params to

$vgId : int

ID of the VG for the parameter

$name : string

Parameter name

$value : string

Parameter value

callPostCallback()

Call a callback after the entity has already been saved.

protected callPostCallback(mixed $name, mixed $entity, mixed $entityData) : mixed
Parameters
$name : mixed

string name of field

$entity : mixed

\Cx\Model\Base\EntityBase object of the class to be saved

$entityData : mixed

array data for entity

Return values
mixed

Return value of the callback

callStorecallback()

Use custom callback to store an attribute

protected callStorecallback(mixed $name, mixed $entityData, mixed $entity) : mixed
Parameters
$name : mixed

string name of attribute

$entityData : mixed

array post values

$entity : mixed
Return values
mixed

edited value

checkBlankPostRequest()

This function checks if a post request contains any data besides csrf

protected checkBlankPostRequest() : bool
Tags
access

protected

global

array $_ARRAYLANG array containing the language variables

Return values
bool

true if $_POST is empty

findEntityClass()

This function is used to find the namespace of a passed object This sets $this->object

protected findEntityClass(object $object, array<string|int, mixed> $options) : string
Parameters
$object : object

object of which the namespace is needed

$options : array<string|int, mixed>

All options supplied to this ViewGenerator

Tags
access

protected

Return values
string

namespace of the passed object

getBaseUrl()

Gets the Url object used to build Urls for this VG

protected static getBaseUrl() : Url
Return values
Url

Url object used to build Urls for this VG

getEntryId()

This function returns the EntryId which was sent over get or post (if both are set it will take get)

protected getEntryId() : int

$_GET['editid'] has the following format: {<vg_incr_no>,<id_to_edit>}[,{<vg_incr_no>,<id_to_edit>}[,...] <id_to_edit> can be a number, string or set of both, separated by comma

Tags
access

protected

Return values
int

0 if no entry was found

getFieldList()

Returns the list of fields for the current render object(s), including custom fields

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

Currently this returns the fields in arbitrary order. This may change in the future.

Tags
throws
ViewGeneratorException

If $this->object is not yet initialized

Return values
array<string|int, mixed>

List of field names

getId()

Parses the mixed type $entryOrId param for all the get...Url methods

protected static getId(int|string|array<string|int, mixed>|object $entryOrId) : string
Parameters
$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

Return values
string

Entity identifier

getListingController()

Returns the listing controller for this ViewGenerator

protected getListingController(mixed $renderObject, string $entityClass) : ListingController
Parameters
$renderObject : mixed

Entity name or DataSet

$entityClass : string

Fully qualified name of the entity class

Return values
ListingController

ListingController for this ViewGenerator

getListingControllerOptions()

Initializes the options to pass to the listing controller

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

List of ListingController options

getPagingControl()

assumes paging is enabled This renders the template for paging control element

protected getPagingControl(int $pageLength, int $dataLength, int $offset, array<string|int, mixed> $urlArgs) : string
Parameters
$pageLength : int

Number of elements per page

$dataLength : int

Total length of data elements

$offset : int

Current paging offset

$urlArgs : array<string|int, mixed>

List of query fields of the current URL to include

Return values
string

HTML code for paging control

getRenderOptions()

Get updated renderObject, renderArray, entityClassWithNS, entityId and actionUrl.

protected getRenderOptions(mixed $renderObject, string $entityClassWithNS, int $entityId[, string $entityTitle = '' ][, null $actionUrl = null ]) : array<string|int, mixed>
Parameters
$renderObject : mixed
$entityClassWithNS : string
$entityId : int
$entityTitle : string = ''
$actionUrl : null = null
Tags
throws
ViewGeneratorException
throws
MappingException
Return values
array<string|int, mixed>

getShowId()

Parses the mixed type $entryOrId param for all the get...Url methods

protected static getShowId(int|string|array<string|int, mixed>|object $entryOrId) : string
Parameters
$entryOrId : int|string|array<string|int, mixed>|object

Entity or entity key

Return values
string

Entity identifier

getSortOrder()

Returns the validated sort order array for this view

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

List of 'ASC' and 'DESC' indexed by field names

getVgParam()

Extracts values for this VG instance from a combined VG-style variable

protected getVgParam(string $param) : array<string|int, mixed>|string
Parameters
$param : string

VG-style param

Tags
see
getEntryId()

for a description of VG-style variable format

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

The relevant contents of the supplied parameter

initializeColumnSorting()

Initializes values for "sort by column" function

protected initializeColumnSorting() : mixed

initializeDragNDropSorting()

Initialize the manual (/drag'n'drop) sorting functionality

protected initializeDragNDropSorting(string $entityNameSpace) : mixed
Parameters
$entityNameSpace : string

entity namespace

initializeOptions()

Initializes local options based on all supplied options This sets $this->options

protected initializeOptions(string $entityWithNS, mixed $options) : mixed
Parameters
$entityWithNS : string

Fully qualified name of the entity class

$options : mixed

initializeSorting()

Initializes sort options

protected initializeSorting(string $entityNameSpace) : mixed
Parameters
$entityNameSpace : string

entity namespace

initializeStatusOption()

Initialize the row status functionality

protected initializeStatusOption(string $entityNameSpace) : mixed
Parameters
$entityNameSpace : string

entity namespace

orderData()

Order an array by a given list

protected orderData(mixed $orderList, mixed $renderArray) : array<string|int, mixed>
Parameters
$orderList : mixed

array order list

$renderArray : mixed

array to order

Return values
array<string|int, mixed>

ordered data

removeEntries()

For each id in $deleteIds, call removeEntry to delete the entry.

protected removeEntries(mixed $entityWithNS, mixed $deleteIds) : mixed

If it is the last ID in the array, set $doRedirect to true for the removeEntry function to redirect.

Parameters
$entityWithNS : mixed
$deleteIds : mixed
Tags
throws
OptimisticLockException
throws
TransactionRequiredException

removeEntry()

This function is used to delete an entry

protected removeEntry(string $entityWithNS, int $deleteId[, bool $doRedirect = true ][, bool $showMessage = true ]) : mixed
Parameters
$entityWithNS : string

class name including namespace

$deleteId : int

id of entity to delete

$doRedirect : bool = true

return or redirect

$showMessage : bool = true

if message should be displayed if the remove was successful.

Tags
access

protected

global

array $_ARRAYLANG array containing the language variables

throws
Exception

renderFormForEntry()

This function will render the form for a given entry by id. If id is null, an empty form will be loaded

protected renderFormForEntry(int $entityId[, bool $readOnly = false ]) : string
Parameters
$entityId : int

id of the entity

$readOnly : bool = false

if entity is only readable

Tags
access

protected

Return values
string

rendered view

saveEntries()

Save multiple entities.

protected saveEntries(string $entityWithNS, array<string|int, mixed> $entities) : mixed
Parameters
$entityWithNS : string

class name with namespace

$entities : array<string|int, mixed>

array with all entities and their content

Tags
global

array $_ARRAYLANG array containing the language variables

saveEntry()

This function saves an entity to the database

protected saveEntry(string $entityWithNS[, int $entityId = 0 ][, array<string|int, mixed> $entityData = array() ]) : bool

Adds messages to \Message on error. On success, no message is added.

Parameters
$entityWithNS : string

class name including namespace

$entityId : int = 0

id of entity

$entityData : array<string|int, mixed> = array()

custom post data to save

Tags
global

array $_ARRAYLANG array containing the language variables

Return values
bool

true if a success message should be shown. false if there was an error or nothing to to.

savePropertiesToClass()

This function saves the data of an entity to its class.

protected savePropertiesToClass(object $entity, ClassMetadata $entityClassMetadata[, array<string|int, mixed> $entityData = array() ][, string $associatedTo = '' ]) : mixed

This only prepares the database store, but does not store it in database To store them in database use persist and flush from doctrine

Parameters
$entity : object

object of the class we want to save

$entityClassMetadata : ClassMetadata

MetaData for the entity

$entityData : array<string|int, mixed> = array()

array with data to save to class

$associatedTo : string = ''

the class which is oneToManyAssociated if it exists

Tags
access

protected

setProperCancelUrl()

Sets the cancel url for the given param

protected setProperCancelUrl(string $parameterName) : mixed
Parameters
$parameterName : string

name of the param

Tags
access

protected

storeSingleValuedAssociation()

Adds/sets a foreign entity (1:1 or n:1)

protected storeSingleValuedAssociation(string $targetEntity, array<string|int, mixed> $criteria, object $entity, string $methodName) : mixed
Parameters
$targetEntity : string

FQCN of foreign entity

$criteria : array<string|int, mixed>

Criteria to fetch the entity to set

$entity : object

Entity to set foreign entity of

$methodName : string

Name of method to set entity

validateForm()

This function checks if a form is valid

protected validateForm() : bool
Tags
access

protected

global

array $_ARRAYLANG array containing the language variables

Return values
bool

true if form is valid


        
On this page

Search results