|
From: <gem...@li...> - 2011-09-13 18:27:35
|
Revision: 12
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=12&view=rev
Author: matijsdejong
Date: 2011-09-13 17:44:45 +0000 (Tue, 13 Sep 2011)
Log Message:
-----------
- SingleTrack projects will now allow the addition of one track to the patient when none exist
- hidden parameters in menu items are now added to parameter source instead of request, in order to allow filtering
- started cleanup of _createTable in TrackActionAbstract
- created new minimal snippet implementation
Modified Paths:
--------------
trunk/library/classes/Gems/Default/TrackAction.php
trunk/library/classes/Gems/Default/TrackActionAbstract.php
trunk/library/classes/Gems/Menu/SubMenuItem.php
trunk/library/classes/Gems/Menu.php
trunk/library/classes/GemsEscort.php
trunk/library/classes/MUtil/Model/ModelAbstract.php
trunk/library/classes/MUtil/Snippets/SnippetInterface.php
Added Paths:
-----------
trunk/library/classes/MUtil/Snippets/EmptySnippetAbstract.php
trunk/library/snippets/Track/
trunk/library/snippets/Track/AvailableTracksSnippets.php
Modified: trunk/library/classes/Gems/Default/TrackAction.php
===================================================================
--- trunk/library/classes/Gems/Default/TrackAction.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/Gems/Default/TrackAction.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -466,6 +466,8 @@
$request = $this->getRequest();
$model = $this->getModel();
+ // Gems_Menu::$verbose = true;
+
if ($data = $model->applyRequest($request)->loadFirst()) {
$this->setMenuParameters($data);
@@ -522,6 +524,21 @@
$this->html->buttonDiv($links);
}
+ } elseif ($this->escort instanceof Gems_Project_Tracks_SingleTrackInterface) {
+
+ $data['gr2o_patient_nr'] = $this->_getIdParam();
+ $data['gr2o_id_organization'] = $this->escort->getCurrentOrganization();
+ $data['track_can_be_created'] = 1;
+ $this->setMenuParameters($data);
+
+ $model = $this->createTrackModel(false, 'index');
+
+ // MUtil_Model::$verbose = true;
+
+ $this->html->h3($this->_('Add track'));
+ $this->html->pInfo($this->_('This respondent does not yet have an active track. Add one here.'));
+ $this->addSnippet('Track_AvailableTracksSnippets', 'model', $model, 'trackType', $this->trackType);
+
} else {
$this->addMessage(sprintf($this->_('Unknown %s requested'), $this->getTopic()));
}
Modified: trunk/library/classes/Gems/Default/TrackActionAbstract.php
===================================================================
--- trunk/library/classes/Gems/Default/TrackActionAbstract.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/Gems/Default/TrackActionAbstract.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -74,10 +74,13 @@
$model = $this->createTrackModel(false, 'index');
$request = $this->getRequest();
+ $organisation_id = $this->escort->getCurrentOrganization();
+ $searchText = $this->_getParam($model->getTextFilter());
+
$model->applyPostRequest($request);
// $model->trackUsage(); DO NOT USE AS all is label here.
- if ($searchText = $this->_getParam($model->getTextFilter())) {
+ if ($searchText) {
$marker = new MUtil_Html_Marker($model->getTextSearches($searchText), 'strong', 'UTF-8');
foreach ($model->getItemNames() as $name) {
if ($model->get($name, 'label')) {
@@ -86,15 +89,13 @@
}
}
- $organisation_id = $this->escort->getCurrentOrganization();
- $filterText = $this->_getParam(MUtil_Model::TEXT_FILTER);
- $filter = $model->getTextSearchFilter($filterText);
+ $filter = $model->getTextSearchFilter($searchText);
$filter['gtr_track_type'] = $this->trackType;
$filter['gtr_active'] = 1;
$filter[] = '(gtr_date_until IS NULL OR gtr_date_until >= CURRENT_DATE) AND gtr_date_start <= CURRENT_DATE';
$filter[] = "gtr_organisations LIKE '%|$organisation_id|%'";
- $baseurl = array('action' => 'index', 'gr2o_patient_nr' => $id, MUtil_Model::TEXT_FILTER => $filterText);
+ $baseurl = array('action' => 'index', 'gr2o_patient_nr' => $id, MUtil_Model::TEXT_FILTER => $searchText);
$bridge = new MUtil_Model_TableBridge($model, array('class' => 'browser'));
$bridge->setBaseUrl($baseurl);
Modified: trunk/library/classes/Gems/Menu/SubMenuItem.php
===================================================================
--- trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/Gems/Menu/SubMenuItem.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -444,6 +444,16 @@
return $this->addActionButton($this->_('Excel export'), $this->get('privilege') . '.excel', 'excel', $options);
}
+ /**
+ * Add parameter values that should not show in the url but that
+ * must be added to the request when this menu item is current.
+ *
+ * @see applyHiddenParameters
+ *
+ * @param string $name Name of parameter
+ * @param mixed $value
+ * @return Gems_Menu_SubMenuItem (continuation pattern
+ */
public function addHiddenParameter($name, $value = null)
{
if (null === $value) {
@@ -531,11 +541,11 @@
return $menu;
}
- public function applyHiddenParameters(Zend_Controller_Request_Abstract $request)
+ public function applyHiddenParameters(Gems_Menu_ParameterSource $source)
{
if ($this->_hiddenParameters) {
foreach ($this->_hiddenParameters as $key => $name) {
- $request->setParam($key, $name);
+ $source[$key] = $name;
}
}
Modified: trunk/library/classes/Gems/Menu.php
===================================================================
--- trunk/library/classes/Gems/Menu.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/Gems/Menu.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -340,12 +340,22 @@
if ($this->escort instanceof Gems_Project_Tracks_SingleTrackInterface) {
+ $trType = 'T';
$subPage = $page->addPage($this->_('Track'), 'pr.track', 'track', 'show-track')
->addNamedParameters(MUtil_Model::REQUEST_ID, 'gr2o_patient_nr')
->addHiddenParameter(Gems_Model::TRACK_ID, $this->escort->getTrackId(), 'gtr_track_type', 'T');
- $tkPages['T'] = $subPage->addAction($this->_('Token'), 'pr.token', 'show')
- ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gto_id_token');
+ $tkPages[$trType] = $subPage->addAction($this->_('Token'), 'pr.token', 'show')
+ ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gto_id_token')
+ ->setParameterFilter('gtr_track_type', $trType, Gems_Model::ID_TYPE, 'token');
+ $subPage->addAction($this->_('Add'), 'pr.track.create', 'create')
+ ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gr2o_patient_nr', Gems_Model::TRACK_ID, 'gtr_id_track')
+ ->setParameterFilter('gtr_track_type', $trType, 'track_can_be_created', 1)
+ ->addHiddenParameter('track_can_be_created', 1);
+ $subPage->addAction($this->_('Preview'), 'pr.track', 'view')
+ ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gr2o_patient_nr', Gems_Model::TRACK_ID, 'gtr_id_track')
+ ->setParameterFilter('gtr_track_type', $trType, 'track_can_be_created', 1)
+ ->addHiddenParameter('track_can_be_created', 1);
} else {
@@ -669,9 +679,12 @@
if ($this->_menuParameters) {
// array_unshift($parameterSources, $this->_menuParameters);
+ // MUtil_echo::track($this->_menuParameters);
$parameterSources[] = $this->_menuParameters;
}
+ // self::$verbose = true;
+
$nav = new Zend_Navigation($this->_toNavigationArray($parameterSources));
// MUtil_Echo::r($this->_toNavigationArray($parameterSources));
Modified: trunk/library/classes/GemsEscort.php
===================================================================
--- trunk/library/classes/GemsEscort.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/GemsEscort.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -1570,7 +1570,7 @@
}
if (isset($menuItem)) {
- $menuItem->applyHiddenParameters($request);
+ $menuItem->applyHiddenParameters($this->menu->getParameterSource());
$this->menu->setCurrent($menuItem);
}
}
Modified: trunk/library/classes/MUtil/Model/ModelAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/MUtil/Model/ModelAbstract.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -198,6 +198,12 @@
return $this;
}
+ /**
+ * Add's one or more sort fields to the standard sort.
+ *
+ * @param mixed $value Array of sortfield => SORT_ASC|SORT_DESC or single sortfield for ascending sort.
+ * @return MUtil_Model_ModelAbstract (continuation pattern)
+ */
public function addSort($value)
{
$value = $this->_checkSortValue($value);
Added: trunk/library/classes/MUtil/Snippets/EmptySnippetAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/EmptySnippetAbstract.php (rev 0)
+++ trunk/library/classes/MUtil/Snippets/EmptySnippetAbstract.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -0,0 +1,108 @@
+<?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.
+ *
+ * Minimal implementation of Snippet interface.
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Minimal implementation of Snippet interface.
+ *
+ * Use this class for a quick implementation when SnippetAbstract feels to heavvy
+ *
+ * @see MUtil_Snippets_SnippetAbstract
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.2
+ */
+abstract class MUtil_Snippets_EmptySnippetAbstract extends MUtil_Registry_TargetAbstract implements MUtil_Snippets_SnippetInterface
+{
+ /**
+ * When hasHtmlOutput() is false a snippet code user should check
+ * for a redirectRoute. Otherwise the redirect calling render() will
+ * execute the redirect.
+ *
+ * This function should never return a value when the snippet does
+ * not redirect.
+ *
+ * Also when hasHtmlOutput() is true this function should not be
+ * called.
+ *
+ * @see Zend_Controller_Action_Helper_Redirector
+ *
+ * @return mixed Nothing or either an array or a string that is acceptable for Redector->gotoRoute()
+ */
+ public function getRedirectRoute()
+ { }
+
+ /**
+ * The place to check if the data set in the snippet is valid
+ * to generate the snippet.
+ *
+ * When invalid data should result in an error, you can throw it
+ * here but you can also perform the check in the
+ * checkRegistryRequestsAnswers() function from the
+ * {@see MUtil_Registry_TargetInterface}.
+ *
+ * @return boolean
+ */
+ public function hasHtmlOutput()
+ {
+ return false;
+ }
+
+ /**
+ * When there is a redirectRoute this function will execute it.
+ *
+ * When hasHtmlOutput() is true this functions should not be called.
+ *
+ * @see Zend_Controller_Action_Helper_Redirector
+ */
+ public function redirectRoute()
+ { }
+
+ /**
+ * Renders the element into a html string
+ *
+ * The $view is used to correctly encode and escape the output
+ *
+ * @param Zend_View_Abstract $view
+ * @return string Correctly encoded and escaped html output
+ */
+ public function render(Zend_View_Abstract $view)
+ { }
+}
Modified: trunk/library/classes/MUtil/Snippets/SnippetInterface.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/SnippetInterface.php 2011-09-13 14:38:14 UTC (rev 11)
+++ trunk/library/classes/MUtil/Snippets/SnippetInterface.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -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
@@ -25,7 +25,7 @@
* 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 Snippets
* @author Matijs de Jong <mj...@ma...>
@@ -35,18 +35,18 @@
*/
/**
- * A snippet is a piece of html output that can be reused on multiple places in the code
+ * A snippet is a piece of html output that can be reused on multiple places in the code
* or that isolates the processing needed for that output.
*
- * Variables are intialized using the MUtil_Registry_TargetInterface mechanism.
+ * Variables are intialized using the MUtil_Registry_TargetInterface mechanism.
* The snippet is then rendered using MUtil_Html_HtmlInterface.
- *
- * The only "program flow" that can be initiated by a snippet is that it can reroute
+ *
+ * The only "program flow" that can be initiated by a snippet is that it can reroute
* the browser to another page.
*
* @see MUtil_Registry_TargetInterface
* @see MUtil_Html_HtmlInterface
- *
+ *
* @package MUtil
* @subpackage Snippets
* @copyright Copyright (c) 2011 Erasmus MC
@@ -57,39 +57,39 @@
{
/**
* When hasHtmlOutput() is false a snippet code user should check
- * for a redirectRoute. Otherwise the redirect calling render() will
+ * for a redirectRoute. Otherwise the redirect calling render() will
* execute the redirect.
- *
+ *
* This function should never return a value when the snippet does
* not redirect.
- *
- * Also when hasHtmlOutput() is true this function should not be
+ *
+ * Also when hasHtmlOutput() is true this function should not be
* called.
- *
+ *
* @see Zend_Controller_Action_Helper_Redirector
- *
+ *
* @return mixed Nothing or either an array or a string that is acceptable for Redector->gotoRoute()
*/
public function getRedirectRoute();
-
+
/**
* The place to check if the data set in the snippet is valid
* to generate the snippet.
*
- * When invalid data should result in an error, you can throw it
- * here but you can also perform the check in the
+ * When invalid data should result in an error, you can throw it
+ * here but you can also perform the check in the
* checkRegistryRequestsAnswers() function from the
* {@see MUtil_Registry_TargetInterface}.
*
* @return boolean
*/
public function hasHtmlOutput();
-
+
/**
* When there is a redirectRoute this function will execute it.
- *
+ *
* When hasHtmlOutput() is true this functions should not be called.
- *
+ *
* @see Zend_Controller_Action_Helper_Redirector
*/
public function redirectRoute();
Property changes on: trunk/library/snippets/Track
___________________________________________________________________
Added: bugtraq:number
+ true
Added: trunk/library/snippets/Track/AvailableTracksSnippets.php
===================================================================
--- trunk/library/snippets/Track/AvailableTracksSnippets.php (rev 0)
+++ trunk/library/snippets/Track/AvailableTracksSnippets.php 2011-09-13 17:44:45 UTC (rev 12)
@@ -0,0 +1,137 @@
+<?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.
+ *
+ * Short description of file
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Short description for class
+ *
+ * Long description for class (if any)...
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4
+ */
+class Track_AvailableTracksSnippets extends Gems_Snippets_ModelTableSnippetAbstract
+{
+ /**
+ *
+ * @var MUtil_Model_ModelAbstract
+ */
+ protected $model;
+
+ /**
+ *
+ * @var string 'S' or 'T'
+ */
+ protected $trackType;
+
+ /**
+ * 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
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ {
+ $controller = $this->request->getControllerName();
+
+ $menuList = $this->menu->getMenuList();
+
+ $menuList->addByController($controller, 'create')
+ ->addByController($controller, 'view')
+ ->addParameterSources($bridge, $this->request)
+ ->setLowerCase(); //->showDisabled();
+
+ // Add create button
+ if ($menuItem = $menuList->getActionLink($controller, 'create')) {
+ $bridge->addItemLink($menuItem);
+ }
+
+ foreach($model->getItemsOrdered() as $name) {
+ if ($label = $model->get($name, 'label')) {
+ $bridge->addSortable($name, $label);
+ }
+ }
+
+ // Add view button
+ if ($menuItem = $menuList->getActionLink($controller, 'view')) {
+ $bridge->addItemLink($menuItem);
+ }
+
+ }
+
+ /**
+ * Creates the model
+ *
+ * @return MUtil_Model_ModelAbstract
+ */
+ public function createModel()
+ {
+ $this->model->addColumn(new Zend_Db_Expr(1), 'track_can_be_created');
+
+
+ return $this->model;
+ }
+
+ /**
+ * Overrule to implement snippet specific filtering and sorting.
+ *
+ * @param MUtil_Model_ModelAbstract $model
+ */
+ protected function processFilterAndSort(MUtil_Model_ModelAbstract $model)
+ {
+ $filter = array();
+
+ if ($this->trackType) {
+ $filter['gtr_track_type'] = $this->trackType;
+ }
+
+ $sort = array('gtr_track_name' => SORT_ASC);
+
+ // MUtil_Echo::track($filter);
+
+ $model->addFilter($filter);
+ $model->addSort($sort);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|