From: <gem...@li...> - 2013-03-19 15:15:56
|
Revision: 1196 http://sourceforge.net/p/gemstracker/code/1196 Author: matijsdejong Date: 2013-03-19 15:14:49 +0000 (Tue, 19 Mar 2013) Log Message: ----------- Extended mail log details shown and search capabilities Modified Paths: -------------- trunk/library/classes/Gems/Default/ComplianceAction.php trunk/library/classes/Gems/Default/MailLogAction.php trunk/library/classes/Gems/Util/TokenData.php Added Paths: ----------- trunk/library/classes/Gems/Snippets/Mail/ trunk/library/classes/Gems/Snippets/Mail/Log/ trunk/library/classes/Gems/Snippets/Mail/Log/MailLogBrowseSnippet.php trunk/library/classes/Gems/Snippets/Mail/Log/MailLogSearchSnippet.php Removed Paths: ------------- trunk/library/snippets/Mail/ Modified: trunk/library/classes/Gems/Default/ComplianceAction.php =================================================================== --- trunk/library/classes/Gems/Default/ComplianceAction.php 2013-03-19 13:08:04 UTC (rev 1195) +++ trunk/library/classes/Gems/Default/ComplianceAction.php 2013-03-19 15:14:49 UTC (rev 1196) @@ -122,16 +122,7 @@ return $model; } - $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' - WHEN gto_valid_until < CURRENT_TIMESTAMP THEN 'M' - ELSE 'O' - END - "); + $status = $this->util->getTokenData()->getStatusExpression(); $select = $this->db->select(); $select->from('gems__tokens', array( Modified: trunk/library/classes/Gems/Default/MailLogAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailLogAction.php 2013-03-19 13:08:04 UTC (rev 1195) +++ trunk/library/classes/Gems/Default/MailLogAction.php 2013-03-19 15:14:49 UTC (rev 1196) @@ -58,7 +58,6 @@ * @var array Mixed key => value array for snippet initialization */ protected $autofilterParameters = array( - 'extraFilter' => 'getExtraFilter', 'extraSort' => array('grco_created' => SORT_DESC), ); @@ -70,6 +69,13 @@ protected $autofilterSnippets = 'Mail_Log_MailLogBrowseSnippet'; /** + * The snippets used for the index action, before those in autofilter + * + * @var mixed String or array of snippets name + */ + protected $indexStartSnippets = array('Generic_ContentTitleSnippet', 'Mail_Log_MailLogSearchSnippet'); + + /** * 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 @@ -88,6 +94,11 @@ $model->addLeftTable('gems__staff', array('grco_id_by' => 'gsf_id_user')); $model->addLeftTable('gems__mail_templates', array('grco_id_message' => 'gmt_id_message')); + $model->addLeftTable('gems__tokens', array('grco_id_token' => 'gto_id_token')); + $model->addLeftTable('gems__reception_codes', array('gto_reception_code' => 'grc_id_reception_code')); + $model->addLeftTable('gems__tracks', array('gto_id_track' => 'gtr_id_track')); + $model->addLeftTable('gems__surveys', array('gto_id_survey' => 'gsu_id_survey')); + $model->addColumn( "TRIM(CONCAT(COALESCE(CONCAT(grs_last_name, ', '), '-, '), COALESCE(CONCAT(grs_first_name, ' '), ''), COALESCE(grs_surname_prefix, '')))", 'respondent_name'); @@ -103,6 +114,7 @@ ) END", 'assigned_by'); + $model->addColumn($this->util->getTokenData()->getStatusExpression(), 'status'); $model->resetOrder(); @@ -113,6 +125,10 @@ $model->set('grco_sender', 'label', $this->_('From address'), 'itemDisplay', 'MUtil_Html_AElement::ifmail'); $model->set('grco_id_token', 'label', $this->_('Token')); $model->set('grco_topic', 'label', $this->_('Subject')); + $model->set('gtr_track_name', 'label', $this->_('Track')); + $model->set('gsu_survey_name', 'label', $this->_('Survey')); + $model->set('status', 'label', $this->_('Status'), + 'formatFunction', array($this->util->getTokenData(), 'getStatusDescription')); if ($detailed) { $model->set('gmt_subject', 'label', $this->_('Template')); @@ -120,20 +136,17 @@ $model->set('grco_created', 'formatFunction', $this->util->getTranslated()->formatDate); } + $filter = $this->util->getRequestCache('index', $detailed)->getProgramParams(); + + // Add the period filter - if any + if ($where = Gems_Snippets_AutosearchFormSnippet::getPeriodFilter($filter, $this->db)) { + $model->addFilter(array($where)); + } + return $model; } /** - * Returns an extra filter for this action - * - * @return array - */ - protected function getExtraFilter() - { - return array('grco_organization' => $this->escort->getCurrentOrganization()); - } - - /** * Helper function to get the title for the index action. * * @return $string Copied: trunk/library/classes/Gems/Snippets/Mail/Log/MailLogBrowseSnippet.php (from rev 1194, trunk/library/snippets/Mail/Log/MailLogBrowseSnippet.php) =================================================================== --- trunk/library/classes/Gems/Snippets/Mail/Log/MailLogBrowseSnippet.php (rev 0) +++ trunk/library/classes/Gems/Snippets/Mail/Log/MailLogBrowseSnippet.php 2013-03-19 15:14:49 UTC (rev 1196) @@ -0,0 +1,115 @@ +<?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 <COPYRIGHT HOLDER> 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\Mail\Log + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @version $Id$ + */ + +/** + * Add complex column layout to display. + * + * + * @package Gems + * @subpackage Snippets\Mail\Log + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.4 + */ +class Gems_Snippets_Mail_Log_MailLogBrowseSnippet 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 + * 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) + { + if ($menuItem = $this->getShowMenuItem()) { + $bridge->addItemLink($menuItem->toActionLinkLower($this->request, $bridge)); + } + + // Newline placeholder + $br = MUtil_Html::create('br'); + + // make sure search results are highlighted + $this->applyTextMarker(); + + $bridge->addMultiSort('grco_created', $br, 'respondent_name', $br, 'grco_address', $br, 'gtr_track_name'); + $bridge->addMultiSort('grco_id_token', $br, 'assigned_by', $br, 'grco_sender', $br, 'gsu_survey_name'); + $bridge->addMultiSort('status', $br, 'grco_topic'); + + $title = MUtil_Html::create()->strong($this->_('+')); + $params = array( + 'gto_id_token' => $bridge->gto_id_token, + 'gtr_track_type' => $bridge->gtr_track_type, + 'grc_success' => 1, + Gems_Model::ID_TYPE => 'token', + ); + + $showLinks[] = $this->createMenuLink($params, 'track', 'show', $title); + $showLinks[] = $this->createMenuLink($params, 'survey', 'show', $title); + + // Remove nulls + $showLinks = array_filter($showLinks); + + if ($showLinks) { + foreach ($showLinks as $showLink) { + if ($showLink) { + $showLink->title = array($this->_('Token'), $bridge->gto_id_token->strtoupper()); + } + } + } + $bridge->getTable()->appendAttrib('class', 'compliance'); + + $tbody = $bridge->tbody(); + $td = $tbody[0][0]; + /* // Does not repeat for some reason + $td->appendAttrib('class', MUtil_Lazy::method($this->util->getTokenData(), 'getStatusClass', $bridge->status)); + $td->append($br); + $td->append($br); // */ + $td->append($br); + $td->append($showLinks); + // $bridge->addItemLink($showLinks); + } +} Added: trunk/library/classes/Gems/Snippets/Mail/Log/MailLogSearchSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Mail/Log/MailLogSearchSnippet.php (rev 0) +++ trunk/library/classes/Gems/Snippets/Mail/Log/MailLogSearchSnippet.php 2013-03-19 15:14:49 UTC (rev 1196) @@ -0,0 +1,125 @@ +<?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 Pulse + * @author Matijs de Jong <mj...@ma...> + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @version $id: MailLogSearchSnippet.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * + * + * @package Gems + * @subpackage Pulse + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.6 + */ +class Gems_Snippets_Mail_Log_MailLogSearchSnippet extends Gems_Snippets_AutosearchFormSnippet +{ + /** + * + * @var Gems_Loader + */ + public $loader; + + /** + * Creates the form itself + * + * @param array $options + * @return Gems_Form + */ + protected function createForm($options = null) + { + $form = parent::createForm($options); + + $form->activateJQuery(); + + return $form; + } + + /** + * Returns a text element for autosearch. Can be overruled. + * + * The form / html elements to search on. Elements can be grouped by inserting null's between them. + * That creates a distinct group of elements + * + * @param array $data The $form field values (can be usefull, but no need to set them) + * @return array Of Zend_Form_Element's or static tekst to add to the html or null for group breaks. + */ + protected function getAutoSearchElements(array $data) + { + // Search text + $elements = parent::getAutoSearchElements($data); + + $this->_addPeriodSelectors($elements, array('grco_created' => $this->_('Date sent'))); + + $br = MUtil_Html::create()->br(); + + $elements[] = null; + + $dbLookup = $this->util->getDbLookup(); + + $elements[] = $this->_createSelectElement( + 'gto_id_track', + $this->util->getTrackData()->getSteppedTracks(), + $this->_('(select a track)') + ); + + $elements[] = $this->_createSelectElement('gto_id_survey', + $this->util->getTrackData()->getAllSurveys(), + $this->_('(all surveys)')); + + $elements[] = $this->_createSelectElement( + 'grco_organization', + $this->loader->getCurrentUser()->getRespondentOrganizations(), + $this->_('(all organizations)') + ); + + return $elements; + } + + /** + * + * @return array The data to fill the form with + */ + protected function getSearchData() + { + $data = parent::getSearchData(); + + if (!array_key_exists('grco_organization', $data)) { + $data['grco_organization'] = $this->loader->getOrganization()->getId(); + } + + return $data; + } +} Modified: trunk/library/classes/Gems/Util/TokenData.php =================================================================== --- trunk/library/classes/Gems/Util/TokenData.php 2013-03-19 13:08:04 UTC (rev 1195) +++ trunk/library/classes/Gems/Util/TokenData.php 2013-03-19 15:14:49 UTC (rev 1196) @@ -112,4 +112,23 @@ return $status['D']; } + + /** + * An expression for calculating the token status + * + * @return Zend_Db_Expr + */ + public function getStatusExpression() + { + return new Zend_Db_Expr(" + CASE + WHEN gto_id_token IS NULL OR 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' + WHEN gto_valid_until < CURRENT_TIMESTAMP THEN 'M' + ELSE 'O' + END + "); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |