From: <gem...@li...> - 2011-09-26 16:29:11
|
Revision: 75 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=75&view=rev Author: matijsdejong Date: 2011-09-26 16:29:02 +0000 (Mon, 26 Sep 2011) Log Message: ----------- - documented Echo and added hasOutput function - continued new Model Action Modified Paths: -------------- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php trunk/library/classes/Gems/Default/MailLogAction.php trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php trunk/library/classes/MUtil/Echo.php trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php Added Paths: ----------- trunk/library/snippets/Generic/ModelItemTableSnippet.php Modified: trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2011-09-26 11:48:45 UTC (rev 74) +++ trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2011-09-26 16:29:02 UTC (rev 75) @@ -81,6 +81,34 @@ protected $indexSnippets = 'Generic_AutosearchForm'; /** + * The snippets used for the show action + * + * @var mixed String or array of snippets name + */ + protected $showSnippets = 'Generic_ModelItemTableSnippet'; + + /** + * Finds the first item with one of the actions specified as parameter and using the current controller + * + * @param string $action + * @param string $action2 + * @return Gems_Menu_SubMenuItem + */ + protected function firstAllowedMenuItem($action, $action2 = null) + { + $actions = MUtil_Ra::args(func_get_args()); + $controller = $this->_getParam('controller'); + + foreach ($actions as $action) { + $menuItem = $this->menu->find(array('controller' => $controller, 'action' => $action, 'allowed' => true)); + + if ($menuItem) { + return $menuItem; + } + } + } + + /** * Intializes the html component. * * @param boolean $reset Throws away any existing html output when true Modified: trunk/library/classes/Gems/Default/MailLogAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailLogAction.php 2011-09-26 11:48:45 UTC (rev 74) +++ trunk/library/classes/Gems/Default/MailLogAction.php 2011-09-26 16:29:02 UTC (rev 75) @@ -50,6 +50,43 @@ class Gems_Default_MailLogAction extends Gems_Controller_ModelSnippetActionAbstract { /** + * Adds columns from the model to the bridge that creates the browse table. + * + * Adds a button column to the model, if such a button exists in the model. + * + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @rturn void + */ + public function addTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) + { + if ($menuItem = $this->firstAllowedMenuItem('show')) { + $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); + } + + // Newline placeholder + $br = MUtil_Html::create('br'); + + $bridge->addMultiSort('grco_created', $br, 'respondent_name', $br, 'grco_address'); + $bridge->addMultiSort('grco_id_token', $br, 'assigned_by', $br, 'grco_sender'); + $bridge->addMultiSort('grco_topic'); + } + + /** + * The automatically filtered result + */ + public function autofilterAction($resetMvc = true) + { + $filter = array('grco_organization' => $this->escort->getCurrentOrganization()); + + $this->autofilterParameters['addTableColumns'] = array($this, 'addTableColumns'); + $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 @@ -107,11 +144,7 @@ { $this->html->h3($this->_('Mail Activity Log')); - $filter = array('grco_organization' => $this->escort->getCurrentOrganization()); - - $this->indexParameters['extraFilter'] = $filter; - $this->indexParameters['extraSort'] = array('grco_created' => SORT_DESC); - + // MUtil_Echo::track($this->indexParameters); parent::indexAction(); } } Modified: trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2011-09-26 11:48:45 UTC (rev 74) +++ trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2011-09-26 16:29:02 UTC (rev 75) @@ -77,6 +77,20 @@ protected $indexSnippets = null; /** + * The parameters used for the show action + * + * @var array Mixed key => value array for snippet initialization + */ + protected $showParameters = array(); + + /** + * The snippets used for the show action + * + * @var mixed String or array of snippets name + */ + protected $showSnippets = 'ModelVerticalTableSnippet'; + + /** * Set the action key in request * * Use this when an action is a Ajax action for retrieving @@ -93,6 +107,8 @@ /** * The automatically filtered result + * + * @param $resetMvc When true only the filtered resulsts */ public function autofilterAction($resetMvc = true) { @@ -112,10 +128,14 @@ $this->addSnippets($this->autofilterSnippets, $this->autofilterParameters); } + + if ($resetMvc && MUtil_Echo::hasOutput()) { + $this->html->raw(MUtil_Echo::out()); + } } /** - * Action for showing a browse page, optional with + * Action for showing a browse page */ public function indexAction() { @@ -131,4 +151,19 @@ $this->autofilterAction(false); } + + /** + * Action for showing an item page + */ + public function showAction() + { + if ($this->showSnippets) { + $this->showParameters = $this->indexParameters + $this->autofilterParameters; + + $this->showParameters['model'] = $this->getModel(); + $this->showParameters['request'] = $this->getRequest(); + + $this->addSnippets($this->showSnippets, $this->showParameters); + } + } } Modified: trunk/library/classes/MUtil/Echo.php =================================================================== --- trunk/library/classes/MUtil/Echo.php 2011-09-26 11:48:45 UTC (rev 74) +++ trunk/library/classes/MUtil/Echo.php 2011-09-26 16:29:02 UTC (rev 75) @@ -1,68 +1,96 @@ <?php - -/** - * 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 - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * 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 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - + /** - * @package MUtil + * 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 + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package MUtil + * @subpackage Echo + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ */ +/** + * This class allows you to echo debug statements over multiple requests by + * storing the output in the session. + * + * @package MUtil + * @subpackage Echo + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.0 + */ class MUtil_Echo { + /** + * Add's a backtrace of the position of the code + * where this function is called. + * + * The function itself is not in the backtrace. + * + * @return void + */ public static function backtrace() { - $trace = debug_backtrace(false); + $trace = debug_backtrace(false); - $content = "\n<h8><b>Print backtrace</b></h8>\n<br/>\n"; - foreach ($trace as $key => $line) { - if (0 === $key) { - // First line is different - $content .= '<i>Starting backtrace at</i>: '; - } else { - if (isset($line['type'])) { - $content .= $line['class'] . $line['type']; + $content = "\n<h8><b>Print backtrace</b></h8>\n<br/>\n"; + foreach ($trace as $key => $line) { + if (0 === $key) { + // First line is different + $content .= '<i>Starting backtrace at</i>: '; + } else { + if (isset($line['type'])) { + $content .= $line['class'] . $line['type']; + } + if (isset($line['function'])) { + $content .= $line['function'] . '() '; + } } - if (isset($line['function'])) { - $content .= $line['function'] . '() '; + if (isset($line['file'])) { + $content .= $line['file']; } + if (isset($line['line'])) { + $content .= ' (' . $line['line'] . ')'; + } + $content .= "<br/>\n"; } - if (isset($line['file'])) { - $content .= $line['file']; - } - if (isset($line['line'])) { - $content .= ' (' . $line['line'] . ')'; - } - $content .= "<br/>\n"; - } - $session = self::getSession(); - $session->content .= $content . "\n"; + $session = self::getSession(); + $session->content .= $content . "\n"; } + /** + * Returns the current session namespace that stores the content. + * + * @staticvar Zend_Session_Namespace $session + * @return Zend_Session_Namespace + */ private static function getSession() { static $session; @@ -74,6 +102,22 @@ return $session; } + /** + * Returns true if there is information to output. + * + * @return boolean + */ + public static function hasOutput() + { + $session = self::getSession(); + return isset($session->content); + } + + /** + * Returns and resets the content of the output/ + * + * @return string Raw html content. + */ public static function out() { $session = self::getSession(); @@ -89,11 +133,23 @@ } } + /** + * Outputs a wordwrapped string with an optional caption. + * + * @param string $var The variable to wordwrap + * @param string $caption Optional text descibing the variable or moment of debugging. + */ public static function pre($var, $caption = null) { self::r(wordwrap((string) $var, 120), $caption); } + /** + * Adds the content of a variable and an optional caption to the output. + * + * @param mixed $var Any kind of variable + * @param string $caption Optional text descibing the variable or moment of debugging. + */ public static function r($var, $caption = null) { $session = self::getSession(); @@ -121,13 +177,26 @@ $session->content .= $content; } + /** + * Adds multiple variables to the output (without captions). + * + * @param mixed $var_1 Any kind of variable + * @param mixed $var_2 Optional, any kind of variable + */ public static function rs($var_1, $var_2 = null) { foreach (func_get_args() as $var) { self::r($var); } } - + + /** + * Adds multiple variables to the output with as caption information on the line + * of code that called this function. + * + * @param mixed $var_1 Any kind of variable + * @param mixed $var_2 Optional, any kind of variable + */ public static function track($var_1, $var_2 = null) { $trace = debug_backtrace(false); @@ -144,7 +213,7 @@ $header .= ': ' . $trace[0]['line']; } - + foreach (func_get_args() as $var) { self::r($var, $header); $header = null; Modified: trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php =================================================================== --- trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php 2011-09-26 11:48:45 UTC (rev 74) +++ trunk/library/classes/MUtil/Snippets/ModelTableSnippetAbstract.php 2011-09-26 16:29:02 UTC (rev 75) @@ -57,6 +57,13 @@ protected $_marker; /** + * Functional extension: optionally use this function to add the browse columns + * + * @var callable With signature: function(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) + */ + public $addTableColumns; + + /** * Url parts added to each link in the resulting table * * @var array @@ -71,13 +78,6 @@ public $browse = false; /** - * When true the post parameters are removed from the request while filtering - * - * @var boolean Should post variables be removed from the request? - */ - public $removePost = false; - - /** * Content to show when there are no rows. * * Null shows '…' @@ -87,6 +87,13 @@ public $onEmpty = null; /** + * When true the post parameters are removed from the request while filtering + * + * @var boolean Should post variables be removed from the request? + */ + public $removePost = false; + + /** * Adds columns from the model to the bridge that creates the browse table. * * Overrule this function to add different columns to the browse table, without @@ -139,7 +146,11 @@ $bridge->setBaseUrl($this->baseUrl); } - $this->addBrowseTableColumns($bridge, $model); + if (is_callable($this->addTableColumns)) { + call_user_func($this->addTableColumns, $bridge, $model); + } else { + $this->addBrowseTableColumns($bridge, $model); + } return $bridge->getTable(); } Copied: trunk/library/snippets/Generic/ModelItemTableSnippet.php (from rev 74, trunk/library/classes/MUtil/Snippets/Standard/ModelVerticalTableSnippet.php) =================================================================== --- trunk/library/snippets/Generic/ModelItemTableSnippet.php (rev 0) +++ trunk/library/snippets/Generic/ModelItemTableSnippet.php 2011-09-26 16:29:02 UTC (rev 75) @@ -0,0 +1,103 @@ +<?php + + +/** + * 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 + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * 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 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * @package Gems + * @subpackage Snippets + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * Displays each fields of a single item in a model in a row in a Html table + * the model set through the $model snippet parameter. + * + * @package MUtil + * @subpackage Gems + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.2 + */ +class Generic_ModelItemTableSnippet extends MUtil_Snippets_ModelVerticalTableSnippetAbstract +{ + /** + * The PHP class used to create the VerticalTableBridge. + * + * Must be instanceof MUtil_Model_VerticalTableBridge. + * + * @var string Class name + */ + // protected $bridgeClass = 'Gems_Model_ThreeColumnTableBridge'; + + /** + * Shortfix to add class attribute + * + * @var string + */ + protected $class = 'displayer'; + + /** + * Required + * + * @var Gems_Loader + */ + protected $loader; + + /** + * Required + * + * @var Gems_Menu + */ + protected $menu; + + /** + * + * @var MUtil_Model_ModelAbstract + */ + protected $model; + + /** + * Required + * + * @var Zend_Controller_Request_Abstract + */ + protected $request; + + /** + * Creates the model + * + * @return MUtil_Model_ModelAbstract + */ + protected function createModel() + { + return $this->model; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |