|
From: <gem...@li...> - 2013-01-21 13:54:02
|
Revision: 1114
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1114&view=rev
Author: matijsdejong
Date: 2013-01-21 13:53:54 +0000 (Mon, 21 Jan 2013)
Log Message:
-----------
Extended ComplianceAction.php with link for each (existing) token
CrossTabTransformer.php can now crosstab over multiple values
Added Legenda to Compliance overview
Moved status code to new Util/TokenData.php
Modified Paths:
--------------
trunk/library/classes/Gems/Default/ComplianceAction.php
trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php
trunk/library/classes/Gems/Util.php
trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php
trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php
Added Paths:
-----------
trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php
trunk/library/classes/Gems/Util/TokenData.php
Modified: trunk/library/classes/Gems/Default/ComplianceAction.php
===================================================================
--- trunk/library/classes/Gems/Default/ComplianceAction.php 2013-01-18 17:28:15 UTC (rev 1113)
+++ trunk/library/classes/Gems/Default/ComplianceAction.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -61,6 +61,13 @@
protected $indexStartSnippets = array('Generic_ContentTitleSnippet', 'Tracker_Compliance_ComplianceSearchFormSnippet');
/**
+ * The snippets used for the index action, after those in autofilter
+ *
+ * @var mixed String or array of snippets name
+ */
+ protected $indexStopSnippets = array('Tracker_TokenStatusLegenda', 'Generic_CurrentButtonRowSnippet');
+
+ /**
* 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
@@ -117,6 +124,7 @@
$status = new Zend_Db_Expr("
CASE
+ WHEN grc_success = 0 THEN 'D'
WHEN gto_completion_time IS NOT NULL THEN 'A'
WHEN gto_valid_from IS NULL THEN 'U'
WHEN gto_valid_from > CURRENT_TIMESTAMP THEN 'W'
@@ -126,10 +134,13 @@
");
$select = $this->db->select();
- $select->from('gems__tokens', array('gto_id_respondent_track', 'gto_id_round', 'status' => $status))
+ $select->from('gems__tokens', array(
+ 'gto_id_respondent_track', 'gto_id_round', 'gto_id_token', 'status' => $status,
+ ))
->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array())
- ->where('grc_success = 1')
+ // ->where('grc_success = 1')
->where('gto_id_track = ?', $filter['gr2t_id_track'])
+ ->order('grc_success')
->order('gto_id_respondent_track')
->order('gto_round_order');
@@ -138,15 +149,17 @@
$newModel->setKeys(array('gto_id_respondent_track'));
$transformer = new MUtil_Model_Transform_CrossTabTransformer();
- $transformer->setCrosstabFields('gto_id_round', 'status');
+ $transformer->addCrosstabField('gto_id_round', 'status', 'stat_')
+ ->addCrosstabField('gto_id_round', 'gto_id_token', 'tok_');
foreach ($data as $row) {
- $name = 'col_' . $row['gro_id_round'];
+ $name = 'stat_' . $row['gro_id_round'];
$transformer->set($name, 'label', MUtil_Lazy::call('substr', $row['gsu_survey_name'], 0, 2),
'description', sprintf("%s\n[%s]", $row['gsu_survey_name'], $row['gro_round_description']),
'noSort', true,
'round', $row['gro_round_description']
);
+ $transformer->set('tok_' . $row['gro_id_round']);
}
$newModel->addTransformer($transformer);
Modified: trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php
===================================================================
--- trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php 2013-01-18 17:28:15 UTC (rev 1113)
+++ trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -47,6 +47,12 @@
class Gems_Snippets_Tracker_Compliance_ComplianceTableSnippet extends Gems_Snippets_ModelTableSnippetGeneric
{
/**
+ *
+ * @var Gems_Util
+ */
+ protected $util;
+
+ /**
* 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
@@ -58,6 +64,7 @@
*/
protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model)
{
+ $tUtil = $this->util->getTokenData();
$table = $bridge->getTable();
$table->appendAttrib('class', 'compliance');
@@ -89,14 +96,30 @@
}
if ($model->get($name, 'noSort')) {
- $tds = $bridge->addColumn(
+ // http://localhost/pulse/track/show/id/afw8-o725
+ $title = array(
+ MUtil_Lazy::method($tUtil, 'getStatusDescription', $bridge->$name),
+ "\n" . $model->get($name, 'description')
+ );
+ $token = 'tok_' . substr($name, 5);
+
+ $tds = $bridge->addColumn(
array(
- $bridge->$name,
- 'class' => array('round', MUtil_Lazy::method($this, 'getClassFor', $bridge->$name)),
- 'title' => array(
- MUtil_Lazy::method($this, 'getDescriptionFor', $bridge->$name),
- "\n" . $model->get($name, 'description')
- ),
+ MUtil_Html_AElement::iflink(
+ $bridge->$token,
+ array(
+ 'href' => array(
+ 'controller' => 'track',
+ 'action' => 'show',
+ MUtil_Model::REQUEST_ID => $bridge->$token,
+ ),
+ 'onclick' => 'event.cancelBubble = true;',
+ 'title' => $title,
+ $bridge->$name,
+ ),
+ $bridge->$name),
+ 'class' => array('round', MUtil_Lazy::method($tUtil, 'getStatusClass', $bridge->$name)),
+ 'title' => $title,
),
array($label, 'title' => $model->get($name, 'description'), 'class' => 'round')
);
@@ -113,54 +136,6 @@
}
/**
- * Returns the class to display the answer
- *
- * @param string $value Character
- * @return string
- */
- public function getClassFor($value)
- {
- switch ($value) {
- case 'A':
- return 'answered';
- case 'M':
- return 'missed';
- case 'O':
- return 'open';
- case 'U':
- return 'unknown';
- case 'W':
- return 'waiting';
- default:
- return 'empty';
- }
- }
-
- /**
- * Returns the decription to add to the answer
- *
- * @param string $value Character
- * @return string
- */
- public function getDescriptionFor($value)
- {
- switch ($value) {
- case 'A':
- return $this->_('Answered');
- case 'M':
- return $this->_('Missed deadline');
- case 'O':
- return $this->_('Open - can be answered now');
- case 'U':
- return $this->_('Valid from date unknown');
- case 'W':
- return $this->_('Valid from date in the future');
- default:
- return $this->_('Token does not exist');
- }
- }
-
- /**
* Returns a show menu item, if access is allowed by privileges
*
* @return Gems_Menu_SubMenuItem
Added: trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php
===================================================================
--- trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php (rev 0)
+++ trunk/library/classes/Gems/Snippets/Tracker/TokenStatusLegenda.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * Copyright (c) 2012, 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 Tracker
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @version $id: TokenStatusLegenda.php 203 2012-01-01t 12:51:32Z matijs $
+ */
+
+/**
+ *
+ *
+ * @package Gems
+ * @subpackage Tracker
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5
+ */
+class Gems_Snippets_Tracker_TokenStatusLegenda extends MUtil_Snippets_SnippetAbstract
+{
+ /**
+ *
+ * @var Gems_Util
+ */
+ protected $util;
+
+ /**
+ * Create the snippets content
+ *
+ * This is a stub function either override getHtmlOutput() or override render()
+ *
+ * @param Zend_View_Abstract $view Just in case it is needed here
+ * @return MUtil_Html_HtmlInterface Something that can be rendered
+ */
+ public function getHtmlOutput(Zend_View_Abstract $view)
+ {
+ $tUtil = $this->util->getTokenData();
+
+ $repeater = new MUtil_Lazy_RepeatableByKeyValue($tUtil->getEveryStatus());
+ $table = new MUtil_Html_TableElement();
+ $table->class = 'compliance timeTable rightFloat';
+ $table->setRepeater($repeater);
+
+ $table->throw($this->_('Legend'));
+ $table->td($repeater->key)->class = array(
+ 'round',
+ MUtil_Lazy::method($tUtil, 'getStatusClass', $repeater->key)
+ );
+ $table->td($repeater->value);
+
+ return $table;
+ }
+}
Added: trunk/library/classes/Gems/Util/TokenData.php
===================================================================
--- trunk/library/classes/Gems/Util/TokenData.php (rev 0)
+++ trunk/library/classes/Gems/Util/TokenData.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -0,0 +1,115 @@
+<?php
+
+/**
+ * Copyright (c) 2012, 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 Util
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @version $id: TokenData.php 203 2012-01-01t 12:51:32Z matijs $
+ */
+
+/**
+ * Class that bundles information on tokens
+ *
+ * @package Gems
+ * @subpackage Util
+ * @copyright Copyright (c) 2012 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.6
+ */
+class Gems_Util_TokenData extends MUtil_Translate_TranslateableAbstract
+{
+ /**
+ * Returns a status code => decription array
+ *
+ * @static $status array
+ * @return array
+ */
+ public function getEveryStatus()
+ {
+ static $status;
+
+ if ($status) {
+ return $status;
+ }
+
+ $status = array(
+ 'U' => $this->_('Valid from date unknown'),
+ 'W' => $this->_('Valid from date in the future'),
+ 'O' => $this->_('Open - can be answered now'),
+ 'A' => $this->_('Answered'),
+ 'M' => $this->_('Missed deadline'),
+ 'D' => $this->_('Token does not exist'),
+ );
+
+ return $status;
+ }
+
+ /**
+ * Returns the class to display the answer
+ *
+ * @param string $value Character
+ * @return string
+ */
+ public function getStatusClass($value)
+ {
+ switch ($value) {
+ case 'A':
+ return 'answered';
+ case 'M':
+ return 'missed';
+ case 'O':
+ return 'open';
+ case 'U':
+ return 'unknown';
+ case 'W':
+ return 'waiting';
+ default:
+ return 'empty';
+ }
+ }
+
+ /**
+ * Returns the decription to add to the answer
+ *
+ * @param string $value Character
+ * @return string
+ */
+ public function getStatusDescription($value)
+ {
+ $status = $this->getEveryStatus();
+
+ if (isset($status[$value])) {
+ return $status[$value];
+ }
+
+ return $status['D'];
+ }
+}
Modified: trunk/library/classes/Gems/Util.php
===================================================================
--- trunk/library/classes/Gems/Util.php 2013-01-18 17:28:15 UTC (rev 1113)
+++ trunk/library/classes/Gems/Util.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -91,6 +91,12 @@
/**
*
+ * @var Gems_Util_TokenData
+ */
+ protected $tokenData;
+
+ /**
+ *
* @var Gems_Util_TrackData
*/
protected $trackData;
@@ -275,6 +281,15 @@
/**
*
+ * @return Gems_Util_TokenData
+ */
+ public function getTokenData()
+ {
+ return $this->_getClass('tokenData');
+ }
+
+ /**
+ *
* @return Gems_Util_TrackData
*/
public function getTrackData()
Modified: trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php 2013-01-18 17:28:15 UTC (rev 1113)
+++ trunk/library/classes/MUtil/Model/ModelTransformerAbstract.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -126,24 +126,28 @@
$args = func_get_args();
$args = MUtil_Ra::pairs($args, 1);
- foreach ($args as $key => $value) {
- // If $key end with ] it is array value
- if (substr($key, -1) == ']') {
- if (substr($key, -2) == '[]') {
- // If $key ends with [], append it to array
- $key = substr($key, 0, -2);
- $this->_fields[$name][$key][] = $value;
+ if ($args) {
+ foreach ($args as $key => $value) {
+ // If $key end with ] it is array value
+ if (substr($key, -1) == ']') {
+ if (substr($key, -2) == '[]') {
+ // If $key ends with [], append it to array
+ $key = substr($key, 0, -2);
+ $this->_fields[$name][$key][] = $value;
+ } else {
+ // Otherwise extract subkey
+ $pos = strpos($key, '[');
+ $subkey = substr($key, $pos + 1, -1);
+ $key = substr($key, 0, $pos);
+
+ $this->_fields[$name][$key][$subkey] = $value;
+ }
} else {
- // Otherwise extract subkey
- $pos = strpos($key, '[');
- $subkey = substr($key, $pos + 1, -1);
- $key = substr($key, 0, $pos);
-
- $this->_fields[$name][$key][$subkey] = $value;
+ $this->_fields[$name][$key] = $value;
}
- } else {
- $this->_fields[$name][$key] = $value;
}
+ } elseif (!array_key_exists($name, $this->_fields)) {
+ $this->_fields[$name] = array();
}
return $this;
Modified: trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php
===================================================================
--- trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php 2013-01-18 17:28:15 UTC (rev 1113)
+++ trunk/library/classes/MUtil/Model/Transform/CrossTabTransformer.php 2013-01-21 13:53:54 UTC (rev 1114)
@@ -47,29 +47,47 @@
class MUtil_Model_Transform_CrossTabTransformer extends MUtil_Model_ModelTransformerAbstract
{
/**
- * The field to crosstab over
+ * The fields to crosstab over
*
- * @var string
+ * @var array Nested array: index => array('id' => idField, 'val' => valueField, 'pre' => prefix)
*/
- protected $idField;
+ protected $crossTabs;
/**
+ * The fields to exclude from the crosstab result
*
- * @var string
+ * Calculated by setCrosstabFields
+ *
+ * @var array idField => idField
*/
- protected $valueField;
+ protected $excludes;
/**
+ * Set the idField / crossTab output fields for the transformer.
*
- * @param string $idField The field values to perform the crosstab over
+ * You can define multiple crossTabs over the same id value.
+ *
+ * @param string $idField The field values to perform the crosstab over
* @param string $valueField The field values to crosstab
+ * @param string $prefix Optional prefix to add before the $idField value as the identifier
+ * for the output field, otherwise
* @return MUtil_Model_Transform_CrossTabTransformer (continuation pattern)
*/
- public function setCrosstabFields($idField, $valueField)
+ public function addCrosstabField($idField, $valueField, $prefix = null)
{
- $this->idField = $idField;
- $this->valueField = $valueField;
+ if (null === $prefix) {
+ $prefix = $valueField . '_';
+ }
+ $this->crossTabs[] = array(
+ 'id' => $idField,
+ 'val' => $valueField,
+ 'pre' => $prefix,
+ );
+
+ $this->excludes[$idField] = $idField;
+ $this->excludes[$valueField] = $valueField;
+
return $this;
}
@@ -90,33 +108,33 @@
//*
$row = reset($data);
- if (! ($this->idField &&
- $this->valueField &&
- isset($row[$this->idField]) &&
- array_key_exists($this->valueField, $row)
- )) {
+ if (! ($this->crossTabs)) {
return $data;
}
$keys = $model->getKeys();
$keys = array_combine($keys, $keys);
- $default = array_fill_keys(array_keys($this->_fields), null);
- $except = array($this->idField => 1, $this->valueField => 1);
+ $default = array_fill_keys(array_keys(array_diff_key($this->_fields, $this->excludes)), null);
$results = array();
+ // MUtil_Echo::track($default);
+
foreach ($data as $row) {
- $name = 'col_' . $row[$this->idField];
+ foreach ($this->crossTabs as $crossTab) {
+ $name = $crossTab['pre'] . $row[$crossTab['id']];
- if (isset($this->_fields[$name])) {
$key = implode("\t", array_intersect_key($row, $keys));
if (! isset($results[$key])) {
- $results[$key] = array_diff_key($row, $except) + $default;
+ $results[$key] = array_diff_key($row, $this->excludes) + $default;
}
- $results[$key][$name] = $row[$this->valueField];
+
+ $results[$key][$name] = $row[$crossTab['val']];
}
}
- // MUtil_Echo::track($results, $data);
+ if (MUtil_Model::$verbose) {
+ MUtil_Echo::r($results, 'Transform output');
+ }
return $results;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|