From: <gem...@li...> - 2012-06-14 14:33:49
|
Revision: 763 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=763&view=rev Author: matijsdejong Date: 2012-06-14 14:33:38 +0000 (Thu, 14 Jun 2012) Log Message: ----------- TargetInterface extented with afterRegistry() function ModelAbstract now extends from TargetAbstract Modified Paths: -------------- trunk/library/classes/Gems/Form.php trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php trunk/library/classes/Gems/Model/HiddenOrganizationModel.php trunk/library/classes/Gems/Model/OrganizationModel.php trunk/library/classes/Gems/Model/StaffModel.php trunk/library/classes/Gems/Model.php trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php trunk/library/classes/Gems/Tracker/Model/TrackModel.php trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php trunk/library/classes/MUtil/Model/ModelAbstract.php trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php trunk/library/classes/MUtil/Registry/Source.php trunk/library/classes/MUtil/Registry/TargetAbstract.php trunk/library/classes/MUtil/Registry/TargetInterface.php Modified: trunk/library/classes/Gems/Form.php =================================================================== --- trunk/library/classes/Gems/Form.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Form.php 2012-06-14 14:33:38 UTC (rev 763) @@ -101,6 +101,15 @@ $this->_scripts[] = $script; } + /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry() + { } + public function getScripts() { return $this->_scripts; } Modified: trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php =================================================================== --- trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Loader/TargetLoaderAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -3,7 +3,7 @@ /** * Copyright (c) 2011, Erasmus MC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Erasmus MC nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -36,8 +36,8 @@ */ /** - * LoaderAbstract is used for classes that chain from Gems_Loader. - * + * LoaderAbstract is used for classes that chain from Gems_Loader. + * * As these classes may need setting of values this subclass implements the * checkRegistryRequestsAnswers() easy access to resources. * @@ -48,6 +48,15 @@ class Gems_Loader_TargetLoaderAbstract extends Gems_Loader_LoaderAbstract implements MUtil_Registry_TargetInterface { /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry() + { } + + /** * Allows the loader to set resources. * * @param string $name Name of resource to set Modified: trunk/library/classes/Gems/Model/HiddenOrganizationModel.php =================================================================== --- trunk/library/classes/Gems/Model/HiddenOrganizationModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model/HiddenOrganizationModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -45,23 +45,9 @@ * @license New BSD License * @since Class available since version 1.0 */ -class Gems_Model_HiddenOrganizationModel extends Gems_Model_JoinModel implements MUtil_Registry_TargetInterface +class Gems_Model_HiddenOrganizationModel extends Gems_Model_JoinModel { /** - * Allows the loader to set resources. - * - * @param string $name Name of resource to set - * @param mixed $resource The resource. - * @return boolean True if $resource was OK - */ - public function answerRegistryRequest($name, $resource) - { - $this->$name = $resource; - - return true; - } - - /** * Stores the fields that can be used for sorting or filtering in the * sort / filter objects attached to this model. * @@ -94,36 +80,11 @@ return array(); } - /** - * Should be called after answering the request to allow the Target - * to check if all required registry values have been set correctly. - * - * @return boolean False if required values are missing. - */ - public function checkRegistryRequestsAnswers() - { - return true; - } - - /** - * Filters the names that should not be requested. - * - * Can be overriden. - * - * @param string $name - * @return boolean - */ - protected function filterRequestNames($name) - { - return '_' !== $name[0]; - } - public function getCurrentOrganization() { return GemsEscort::getInstance()->getCurrentOrganization(); } - public function getKeyRef($forData, $href = array(), $organizationInKey = null) { $keys = $this->getKeys(); @@ -148,18 +109,4 @@ return $href; } - - /** - * Allows the loader to know the resources to set. - * - * Returns those object variables defined by the subclass but not at the level of this definition. - * - * Can be overruled. - * - * @return array of string names - */ - public function getRegistryRequests() - { - return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); - } } Modified: trunk/library/classes/Gems/Model/OrganizationModel.php =================================================================== --- trunk/library/classes/Gems/Model/OrganizationModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model/OrganizationModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -45,7 +45,7 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_Model_OrganizationModel extends Gems_Model_ModelAbstract +class Gems_Model_OrganizationModel extends Gems_Model_JoinModel { /** * @var Gems_Loader Modified: trunk/library/classes/Gems/Model/StaffModel.php =================================================================== --- trunk/library/classes/Gems/Model/StaffModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model/StaffModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -46,7 +46,7 @@ * @license New BSD License * @since Class available since version 1.5 */ -class Gems_Model_StaffModel extends Gems_Model_ModelAbstract +class Gems_Model_StaffModel extends Gems_Model_JoinModel { public function __construct(Gems_Loader $loader) { Modified: trunk/library/classes/Gems/Model.php =================================================================== --- trunk/library/classes/Gems/Model.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Model.php 2012-06-14 14:33:38 UTC (rev 763) @@ -96,30 +96,6 @@ protected $util; /** - * Create or loads the class. When only loading, this function returns a StaticCall object that - * can be invoked lazely. - * - * @see MUtil_Lazy_StaticCall - * @see MUtil_Registry_TargetInterface - * - * @param type $name - * @param type $create - * @param array $arguments - * @return Gems_Model_ModelAbstract - */ - protected function _loadClass($name, $create = false, array $arguments = array()) - { - $obj = parent::_loadClass($name, $create, $arguments); - - // If it as a Gems_Model_ModelAbstract, run the init method now - if ($obj instanceof Gems_Model_ModelAbstract) { - $obj->init(); - } - - return $obj; - } - - /** * Link the model to the user_logins table. * * @param Gems_Model_JoinModel $model Modified: trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php =================================================================== --- trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Tracker/Model/StandardTokenModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -65,7 +65,7 @@ * @license New BSD License * @since Class available since version 1.4 */ -class Gems_Tracker_Model_StandardTokenModel extends Gems_Model_HiddenOrganizationModel implements MUtil_Registry_TargetInterface +class Gems_Tracker_Model_StandardTokenModel extends Gems_Model_HiddenOrganizationModel { /** * @@ -183,25 +183,6 @@ } /** - * Allows the source to set request. - * - * @param string $name Name of resource to set - * @param mixed $resource The resource. - * @return boolean True if $resource was OK - */ - public function answerRegistryRequest($name, $resource) - { - if (MUtil_Registry_Source::$verbose) { - MUtil_Echo::r('Resource set: ' . get_class($this) . '->' . __FUNCTION__ . - '("' . $name . '", ' . - (is_object($resource) ? get_class($resource) : gettype($resource)) . ')'); - } - $this->$name = $resource; - - return true; - } - - /** * Sets the labels, format functions, etc... * * @return Gems_Tracker_Model_StandardTokenModel @@ -248,29 +229,6 @@ return $this->translate && $this->util; } - /** - * Filters the names that should not be requested. - * - * Can be overriden. - * - * @param string $name - * @return boolean - */ - protected function filterRequestNames($name) - { - return '_' !== $name[0]; - } - - /** - * Allows the loader to know the resources to set. - * - * @return array of string names - */ - public function getRegistryRequests() - { - return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); - } - public function useRespondentTrackAsKey() { $this->setKeys($this->_getKeysFor('gems__respondent2org') + $this->_getKeysFor('gems__tracks')); Modified: trunk/library/classes/Gems/Tracker/Model/TrackModel.php =================================================================== --- trunk/library/classes/Gems/Tracker/Model/TrackModel.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/Gems/Tracker/Model/TrackModel.php 2012-06-14 14:33:38 UTC (rev 763) @@ -45,11 +45,11 @@ * @license New BSD License * @since Class available since version 1.4 */ -class Gems_Tracker_Model_TrackModel extends MUtil_Model_TableModel implements MUtil_Registry_TargetInterface +class Gems_Tracker_Model_TrackModel extends MUtil_Model_TableModel { /** * Holds the trackData in array with key trackId, for internal caching use only - * + * * @var array */ protected $_trackData = array(); @@ -84,25 +84,6 @@ } /** - * Allows the source to set request. - * - * @param string $name Name of resource to set - * @param mixed $resource The resource. - * @return boolean True if $resource was OK - */ - public function answerRegistryRequest($name, $resource) - { - if (MUtil_Registry_Source::$verbose) { - MUtil_Echo::r('Resource set: ' . get_class($this) . '->' . __FUNCTION__ . - '("' . $name . '", ' . - (is_object($resource) ? get_class($resource) : gettype($resource)) . ')'); - } - $this->$name = $resource; - - return true; - } - - /** * Sets the labels, format functions, etc... * * @param boolean $detailed True when shopwing detailed information @@ -143,29 +124,6 @@ } /** - * Filters the names that should not be requested. - * - * Can be overriden. - * - * @param string $name - * @return boolean - */ - protected function filterRequestNames($name) - { - return '_' !== $name[0]; - } - - /** - * Allows the loader to know the resources to set. - * - * @return array of string names - */ - public function getRegistryRequests() - { - return array_filter(array_keys(get_object_vars($this)), array($this, 'filterRequestNames')); - } - - /** * Get the TrackCompletedEvent for the given trackId * * @param int $trackId Modified: trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -644,7 +644,7 @@ * A ModelAbstract->setOnSave() function that returns the input * date as a valid date. * - * @see Gems_Model_ModelAbstract + * @see MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/ModelAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -57,7 +57,7 @@ * @license New BSD License * @since Class available since version 1.0 */ -abstract class MUtil_Model_ModelAbstract +abstract class MUtil_Model_ModelAbstract extends MUtil_Registry_TargetAbstract { const ALIAS_OF = 'alias_of'; const AUTO_SAVE = 'auto_save'; @@ -788,6 +788,14 @@ return false; } + /** + * This is the place to put code to run after object initialization has finished and when all + * registry requests have been answered + */ + public function init() + { + } + public function is($name, $key, $value) { return $value == $this->_getKeyValue($name, $key); Modified: trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php =================================================================== --- trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Model/Type/ConcatenatedRow.php 2012-06-14 14:33:38 UTC (rev 763) @@ -131,7 +131,7 @@ * A ModelAbstract->setOnLoad() function that concatenates the * value if it is an array. * - * @see Gems_Model_ModelAbstract + * @see MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved @@ -157,7 +157,7 @@ * A ModelAbstract->setOnSave() function that concatenates the * value if it is an array. * - * @see Gems_Model_ModelAbstract + * @see MUtil_Model_ModelAbstract * * @param mixed $value The value being saved * @param boolean $isNew True when a new item is being saved Modified: trunk/library/classes/MUtil/Registry/Source.php =================================================================== --- trunk/library/classes/MUtil/Registry/Source.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Registry/Source.php 2012-06-14 14:33:38 UTC (rev 763) @@ -144,7 +144,13 @@ } // */ } } - return $target->checkRegistryRequestsAnswers(); + if ($target->checkRegistryRequestsAnswers()) { + $target->afterRegistry(); + + return true; + } else { + return false; + } } /** Modified: trunk/library/classes/MUtil/Registry/TargetAbstract.php =================================================================== --- trunk/library/classes/MUtil/Registry/TargetAbstract.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Registry/TargetAbstract.php 2012-06-14 14:33:38 UTC (rev 763) @@ -53,6 +53,15 @@ abstract class MUtil_Registry_TargetAbstract implements MUtil_Registry_TargetInterface { /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry() + { } + + /** * Allows the loader to set resources. * * @param string $name Name of resource to set Modified: trunk/library/classes/MUtil/Registry/TargetInterface.php =================================================================== --- trunk/library/classes/MUtil/Registry/TargetInterface.php 2012-06-14 13:56:33 UTC (rev 762) +++ trunk/library/classes/MUtil/Registry/TargetInterface.php 2012-06-14 14:33:38 UTC (rev 763) @@ -53,6 +53,14 @@ interface MUtil_Registry_TargetInterface { /** + * Called after the check that all required registry values + * have been set correctly has run. + * + * @return void + */ + public function afterRegistry(); + + /** * Allows the source to set request. * * @param string $name Name of resource to set This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |