From: <gem...@li...> - 2012-03-01 15:21:58
|
Revision: 529 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=529&view=rev Author: matijsdejong Date: 2012-03-01 15:21:51 +0000 (Thu, 01 Mar 2012) Log Message: ----------- First round in simplifying ModelSnippetActionAbstract Plus bugfix in DatabaseModelAbstract.php for certain filter cases Modified Paths: -------------- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php trunk/library/classes/Gems/Default/MailJobAction.php trunk/library/classes/Gems/Default/MailLogAction.php trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php Modified: trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-03-01 15:21:51 UTC (rev 529) @@ -47,14 +47,16 @@ abstract class Gems_Controller_ModelSnippetActionAbstract extends MUtil_Controller_ModelSnippetActionAbstract { /** - * The parameters used for the autofilter action. + * Gems only parameters used for the autofilter action. Can be overruled + * by setting $this->autofilterParameters * * @var array Mixed key => value array for snippet initialization */ - protected $autofilterParameters = array( + private $_autofilterExtraParameters = array( 'browse' => true, 'containingId' => 'autofilter_target', 'keyboard' => true, + 'onEmpty' => 'getOnEmpty', ); /** @@ -118,6 +120,21 @@ public $util; /** + * The automatically filtered result + * + * @param $resetMvc When true only the filtered resulsts + */ + public function autofilterAction($resetMvc = true) + { + // Already done when this value is false + if ($resetMvc) { + $this->autofilterParameters = $this->autofilterParameters + $this->_autofilterExtraParameters; + } + + return parent::autofilterAction($resetMvc); + } + + /** * Outputs the model to excel, applying all filters and searches needed * * When you want to change the output, there are two places to check: @@ -224,6 +241,16 @@ } /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('Nothing found...'); + } + + /** * Returns the current html/head/title for this page. * * If the title is an array the seperator concatenates the parts. @@ -249,6 +276,16 @@ } /** + * Action for showing a browse page + */ + public function indexAction() + { + $this->autofilterParameters = $this->autofilterParameters + $this->_autofilterExtraParameters; + + return parent::indexAction(); + } + + /** * Intializes the html component. * * @param boolean $reset Throws away any existing html output when true Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2012-03-01 15:21:51 UTC (rev 529) @@ -53,18 +53,6 @@ public $project; /** - * The automatically filtered result - * - * @param $resetMvc When true only the filtered resulsts - */ - public function autofilterAction($resetMvc = true) - { - $this->autofilterParameters['onEmpty'] = $this->_('No automatic mail jobs found...'); - - parent::autofilterAction($resetMvc); - } - - /** * Action for showing a create new item page */ public function createAction() @@ -178,6 +166,16 @@ } /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('No automatic mail jobs found...'); + } + + /** * Action for showing a browse page */ public function indexAction() Modified: trunk/library/classes/Gems/Default/MailLogAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailLogAction.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Default/MailLogAction.php 2012-03-01 15:21:51 UTC (rev 529) @@ -48,6 +48,21 @@ class Gems_Default_MailLogAction extends Gems_Controller_ModelSnippetActionAbstract { /** + * The parameters used for the autofilter action. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array Mixed key => value array for snippet initialization + */ + protected $autofilterParameters = array( + 'extraFilter' => 'getExtraFilter', + 'extraSort' => array('grco_created' => SORT_DESC), + ); + + /** * The snippets used for the autofilter action. * * @var mixed String or array of snippets name @@ -55,19 +70,6 @@ protected $autofilterSnippets = 'Mail_Log_MailLogBrowseSnippet'; /** - * The automatically filtered result - */ - public function autofilterAction($resetMvc = true) - { - $filter = array('grco_organization' => $this->escort->getCurrentOrganization()); - - $this->autofilterParameters['extraFilter'] = $filter; - $this->autofilterParameters['extraSort'] = array('grco_created' => SORT_DESC); - - return parent::autofilterAction($resetMvc); - } - - /** * Creates a model for getModel(). Called only for each new $action. * * The parameters allow you to easily adapt the model to the current action. The $detailed @@ -122,6 +124,26 @@ } /** + * Returns an extra filter for this action + * + * @return array + */ + protected function getExtraFilter() + { + return array('grco_organization' => $this->escort->getCurrentOrganization()); + } + + /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('No mail activity found...'); + } + + /** * Action for showing a browse page */ public function indexAction() Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2012-03-01 15:21:51 UTC (rev 529) @@ -207,6 +207,16 @@ } /** + * Returns the on empty texts for the autofilter snippets + * + * @return string + */ + public function getOnEmpty() + { + return $this->_('No organization found...'); + } + + /** * Action for showing a browse page */ public function indexAction() Modified: trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2012-03-01 15:21:51 UTC (rev 529) @@ -49,6 +49,52 @@ abstract class MUtil_Controller_ModelSnippetActionAbstract extends MUtil_Controller_Action { /** + * Default parameters for createAction, can be overruled by $this->createParameters + * or $this->createEditParameters values with the same key. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array + */ + private $_defaultCreateParameters = array( + 'createData' => true, + ); + + /** + * Default parameters for editAction, can be overruled by $this->editParameters + * or $this->createEditParameters values with the same key. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array + */ + private $_defaultEditParameters = array( + 'createData' => false, + ); + + /** + * Default parameters for all actions, unless overruled by values with the same key at + * the action level + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array + */ + private $_defaultParameters = array( + 'model' => 'getModel', + 'request' => 'getRequest', + ); + + /** * Created in createModel(). * * Always retrieve using $this->getModel(). @@ -60,6 +106,11 @@ /** * The parameters used for the autofilter action. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $autofilterParameters = array(); @@ -74,11 +125,30 @@ /** * The parameters used for the create and edit actions. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $createEditParameters = array(); /** + * The parameters used for the edit actions, overrules any values in + * $this->createEditParameters. + * + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array Mixed key => value array for snippet initialization + */ + protected $createParameters = array(); + + /** * The snippets used for the create and edit actions. * * @var mixed String or array of snippets name @@ -88,6 +158,11 @@ /** * The parameters used for the delete action. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $deleteParameters = array(); @@ -100,8 +175,26 @@ protected $deleteSnippets = 'ModelYesNoDeleteSnippet'; /** + * The parameters used for the edit actions, overrules any values in + * $this->createEditParameters. + * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * + * @var array Mixed key => value array for snippet initialization + */ + protected $editParameters = array(); + + /** * The parameters used for the index action minus those in autofilter. * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $indexParameters = array(); @@ -123,6 +216,11 @@ /** * The parameters used for the show action * + * When the value is a function name of that object, then that functions is executed + * with the array key as single parameter and the return value is set as the used value + * - unless the key is an integer in which case the code is executed but the return value + * is not stored. + * * @var array Mixed key => value array for snippet initialization */ protected $showParameters = array(); @@ -165,6 +263,29 @@ } /** + * + * @param array $input + * @return array + */ + protected function _processParameters(array $input) + { + $output = array(); + + foreach ($input + $this->_defaultParameters as $key => $value) { + if (is_string($value) && method_exists($this, $value)) { + $value = $this->$value($key); + + if (is_integer($key) || ($value === null)) { + continue; + } + } + $output[$key] = $value; + } + + return $output; + } + + /** * Set the action key in request * * Use this when an action is a Ajax action for retrieving @@ -197,10 +318,9 @@ } if ($this->autofilterSnippets) { - $this->autofilterParameters['model'] = $this->getModel(); - $this->autofilterParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->autofilterParameters); - $this->addSnippets($this->autofilterSnippets, $this->autofilterParameters); + $this->addSnippets($this->autofilterSnippets, $params); } if ($resetMvc && MUtil_Echo::hasOutput()) { @@ -216,28 +336,13 @@ public function createAction() { if ($this->createEditSnippets) { - $this->createEditParameters['createData'] = true; - $this->createEditParameters['model'] = $this->getModel(); - $this->createEditParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->createParameters + $this->createEditParameters + $this->_defaultCreateParameters); - $this->addSnippets($this->createEditSnippets, $this->createEditParameters); + $this->addSnippets($this->createEditSnippets, $params); } } /** - * Action for showing a delete item page - */ - public function deleteAction() - { - if ($this->deleteSnippets) { - $this->deleteParameters['model'] = $this->getModel(); - $this->deleteParameters['request'] = $this->getRequest(); - - $this->addSnippets($this->deleteSnippets, $this->deleteParameters); - } - } - - /** * Creates a model for getModel(). Called only for each new $action. * * The parameters allow you to easily adapt the model to the current action. The $detailed @@ -251,16 +356,26 @@ abstract protected function createModel($detailed, $action); /** + * Action for showing a delete item page + */ + public function deleteAction() + { + if ($this->deleteSnippets) { + $params = $this->_processParameters($this->deleteParameters); + + $this->addSnippets($this->deleteSnippets, $params); + } + } + + /** * Action for showing a edit item page */ public function editAction() { if ($this->createEditSnippets) { - $this->createEditParameters['createData'] = false; - $this->createEditParameters['model'] = $this->getModel(); - $this->createEditParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->editParameters + $this->createEditParameters + $this->_defaultEditParameters); - $this->addSnippets($this->createEditSnippets, $this->createEditParameters); + $this->addSnippets($this->createEditSnippets, $params); } } @@ -293,27 +408,23 @@ return $this->_model; } - /** * Action for showing a browse page */ public function indexAction() { if ($this->indexStartSnippets || $this->indexStopSnippets) { - $this->indexParameters = $this->indexParameters + $this->autofilterParameters; + $params = $this->_processParameters($this->indexParameters + $this->autofilterParameters); - $this->indexParameters['model'] = $this->getModel(); - $this->indexParameters['request'] = $this->getRequest(); - if ($this->indexStartSnippets) { - $this->addSnippets($this->indexStartSnippets, $this->indexParameters); + $this->addSnippets($this->indexStartSnippets, $params); } } $this->autofilterAction(false); if ($this->indexStopSnippets) { - $this->addSnippets($this->indexStopSnippets, $this->indexParameters); + $this->addSnippets($this->indexStopSnippets, $params); } } @@ -323,10 +434,9 @@ public function showAction() { if ($this->showSnippets) { - $this->showParameters['model'] = $this->getModel(); - $this->showParameters['request'] = $this->getRequest(); + $params = $this->_processParameters($this->showParameters); - $this->addSnippets($this->showSnippets, $this->showParameters); + $this->addSnippets($this->showSnippets, $params); } } } Modified: trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php =================================================================== --- trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-03-01 14:06:23 UTC (rev 528) +++ trunk/library/classes/MUtil/Model/DatabaseModelAbstract.php 2012-03-01 15:21:51 UTC (rev 529) @@ -722,7 +722,15 @@ $wheres[] = $sqlField . ' LIKE \'%' . $search . '%\''; } } - $filter[] = implode(' ' . Zend_Db_Select::SQL_OR . ' ', $wheres); + + if ($wheres) { + $filter[] = implode(' ' . Zend_Db_Select::SQL_OR . ' ', $wheres); + } else { + // When all fields are multiOption fields that do not result in a + // filter, then there is no existing filter and the result set + // should always be empty. + $filter[] = '1=0'; + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |