PHP Class BaseEventTypeController

BaseEventTypeController is the base controller for modules managing events within OpenEyes. It implements a standardised design pattern to provide the general CRUD interface for module events. The controller is designed to be stateful. When an action is called, the state of the controller is determined from the POST and GET attributes of the request. Properties on the controller are populated through a series of methods, and the response is rendered based on these values, and returned to the user. The rationale behind this is that each of the methods provide discrete hooks which can be overridden in module controllers to redefine what the controller properties should be set to. The primary property of the controller to be manipulated is the {@link open_elements} which defines the elements of the event to be displayed in whatever action is being performed. An abstract class in all but name, it should be used for all event based modules. Specific methods can be implemented in module level controllers that will be called automatically by this base controller. Specifically setting defaults on elements and setting complex attributes on individual elements can be handled in specific methods, as defined by
  • {@link setElementDefaultOptions}
  • {@link setElementComplexAttributesFromData}
  • {@link saveElementComplexAttributesFromData}
It's worth noting that at the moment there is no class for Events at the module level. As a result, the controller tends to contain certain business logic that should really be part of the event. Such behaviour should be written in a way that it can be easily extracted into a separate class. The intention in the future is that this would be abstracted into (at a minimum) a helper class, or ideally into an actual event class that would contain all business logic for manipulating the event and its elements. Furthermore no $_POST, $_GET or session data should be utilised within the element models. Data should be extracted by controllers and passed to methods on the element models. In the future, models may be instantiated in different context where these globals would not be available.
Inheritance: extends BaseModuleController
Mostra file Open project: openeyes/openeyes Class Usage Examples

Public Properties

Property Type Description
$dont_redirect
$editable
$editing
$episode
$event * @var Event
$eventIssueCreate String to set an issue when an event is created
$event_actions
$event_tabs
$extraViewProperties defines additional variables to be available in view templates
$layout
$moduleStateCssClass
$patient * @var Patient
$pdf_print_documents
$pdf_print_html
$pdf_print_suffix
$renderPatientPanel
$site * @var Site
$successUri

Protected Properties

Property Type Description
$action_types array Override for custom actions.
$open_elements

Public Methods

Method Description
accessRules ( )
actionCreate ( ) : boolean | string Carries out the base create action.
actionDelete ( $id ) Delete the event given by $id. Performs the soft delete action if it's been confirmed by $_POST.
actionElementForm ( integer $id, integer $patient_id, integer $previous_id = null ) Ajax method for loading an individual element (and its children).
actionEventImage ( )
actionPDFPrint ( $id )
actionPrint ( integer $id ) Print action.
actionRequestDeletion ( $id ) : boolean | void Action to process delete requests for an event.
actionSaveCanvasImages ( $id )
actionUpdate ( $id ) The update action for the given event id.
actionView ( $id ) View the event specified by $id.
actionViewPreviousElements ( integer $element_type_id, integer $patient_id ) Ajax method for viewing previous elements.
behaviors ( )
canCopy ( BaseEventTypeElement $element ) : boolean Can an element can be copied from a previous version.
canViewPrevious ( BaseEventTypeElement $element ) : boolean Can we view the previous version of the element.
checkAdminAccess ( ) : boolean
checkCreateAccess ( ) : boolean
checkDeleteAccess ( ) : boolean
checkEditAccess ( ) : boolean
checkFormAccess ( ) : boolean
checkPrintAccess ( ) : boolean
checkRequestDeleteAccess ( ) : boolean
checkViewAccess ( ) : boolean
displayErrors ( $errors, boolean $bottom = false ) Render the given errors with the standard template.
getActionType ( string $action ) : string Return an ACTION_TYPE_ constant representing the type of an action for authorisation purposes.
getAssetPathForElement ( BaseEventTypeElement $element ) : string Return the asset path for the given element (by interrogating namespace).
getChildElements ( ElementType $parent_type ) : BaseEventTypeElement[] Get the open child elements for the given ElementType.
getChildOptionalElements ( ElementType $parent_type ) : BaseEventTypeElement[] Get the child optional elements for the given element type.
getCurrent_episode ( ) : Episode Wrapper around the episode property on this controller - current_episode is used in patient layouts.
getElementModulePathAlias ( BaseEventTypeElement $element ) : string Return the path alias for the module the element belongs to based on its namespace (assumes elements exist in a namespace below the module namespace).
getElements ( ) : array Get the open elements for the event that are not children.
getEpisode ( ) : Episode Get the current episode for the firm and patient.
getEpisodes ( ) : array Get all the episodes for the current patient.
getOpenElementByClassName ( string $class_name ) : object Get open element by class name.
getOptionalElements ( ) : BaseEventTypeElement[] Get the optional elements for the current module's event type (that are not children).
getTitle ( )
hasPrevious ( ElementType $element_type, integer $exclude_event_id = null ) : boolean Are there one or more previous instances of an element?
init ( )
isHiddenInUI ( BaseEventTypeElement $element ) : boolean Is this element to be hidden in the UI? (Prevents the elements from being displayed on page load.).
isPrintAction ( string $action ) : boolean Override to use $action_types.
isRequired ( BaseEventTypeElement $element ) : boolean Is this a required element?
isRequiredInUI ( BaseEventTypeElement $element ) : boolean Is this element required in the UI? (Prevents the user from being able to remove the element.).
processJsVars ( ) set base js vars for use in the standard scripts for the controller.
renderChildOpenElements ( BaseEventTypeElement $parent_element, string $action, BaseCActiveBaseEventTypeCActiveForm $form = null, array $data = null ) Render the open elements that are children of the given parent element type.
renderChildOptionalElements ( BaseEventTypeElement $parent_element, string $action, BaseCActiveBaseEventTypeCActiveForm $form = null, array $data = null ) Render the optional child elements for the given parent element type.
renderEventMetadata ( string $view = '//patient/event_metadata' ) Renders the metadata of the event with the standard template.
renderOpenElements ( string $action, BaseCActiveBaseEventTypeCActiveForm $form = null, array $data = null ) Render the open elements for the controller state.
renderOptionalElements ( string $action, boolean $form = null, boolean $data = null ) Render the optional elements for the controller state.
renderPartial ( string $view, null $data = null, boolean $return = false, boolean $processOutput = false ) : string Extend the parent method to support inheritance of modules (and rendering the element views from the parent module).
saveEvent ( $data ) : boolean Save the event for this controller - will create or update the event, create and update the elements, delete any elements that are no longer required. Note that $data is provided for the purposes of any extensions to this behaviour that might be required.
setOpenElements ( array $open_elements ) Set the open elements (for unit testing).
setTitle ( $title )

Protected Methods

Method Description
afterCreateElements ( Event $event ) Called after event (and elements) have been created.
afterUpdateElements ( Event $event ) Called after event (and elements) has been updated.
beforeAction ( $action ) : boolean Setup base css/js etc requirements for the eventual action render.
getControllerPrefix ( ) : string Get the prefix name of this controller, used for path calculations for element views.
getElementForElementForm ( ElementType $element_type, integer $previous_id, array() $additional ) : BaseEventTypeElement Initialise an element of $element_type for returning as an individual form. If the $previous_id is provided, then the default values of the element will be overridden with the properties of the previous intance of the element. Similarly, $additional allows specific values to be set on the element.
getElementViewPathAlias ( BaseEventTypeElement $element ) : string calculate the alias dot notated path to an element view.
getElementsForElementType ( ElementType $element_type, $data ) : array Processes provided form data to create 1 or more elements of the provided type.
getEventElements ( ) : BaseEventTypeElement[] Abstraction of getting the elements for the event being controlled to allow more complex overrides (such as workflow) where required.
initAction ( string $action ) Runs initialisation of the controller based on the action. Looks for a method name of.
initActionCreate ( ) Initialise the controller prior to a create action.
initActionDelete ( ) initialise the controller with the event id.
initActionRequestDeletion ( ) Sets the the css state.
initActionUpdate ( ) initialise the controller prior to event update action.
initActionView ( ) Sets the the css state.
initWithEventId ( $id ) Intialise controller property based off the event id.
persistPcrRisk ( )
printHTML ( integer $id, BaseEventTypeElement[] $elements, string $template = 'print' ) Render HTML print layout.
printInit ( integer $id ) Initialise print action.
printLog ( integer $id, boolean $pdf ) Log print action.
redirectToPatientEpisodes ( ) Redirect to the patient episodes when the controller determines the action cannot be carried out.
renderElement ( BaseEventTypeElement $element, string $action, BaseCActiveBaseEventTypeCActiveForm $form, array $data, array $view_data = [], boolean $return = false, boolean $processOutput = false ) Render the individual element based on the action provided. Note that view names for the associated actions are set in the model.
renderOptionalElement ( BaseEventTypeElement $element, string $action, BaseCActiveBaseEventTypeCActiveForm $form, array $data ) Render an optional element.
saveEventComplexAttributesFromData ( $data ) Iterates through the open elements and calls the custom methods for saving complex data attributes to them.
setAndValidateElementsFromData ( array $data ) : array Set the attributes of the given $elements from the given structured array.
setElementComplexAttributesFromData ( BaseEventTypeElement $element, array $data, integer $index = null ) Looks for custom methods to set many to many data defined on elements. This is called prior to validation so should set values without actually touching the database.
setElementDefaultOptions ( BaseEventTypeElement $element, string $action ) set the defaults on the given BaseEventTypeElement.
setElementOptions ( string $action ) Set the default values on each of the open elements.
setOpenElementsFromCurrentEvent ( $action ) based on the current state of the controller, sets the open_elements property, which is the array of relevant open elements for the controller.
setPatient ( $patient_id ) Sets the patient object on the controller.
setValidationScenarioForElement ( $element ) Set the validation scenario for the element if necessary.
updateEventInfo ( ) Generates the info text for controller event from the current elements, sets it on the event and saves it.
verifyActionAccess ( CAction $action )

Private Methods

Method Description
updateUniqueCode ( $event ) Update Unique code for the event associated the specific procedures.

Method Details

accessRules() public method

public accessRules ( )

actionCreate() public method

Carries out the base create action.
public actionCreate ( ) : boolean | string
return boolean | string

actionDelete() public method

Delete the event given by $id. Performs the soft delete action if it's been confirmed by $_POST.
public actionDelete ( $id )
$id

actionElementForm() public method

Ajax method for loading an individual element (and its children).
public actionElementForm ( integer $id, integer $patient_id, integer $previous_id = null )
$id integer
$patient_id integer
$previous_id integer

actionEventImage() public method

public actionEventImage ( )

actionPDFPrint() public method

public actionPDFPrint ( $id )

actionPrint() public method

Print action.
public actionPrint ( integer $id )
$id integer event id

actionRequestDeletion() public method

Action to process delete requests for an event.
public actionRequestDeletion ( $id ) : boolean | void
$id
return boolean | void

actionSaveCanvasImages() public method

public actionSaveCanvasImages ( $id )

actionUpdate() public method

The update action for the given event id.
public actionUpdate ( $id )
$id

actionView() public method

View the event specified by $id.
public actionView ( $id )
$id

actionViewPreviousElements() public method

Ajax method for viewing previous elements.
public actionViewPreviousElements ( integer $element_type_id, integer $patient_id )
$element_type_id integer
$patient_id integer

afterCreateElements() protected method

Called after event (and elements) have been created.
protected afterCreateElements ( Event $event )
$event Event

afterUpdateElements() protected method

Called after event (and elements) has been updated.
protected afterUpdateElements ( Event $event )
$event Event

beforeAction() protected method

Setup base css/js etc requirements for the eventual action render.
protected beforeAction ( $action ) : boolean
$action
return boolean

behaviors() public method

public behaviors ( )

canCopy() public method

Can an element can be copied from a previous version.
public canCopy ( BaseEventTypeElement $element ) : boolean
$element BaseEventTypeElement
return boolean

canViewPrevious() public method

Can we view the previous version of the element.
public canViewPrevious ( BaseEventTypeElement $element ) : boolean
$element BaseEventTypeElement
return boolean

checkAdminAccess() public method

public checkAdminAccess ( ) : boolean
return boolean

checkCreateAccess() public method

public checkCreateAccess ( ) : boolean
return boolean

checkDeleteAccess() public method

public checkDeleteAccess ( ) : boolean
return boolean

checkEditAccess() public method

public checkEditAccess ( ) : boolean
return boolean

checkFormAccess() public method

public checkFormAccess ( ) : boolean
return boolean

checkPrintAccess() public method

public checkPrintAccess ( ) : boolean
return boolean

checkRequestDeleteAccess() public method

checkViewAccess() public method

public checkViewAccess ( ) : boolean
return boolean

displayErrors() public method

Render the given errors with the standard template.
public displayErrors ( $errors, boolean $bottom = false )
$errors
$bottom boolean

getActionType() public method

Return an ACTION_TYPE_ constant representing the type of an action for authorisation purposes.
public getActionType ( string $action ) : string
$action string
return string

getAssetPathForElement() public method

Return the asset path for the given element (by interrogating namespace).
public getAssetPathForElement ( BaseEventTypeElement $element ) : string
$element BaseEventTypeElement
return string

getChildElements() public method

Get the open child elements for the given ElementType.
public getChildElements ( ElementType $parent_type ) : BaseEventTypeElement[]
$parent_type ElementType
return BaseEventTypeElement[] $open_elements

getChildOptionalElements() public method

Get the child optional elements for the given element type.
public getChildOptionalElements ( ElementType $parent_type ) : BaseEventTypeElement[]
$parent_type ElementType
return BaseEventTypeElement[] $optional_elements

getControllerPrefix() protected method

Get the prefix name of this controller, used for path calculations for element views.
protected getControllerPrefix ( ) : string
return string

getCurrent_episode() public method

Wrapper around the episode property on this controller - current_episode is used in patient layouts.
public getCurrent_episode ( ) : Episode
return Episode

getElementForElementForm() protected method

Abstracted to allow overrides in specific module controllers
protected getElementForElementForm ( ElementType $element_type, integer $previous_id, array() $additional ) : BaseEventTypeElement
$element_type ElementType
$previous_id integer
$additional array()
return BaseEventTypeElement

getElementModulePathAlias() public method

Return the path alias for the module the element belongs to based on its namespace (assumes elements exist in a namespace below the module namespace).
public getElementModulePathAlias ( BaseEventTypeElement $element ) : string
$element BaseEventTypeElement
return string

getElementViewPathAlias() protected method

calculate the alias dot notated path to an element view.
protected getElementViewPathAlias ( BaseEventTypeElement $element ) : string
$element BaseEventTypeElement
return string

getElements() public method

Get the open elements for the event that are not children.
public getElements ( ) : array
return array

getElementsForElementType() protected method

Processes provided form data to create 1 or more elements of the provided type.
protected getElementsForElementType ( ElementType $element_type, $data ) : array
$element_type ElementType
$data
return array

getEpisode() public method

Get the current episode for the firm and patient.
public getEpisode ( ) : Episode
return Episode

getEpisodes() public method

Get all the episodes for the current patient.
public getEpisodes ( ) : array
return array

getEventElements() protected method

This should be overridden if the standard elements for the event are affected by the controller state.
protected getEventElements ( ) : BaseEventTypeElement[]
return BaseEventTypeElement[]

getOpenElementByClassName() public method

Get open element by class name.
public getOpenElementByClassName ( string $class_name ) : object
$class_name string
return object

getOptionalElements() public method

Get the optional elements for the current module's event type (that are not children).
public getOptionalElements ( ) : BaseEventTypeElement[]
return BaseEventTypeElement[] $elements

getTitle() public method

public getTitle ( )

hasPrevious() public method

Are there one or more previous instances of an element?
public hasPrevious ( ElementType $element_type, integer $exclude_event_id = null ) : boolean
$element_type ElementType
$exclude_event_id integer
return boolean

init() public method

public init ( )

initAction() protected method

initAction[$action] and calls it.
protected initAction ( string $action )
$action string

initActionCreate() protected method

Initialise the controller prior to a create action.
protected initActionCreate ( )

initActionDelete() protected method

initialise the controller with the event id.
protected initActionDelete ( )

initActionRequestDeletion() protected method

Sets the the css state.

initActionUpdate() protected method

initialise the controller prior to event update action.
protected initActionUpdate ( )

initActionView() protected method

Sets the the css state.
protected initActionView ( )

initWithEventId() protected method

Intialise controller property based off the event id.
protected initWithEventId ( $id )
$id

isHiddenInUI() public method

Is this element to be hidden in the UI? (Prevents the elements from being displayed on page load.).
public isHiddenInUI ( BaseEventTypeElement $element ) : boolean
$element BaseEventTypeElement
return boolean

isPrintAction() public method

Override to use $action_types.
public isPrintAction ( string $action ) : boolean
$action string
return boolean

isRequired() public method

Is this a required element?
public isRequired ( BaseEventTypeElement $element ) : boolean
$element BaseEventTypeElement
return boolean

isRequiredInUI() public method

Is this element required in the UI? (Prevents the user from being able to remove the element.).
public isRequiredInUI ( BaseEventTypeElement $element ) : boolean
$element BaseEventTypeElement
return boolean

persistPcrRisk() protected method

protected persistPcrRisk ( )

printHTML() protected method

Render HTML print layout.
protected printHTML ( integer $id, BaseEventTypeElement[] $elements, string $template = 'print' )
$id integer event id
$elements BaseEventTypeElement[]
$template string

printInit() protected method

Initialise print action.
protected printInit ( integer $id )
$id integer event id

printLog() protected method

Log print action.
protected printLog ( integer $id, boolean $pdf )
$id integer event id
$pdf boolean

processJsVars() public method

set base js vars for use in the standard scripts for the controller.
public processJsVars ( )

redirectToPatientEpisodes() protected method

Redirect to the patient episodes when the controller determines the action cannot be carried out.

renderChildOpenElements() public method

Render the open elements that are children of the given parent element type.
public renderChildOpenElements ( BaseEventTypeElement $parent_element, string $action, BaseCActiveBaseEventTypeCActiveForm $form = null, array $data = null )
$parent_element BaseEventTypeElement
$action string
$form BaseCActiveBaseEventTypeCActiveForm
$data array

renderChildOptionalElements() public method

Render the optional child elements for the given parent element type.
public renderChildOptionalElements ( BaseEventTypeElement $parent_element, string $action, BaseCActiveBaseEventTypeCActiveForm $form = null, array $data = null )
$parent_element BaseEventTypeElement
$action string
$form BaseCActiveBaseEventTypeCActiveForm
$data array

renderElement() protected method

Render the individual element based on the action provided. Note that view names for the associated actions are set in the model.
protected renderElement ( BaseEventTypeElement $element, string $action, BaseCActiveBaseEventTypeCActiveForm $form, array $data, array $view_data = [], boolean $return = false, boolean $processOutput = false )
$element BaseEventTypeElement
$action string
$form BaseCActiveBaseEventTypeCActiveForm
$data array
$view_data array Data to be passed to the view.
$return boolean Whether the rendering result should be returned instead of being displayed to end users.
$processOutput boolean Whether the rendering result should be postprocessed using processOutput.

renderEventMetadata() public method

Renders the metadata of the event with the standard template.
public renderEventMetadata ( string $view = '//patient/event_metadata' )
$view string

renderOpenElements() public method

Render the open elements for the controller state.
public renderOpenElements ( string $action, BaseCActiveBaseEventTypeCActiveForm $form = null, array $data = null )
$action string
$form BaseCActiveBaseEventTypeCActiveForm
$data array

renderOptionalElement() protected method

Render an optional element.
protected renderOptionalElement ( BaseEventTypeElement $element, string $action, BaseCActiveBaseEventTypeCActiveForm $form, array $data )
$element BaseEventTypeElement
$action string
$form BaseCActiveBaseEventTypeCActiveForm
$data array

renderOptionalElements() public method

Render the optional elements for the controller state.
public renderOptionalElements ( string $action, boolean $form = null, boolean $data = null )
$action string
$form boolean
$data boolean

renderPartial() public method

Extend the parent method to support inheritance of modules (and rendering the element views from the parent module).
public renderPartial ( string $view, null $data = null, boolean $return = false, boolean $processOutput = false ) : string
$view string
$data null
$return boolean
$processOutput boolean
return string

saveEvent() public method

Save the event for this controller - will create or update the event, create and update the elements, delete any elements that are no longer required. Note that $data is provided for the purposes of any extensions to this behaviour that might be required.
public saveEvent ( $data ) : boolean
$data
return boolean

saveEventComplexAttributesFromData() protected method

Custom method is of the name format saveComplexAttributes_element_class_name
protected saveEventComplexAttributesFromData ( $data )
$data

setAndValidateElementsFromData() protected method

Returns any validation errors that arise.
protected setAndValidateElementsFromData ( array $data ) : array
$data array
return array $errors

setElementComplexAttributesFromData() protected method

The $data attribute will typically be the $_POST structure, but can be any appropriately structured array The optional $index attribute is the counter for multiple elements of the same type that might exist in source data. The convention for the method name for the element setting is: setComplexAttributes_element_class_name
protected setElementComplexAttributesFromData ( BaseEventTypeElement $element, array $data, integer $index = null )
$element BaseEventTypeElement
$data array
$index integer

setElementDefaultOptions() protected method

Looks for a methods based on the class name of the element: setElementDefaultOptions_[element class name] This method is passed the element and action, which allows for controller methods to manipulate the default values of the element (if the controller state is required for this)
protected setElementDefaultOptions ( BaseEventTypeElement $element, string $action )
$element BaseEventTypeElement
$action string

setElementOptions() protected method

Set the default values on each of the open elements.
protected setElementOptions ( string $action )
$action string

setOpenElements() public method

Set the open elements (for unit testing).
public setOpenElements ( array $open_elements )
$open_elements array

setOpenElementsFromCurrentEvent() protected method

based on the current state of the controller, sets the open_elements property, which is the array of relevant open elements for the controller.
protected setOpenElementsFromCurrentEvent ( $action )

setPatient() protected method

Sets the patient object on the controller.
protected setPatient ( $patient_id )
$patient_id

setTitle() public method

public setTitle ( $title )

setValidationScenarioForElement() protected method

Set the validation scenario for the element if necessary.
protected setValidationScenarioForElement ( $element )
$element

updateEventInfo() protected method

Generates the info text for controller event from the current elements, sets it on the event and saves it.
protected updateEventInfo ( )

verifyActionAccess() protected method

protected verifyActionAccess ( CAction $action )
$action CAction

Property Details

$action_types protected_oe static_oe property

Override for custom actions.
protected static array $action_types
return array

$dont_redirect public_oe property

public $dont_redirect

$editable public_oe property

public $editable

$editing public_oe property

public $editing

$episode public_oe property

public $episode

$event public_oe property

* @var Event
public $event

$eventIssueCreate public_oe property

String to set an issue when an event is created
public $eventIssueCreate

$event_actions public_oe property

public $event_actions

$event_tabs public_oe property

public $event_tabs

$extraViewProperties public_oe property

defines additional variables to be available in view templates
public $extraViewProperties

$layout public_oe property

public $layout

$moduleStateCssClass public_oe property

public $moduleStateCssClass

$open_elements protected_oe property

protected $open_elements

$patient public_oe property

* @var Patient
public $patient

$pdf_print_documents public_oe property

public $pdf_print_documents

$pdf_print_html public_oe property

public $pdf_print_html

$pdf_print_suffix public_oe property

public $pdf_print_suffix

$renderPatientPanel public_oe property

public $renderPatientPanel

$site public_oe property

* @var Site
public $site

$successUri public_oe property

public $successUri