Project Application Core code

package Gems
subpackage Project
copyright Copyright (c) 2011 Erasmus MC
license New BSD License
since Class available since version 1.0

 Methods

Copy from \Zend_Translate_Adapter

_(string $text, string|\Zend_Locale $locale = null) : string

Translates the given string returns the translation

Parameters

$text

string

Translation string

$locale

string\Zend_Locale

(optional) Locale/Language to use, identical with locale identifier, @see \Zend_Locale for more information

Returns

string

Constructor

__construct(\Zend_Application|\Zend_Application_Bootstrap_Bootstrapper $application) : void

Parameters

$application

\Zend_Application\Zend_Application_Bootstrap_Bootstrapper

Set the default mailtransport to our own sendmail version

_initMailTransport() 

This is needed to make sure a correct sender is set when using sendmail. Feel free to set a different default transport method in your project when needed.

Adds one or more messages to the session based message store.

addMessage(mixed $message_args) : \MUtil_Controller_Action

Parameters

$message_args

mixed

Can be an array or multiple argemuents. Each sub element is a single message string

Returns

\MUtil_Controller_Action

Hook 2: Called in $this->run().

beforeRun() : void

This->init() has ran and the constructor has finisched so all _init{name} and application.ini resources have been loaded. The code between the constructor and the call to $this->run() has been executed in $this->run() has hooked $this as both a \Zend_Controller_Plugin and a \Zend_Controller_Action_Helper.

Not initialized are the $request, $response and $controller objects.

Previous hook: init() Actions since: $this->_inti{Name}; resources from configuration initialized Actions after: $this->request object created Next hook: requestChanged()

Hook 10: Called before the $controller->preDispatch() and $controller->{name}Action methods have been called.

controllerBeforeAction(\Zend_Controller_Action $actionController = null) : void

Here you can change or check all values set in $controller->init(). All output echoed here is captured for the output.

Previous hook: controllerInit() Actions since: $controller->init(); ob_start(); $controller->dispatch() Actions after: $controller->preDispatch(); $controller->{name}Action(); $controller->postDispatch() Next hook: controllerAfterAction()

Parameters

$actionController

\Zend_Controller_Action

Hook 9: During action controller initialization.

controllerInit(\Zend_Controller_Action $actionController = null) : void

This hook is called in the constructor of the controller. Nothing is done and $controller->init has not been called, so this is a good moment to change settings that should influence $controller->init().

Previous hook: preDispatch() Actions since: $dispatcher->dispatch(); $controller->__construct() Actions after: $controller->init(); ob_start(); $controller->dispatch() Next hook: controllerBeforeAction()

Parameters

$actionController

\Zend_Controller_Action

Hook 7: Called before \Zend_Controller_Front enters its dispatch loop.

dispatchLoopStartup(\Zend_Controller_Request_Abstract $request) : void

This events enables you to adjust the request after the routing has been done.

This is the final hook before the dispatchLoop starts. All the hooks in the dispatchLoop can be executed more then once.

Not yet initialized is the $controller object - as the $controller can change during the dispatchLoop.

Previous hook: routeShutdown() Actions since: nothing, but the route consisting of controller, action and module should now be fixed Actions after: dispatch loop started Next hook: preDispatch()

Parameters

$request

\Zend_Controller_Request_Abstract

getCurrentOrganization()

getCurrentOrganization() : integer
deprecated Since 1.7.2 Replaced by $this->currentOrganization->getId();

Returns

integerThe current active organization id or 0 when not known

getCurrentUserId()

getCurrentUserId() : integer
deprecated Since 1.7.2 Replaced by $this->currentUser->getUserId();

Returns

integerThe current user id or 0 when not known.

Return the directories where the Database Administrator Model (DbaModel) should look for sql creation files.

getDatabasePaths() : array

Returns

arrayOf index => array('path' =>, 'name' =>, 'db' =>,)

Retrieve the GemsEscort object

getInstance() : \GemsEscort
Static

Returns

\GemsEscort

Type access to $this->loader

getLoader() : \Gems_Loader

Returns

\Gems_LoaderOr a subclassed version when specified in the project code

The prefix / directory paths where the Gems Loaders should look

getLoaderDirs() : array

Returns

array

Retrieves / sets the messenger

getMessenger() : \Zend_Controller_Action_Helper_FlashMessenger

Returns

\Zend_Controller_Action_Helper_FlashMessenger

Generate random password

getRandomPassword() : string

Returns

string

Returns a static session, that will not be affected by loading or unloading a user

getStaticSession() : \Zend_Session_Namespace

Returns

\Zend_Session_Namespace

Type access to $this->util

getUtil() : \Gems_Util

Returns

\Gems_UtilOr a subclassed version when specified in the project code

Returns true if the given role or role of the current user has the given privilege

hasPrivilege(string $privilege, string $role = null) : boolean
deprecated Since 1.7.2 Replaced by $this->currentUser->hasPrivilege();

Parameters

$privilege

string

$role

string

Returns

boolean

Return a hashed version of the input value.

passwordHash(string $value, $isNew = false, string $name = null, array $context = array()) : string
deprecated Since 1.5

Parameters

$value

string

The value to hash.

$isNew

$name

string

Optional name, is here for ModelAbstract setOnSave compatibility

$context

array

Optional, the other values being saved

Returns

stringThe salted hash as a 32-character hexadecimal number.

Copy from \Zend_Translate_Adapter

plural(string $singular, string $plural, integer $number, string|\Zend_Locale $locale = null) : string

Translates the given string using plural notations Returns the translated string

see

Parameters

$singular

string

Singular translation string

$plural

string

Plural translation string

$number

integer

Number for detecting the correct plural

$locale

string\Zend_Locale

(Optional) Locale/Language to use, identical with locale identifier, @see \Zend_Locale for more information

Returns

string

Hook 12: Called after an action is dispatched by \Zend_Controller_Dispatcher.

postDispatch(\Zend_Controller_Request_Abstract $request) : void

This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (via {@link \Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}), a new action may be specified for dispatching.

\Zend_Layout_Controller_Plugin_Layout uses this event to change the output of the $response with the rendering of the layout. As the Layout plugin has a priority of 99, this Escort event will take place before the layout is rendered, unless $this->run() was called with a stackIndex lower than zero.

Previous hook: controllerAfterAction() Actions since: ob_get_clean(); $response->appendBody() Actions after: while (! Request->isDispatched()) or back to Hook 8 preDispatch() Next hook: dispatchLoopShutdown()

Parameters

$request

\Zend_Controller_Request_Abstract

Hook 8: Start of dispatchLoop. Called before an action is dispatched by \Zend_Controller_Dispatcher.

preDispatch(\Zend_Controller_Request_Abstract $request) : void

This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (via \Zend_Controller_Request_Abstract::setDispatched()), the current action may be skipped.

Not yet initialized is the $controller object - as the $controller can change during the dispatchLoop.

Previous hook: dispatchLoopStartup() or new loop Actions since: dispatch loop started Actions after: $dispatcher->dispatch(); $controller->__construct() Next hook: controllerInit()

Parameters

$request

\Zend_Controller_Request_Abstract

Hook function called during controllerInit

prepareController() 

return @void

Hook 3: Called in $this->setRequest.

requestChanged(\Zend_Controller_Request_Abstract $request) : void

All resources have been loaded and the $request object is created. Theoretically this event can be triggered multiple times, but this does not happen in a standard Zend application.

Not initialized are the $response and $controller objects.

Previous hook: beforeRun() Actions since: $this->request object created Actions after: $this->response object created Next hook: responseChanged()

Parameters

$request

\Zend_Controller_Request_Abstract

Hook 4: Called in $this->setResponse.

responseChanged(\Zend_Controller_Response_Abstract $response) : void

All resources have been loaded and the $request and $response object have been created. Theoretically this event can be triggered multiple times, but this does not happen in a standard Zend application.

Not initialized is the $controller object and the routing has not yet been executed.

Previous hook: requestChanged() Initialized since: the $this->response object Next hook: routeStartup()

Parameters

$response

Hook 6: Called after \Zend_Controller_Router has determined the route set by the request.

routeShutdown(\Zend_Controller_Request_Abstract $request) : void

This events enables you to adjust the route after the routing has run it's course.

Not initialized is the $controller object.

Previous hook: routeStartup() Actions since: $router->route() Actions after: nothing, but the route consisting of controller, action and module should now be fixed Next hook: dispatchLoopStartup()

Also sets $this->currentOrganization and $this->menu to access afterwards

Parameters

$request

\Zend_Controller_Request_Abstract

setControllerDirectory()

setControllerDirectory(\Zend_Controller_Request_Abstract $request) 

Parameters

$request

Create an exception for the error, depending on processing position we either set the response exception or throw the exception if the response is

setError(string $message, integer $code = 200, string $info = null, boolean $isSecurity = false

Parameters

$message

string

$code

integer

$info

string

$isSecurity

boolean

Exceptions

\exception

Handle the exception depending on processing position we either set the response exception or throw the exception if the response is

setException(\exception $e) 

Parameters

$e

\exception

Exceptions

\exception

Function to maintain uniformity of access to variables from the bootstrap object.

_copyVariables(Object $object) : void

Copies all variables to the target object.

Parameters

$object

Object

An object who gets all variables from this object.

Initialize the access log.

_initAccesslog() : \Gems_AccessLog

Use $this->accesslog to access afterwards

Returns

\Gems_AccessLog

Initialize the database.

_initAcl() : \MUtil_Acl

Use $this->acl to access afterwards

Returns

\MUtil_Acl

Does nothing but add's the Gems Actionhelper path

_initActionHelpers() 

Initialize the basepath string holde object.

_initBasepath() : \Gems_Loader

Use $this->basepath to access afterwards

Returns

\Gems_Loader

Create a default file cache for the Translate and DB adapters to speed up execution

_initCache() : \Zend_Cache_Core

Returns

\Zend_Cache_Core

Initialize the currentUser component.

_initCurrentUser() : \Gems_User_User

You can overrule this function to specify your own project translation method / file.

Use $this->currentUser to access afterwards

Returns

\Gems_User_User

Initialize the database.

_initDb() : \Zend_Db

Use $this->db to access afterwards

Returns

\Zend_Db

Initialize the Project or Gems loader.

_initLoader() : \Gems_Loader

Use $this->loader to access afterwards

Returns

\Gems_Loader

Initialize the locale.

_initLocale() : \Zend_Locale

We use this function instead of the standard application.ini setting to simplify overruling the settings.

Also Firefox tends to overrule the locale settings.

You can overrule this function to specify your own project translation method / file.

Use $this->locale to access afterwards

Returns

\Zend_Locale

Initialize the logger

_initLogger() : \Gems_Log

Returns

\Gems_Log

Initialize the OpenRosa survey source

_initOpenRosa() 

Initialize the GEMS project component.

_initProject() : \Gems_Project_ProjectSettings

The project component contains information about this project that are not Zend specific. For example: -- the super administrator, -- the project name, version and description, -- locales used, -- css and image directories used.

This is the place for you to store any project specific data that should not be in the code. I.e. if you make a controllor that needs a setting to work, then put the setting in this settings file.

Use $this->project to access afterwards

Returns

\Gems_Project_ProjectSettings

Initialize the Gems session.

_initSession() : \Zend_Session_Namespace

The session contains information on the registered user from @see $this->loadLoginInfo($username) This includes: -- user_id -- user_login -- user_name -- user_role -- user_locale -- user_organization_id

Use $this->session to access afterwards

deprecated since 1.5

Returns

\Zend_Session_Namespace

Initialize the loader as source component.

_initSource() : \Gems_Loader

You can overrule this function to specify your own project translation method / file.

Use $this->source to access afterwards

Returns

\Gems_Loader

Initialize the translate component.

_initTranslate() : \Zend_Translate

Scans the application and project dirs for available translations

Use $this->translate to access afterwards Also sets $this->translateAdapter to access afterwards

Returns

\Zend_Translate

Initialize the util component.

_initUtil() : \Gems_Util

You can overrule this function to specify your own project translation method / file.

Use $this->util to access afterwards

Returns

\Gems_Util

Initialize the view component and sets some project specific values.

_initView() : \Zend_View

Actions taken here can take advantage that the full framework has been activated by now, including session data, etc.

Use $this->view to access afterwards

Returns

\Zend_View

Add ZFDebug info to the page output.

_initZFDebug() : void

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutContact(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutCrumbs(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutCss() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutFavicon() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutJQuery() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutLocaleSet(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Display either a link to the login screen or displays the name of the current user and a logoff link.

_layoutLogin(array $args = null) : mixed

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutMenuActiveBranch() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutMenuHtml() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutMenuTopLevel() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutMessages(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutNavigation() : mixed

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutOrganizationSwitcher(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutProjectName(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutTime(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutTitle(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutUser(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function called if specified in the Project.ini layoutPrepare section before the layout is drawn, but after the rest of the program has run it's course.

_layoutVersion(array $args = null) : mixed

Parameters

$args

Returns

mixedIf null nothing is set, otherwise the name of the function is used as \Zend_View variable name.

Function to maintain uniformity of access to variables from the bootstrap object.

_updateVariable(String|Array $name) : void

Updates selected variable(s) to the objects targeted in _copyVariables.

Do this when an object is created or when a non-object variable has changed. You do not need to call this method for changes to objects .

Parameters

$name

StringArray

A property name or array of property names to copy from this object to the previous copy targets.

Creates an object of the specified className seareching the loader dirs path

createProjectClass(string $className, mixed $paramOne = null, mixed $paramTwo = null) : object

Parameters

$className

string

$paramOne

mixed

Optional

$paramTwo

mixed

Optional

Returns

object

Searches and loads ini, xml, php or inc file

includeFile(string $fileName) : mixed

When no extension is specified the system looks for a file with the right extension, in the order: .ini, .php, .xml, .inc.

.php and .inc files run within the context of this object and thus can access all $this-> variables and functions.

Parameters

$fileName

string

A filename in the include path

Returns

mixedfalse if nothing was returned

findExtension()

findExtension($fullFileName, array $extensions) 

Parameters

$fullFileName

$extensions

 Properties

 

Set to true for bootstrap projects. Needs html5 set to true as well

$useBootstrap : boolean

Default

false
 

Set to true for html 5 projects

$useHtml5 : boolean

Default

false
 

Targets for _updateVariable

$_copyDestinations : array

Default

 

Static instance

$_instanceOfSelf : self

Default

Static
 

The prefix / directory paths where the Gems Loaders should look

$_loaderDirs : array

Default

 

The project loader

$_projectLoader : \MUtil_Loader_PluginLoader

Default

 

Is firebird logging on (set by constructor from application.ini)

$_startFirebird : boolean

Default

 Constants

 

Default reception code value

RECEPTION_OK = 'OK'