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
Afficher le fichier Open project: openeyes/openeyes Class Usage Examples

Méthodes publiques

Свойство 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

Свойство Type Description
$action_types array Override for custom actions.
$open_elements

Méthodes publiques

Méthode 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 )

Méthodes protégées

Méthode 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

Méthode Description
updateUniqueCode ( $event ) Update Unique code for the event associated the specific procedures.

Method Details

accessRules() public méthode

public accessRules ( )

actionCreate() public méthode

Carries out the base create action.
public actionCreate ( ) : boolean | string
Résultat boolean | string

actionDelete() public méthode

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

actionElementForm() public méthode

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 méthode

public actionEventImage ( )

actionPDFPrint() public méthode

public actionPDFPrint ( $id )

actionPrint() public méthode

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

actionRequestDeletion() public méthode

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

actionSaveCanvasImages() public méthode

public actionSaveCanvasImages ( $id )

actionUpdate() public méthode

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

actionView() public méthode

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

actionViewPreviousElements() public méthode

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

afterCreateElements() protected méthode

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

afterUpdateElements() protected méthode

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

beforeAction() protected méthode

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

behaviors() public méthode

public behaviors ( )

canCopy() public méthode

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

canViewPrevious() public méthode

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

checkAdminAccess() public méthode

public checkAdminAccess ( ) : boolean
Résultat boolean

checkCreateAccess() public méthode

public checkCreateAccess ( ) : boolean
Résultat boolean

checkDeleteAccess() public méthode

public checkDeleteAccess ( ) : boolean
Résultat boolean

checkEditAccess() public méthode

public checkEditAccess ( ) : boolean
Résultat boolean

checkFormAccess() public méthode

public checkFormAccess ( ) : boolean
Résultat boolean

checkPrintAccess() public méthode

public checkPrintAccess ( ) : boolean
Résultat boolean

checkRequestDeleteAccess() public méthode

public checkRequestDeleteAccess ( ) : boolean
Résultat boolean

checkViewAccess() public méthode

public checkViewAccess ( ) : boolean
Résultat boolean

displayErrors() public méthode

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

getActionType() public méthode

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

getAssetPathForElement() public méthode

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

getChildElements() public méthode

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

getChildOptionalElements() public méthode

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

getControllerPrefix() protected méthode

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

getCurrent_episode() public méthode

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

getElementForElementForm() protected méthode

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()
Résultat BaseEventTypeElement

getElementModulePathAlias() public méthode

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
Résultat string

getElementViewPathAlias() protected méthode

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

getElements() public méthode

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

getElementsForElementType() protected méthode

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
Résultat array

getEpisode() public méthode

Get the current episode for the firm and patient.
public getEpisode ( ) : Episode
Résultat Episode

getEpisodes() public méthode

Get all the episodes for the current patient.
public getEpisodes ( ) : array
Résultat array

getEventElements() protected méthode

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

getOpenElementByClassName() public méthode

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

getOptionalElements() public méthode

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

getTitle() public méthode

public getTitle ( )

hasPrevious() public méthode

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
Résultat boolean

init() public méthode

public init ( )

initAction() protected méthode

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

initActionCreate() protected méthode

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

initActionDelete() protected méthode

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

initActionRequestDeletion() protected méthode

Sets the the css state.

initActionUpdate() protected méthode

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

initActionView() protected méthode

Sets the the css state.
protected initActionView ( )

initWithEventId() protected méthode

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

isHiddenInUI() public méthode

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
Résultat boolean

isPrintAction() public méthode

Override to use $action_types.
public isPrintAction ( string $action ) : boolean
$action string
Résultat boolean

isRequired() public méthode

Is this a required element?
public isRequired ( BaseEventTypeElement $element ) : boolean
$element BaseEventTypeElement
Résultat boolean

isRequiredInUI() public méthode

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

persistPcrRisk() protected méthode

protected persistPcrRisk ( )

printHTML() protected méthode

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

printInit() protected méthode

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

printLog() protected méthode

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

processJsVars() public méthode

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

redirectToPatientEpisodes() protected méthode

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

renderChildOpenElements() public méthode

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 méthode

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 méthode

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 méthode

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

renderOpenElements() public méthode

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 méthode

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

renderOptionalElements() public méthode

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 méthode

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
Résultat string

saveEvent() public méthode

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
Résultat boolean

saveEventComplexAttributesFromData() protected méthode

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

setAndValidateElementsFromData() protected méthode

Returns any validation errors that arise.
protected setAndValidateElementsFromData ( array $data ) : array
$data array
Résultat array $errors

setElementComplexAttributesFromData() protected méthode

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 méthode

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 méthode

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

setOpenElements() public méthode

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

setOpenElementsFromCurrentEvent() protected méthode

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 méthode

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

setTitle() public méthode

public setTitle ( $title )

setValidationScenarioForElement() protected méthode

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

updateEventInfo() protected méthode

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

verifyActionAccess() protected méthode

protected verifyActionAccess ( CAction $action )
$action CAction

Property Details

$action_types protected_oe static_oe property

Override for custom actions.
protected static array $action_types
Résultat 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