|
From: <gem...@li...> - 2012-10-08 09:35:08
|
Revision: 972
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=972&view=rev
Author: mennodekker
Date: 2012-10-08 09:35:02 +0000 (Mon, 08 Oct 2012)
Log Message:
-----------
Fixed #572: Show selected tokens in mailjob overview
Modified Paths:
--------------
trunk/library/classes/Gems/Default/CronAction.php
trunk/library/classes/Gems/Default/MailJobAction.php
trunk/library/classes/Gems/Default/TokenPlanAction.php
trunk/library/classes/Gems/Util/DbLookup.php
Added Paths:
-----------
trunk/library/classes/Gems/Snippets/TokenPlanTableSnippet.php
Modified: trunk/library/classes/Gems/Default/CronAction.php
===================================================================
--- trunk/library/classes/Gems/Default/CronAction.php 2012-10-02 14:38:55 UTC (rev 971)
+++ trunk/library/classes/Gems/Default/CronAction.php 2012-10-08 09:35:02 UTC (rev 972)
@@ -44,7 +44,7 @@
* @license New BSD License
* @since Class available since version 1.4
*/
-class Gems_Default_CronAction extends MUtil_Controller_Action
+class Gems_Default_CronAction extends Gems_Controller_Action
{
/**
*
@@ -53,22 +53,7 @@
public $db;
/**
- * Standard filter that must be true for every token query.
*
- * @var array
- */
- protected $defaultFilter = array(
- 'can_email' => 1,
- 'gtr_active' => 1,
- 'gsu_active' => 1,
- 'grc_success' => 1,
- 'gto_completion_time' => NULL,
- 'gto_valid_from <= CURRENT_DATE',
- '(gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP)'
- );
-
- /**
- *
* @var GemsEscort
*/
public $escort;
@@ -179,23 +164,7 @@
$user->setAsCurrentUser();
}
- // Set up filter
- $filter = $this->defaultFilter;
- if ($job['gmj_filter_mode'] == 'R') {
- $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)';
- $filter[] = 'gto_mail_sent_num < ' . $job['gmj_filter_max_reminders'];
- } else {
- $filter['gto_mail_sent_date'] = NULL;
- }
- if ($job['gmj_id_organization']) {
- $filter['gto_id_organization'] = $job['gmj_id_organization'];
- }
- if ($job['gmj_id_track']) {
- $filter['gto_id_track'] = $job['gmj_id_track'];
- }
- if ($job['gmj_id_survey']) {
- $filter['gto_id_survey'] = $job['gmj_id_survey'];
- }
+ $filter = $this->loader->getUtil()->getDbLookup()->getFilterForMailJob($job);
$tokensData = $model->load($filter);
Modified: trunk/library/classes/Gems/Default/MailJobAction.php
===================================================================
--- trunk/library/classes/Gems/Default/MailJobAction.php 2012-10-02 14:38:55 UTC (rev 971)
+++ trunk/library/classes/Gems/Default/MailJobAction.php 2012-10-08 09:35:02 UTC (rev 972)
@@ -175,4 +175,22 @@
$this->html->pInfo($this->_('With automatic mail jobs and a cron job on the server, mails can be sent without manual user action.'));
}
+
+ public function showAction()
+ {
+ parent::showAction();
+
+ $id = $this->getRequest()->getParam('id');
+ if (!is_null($id)) {
+ $id = (int) $id;
+ $job = $this->db->fetchRow("SELECT * FROM gems__mail_jobs WHERE gmj_active = 1 and gmj_id_job = ?", $id);
+ if ($job) {
+ $model = $this->loader->getTracker()->getTokenModel();
+ $filter = $this->loader->getUtil()->getDbLookup()->getFilterForMailJob($job);
+ $params['model'] = $model;
+ $params['filter'] = $filter;
+ $this->addSnippet('TokenPlanTableSnippet', $params);
+ }
+ }
+ }
}
Modified: trunk/library/classes/Gems/Default/TokenPlanAction.php
===================================================================
--- trunk/library/classes/Gems/Default/TokenPlanAction.php 2012-10-02 14:38:55 UTC (rev 971)
+++ trunk/library/classes/Gems/Default/TokenPlanAction.php 2012-10-08 09:35:02 UTC (rev 972)
@@ -110,7 +110,7 @@
public function createModel($detailed, $action)
{
// MUtil_Model::$verbose = true;
- $model = $this->loader->getTracker()->getTokenModel();;
+ $model = $this->loader->getTracker()->getTokenModel();
$model->setCreate(false);
$model->set('gr2o_patient_nr', 'label', $this->_('Respondent'));
Added: trunk/library/classes/Gems/Snippets/TokenPlanTableSnippet.php
===================================================================
--- trunk/library/classes/Gems/Snippets/TokenPlanTableSnippet.php (rev 0)
+++ trunk/library/classes/Gems/Snippets/TokenPlanTableSnippet.php 2012-10-08 09:35:02 UTC (rev 972)
@@ -0,0 +1,143 @@
+<?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
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 215 2011-07-12 08:52:54Z michiel $
+ */
+
+/**
+ * Displays a table for TokenModel
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.5.6
+ */
+class Gems_Snippets_TokenPlanTableSnippet extends Gems_Snippets_ModelTableSnippetGeneric
+{
+ public $filter = array();
+
+ /**
+ * @var GemsEscort
+ */
+ public $escort;
+
+ public function addBrowseTableColumns(\MUtil_Model_TableBridge $bridge, \MUtil_Model_ModelAbstract $model)
+ {
+ $model->set('gr2o_patient_nr', 'label', $this->_('Respondent'));
+ $model->set('gto_round_description', 'label', $this->_('Round / Details'));
+ $model->set('gto_valid_from', 'label', $this->_('Valid from'));
+ $model->set('gto_valid_until', 'label', $this->_('Valid until'));
+ $model->set('gto_mail_sent_date', 'label', $this->_('Contact date'));
+ $model->set('respondent_name', 'label', $this->_('Name'));
+
+ $HTML = MUtil_Html::create();
+
+ // Row with dates and patient data
+ $bridge->gtr_track_type; // Data needed for buttons
+
+ $bridge->setDefaultRowClass(MUtil_Html_TableElement::createAlternateRowClass('even', 'even', 'odd', 'odd'));
+ $bridge->addColumn($this->getTokenLinks($bridge), ' ')->rowspan = 2; // Space needed because TableElement does not look at rowspans
+ $bridge->addSortable('gto_valid_from');
+ $bridge->addSortable('gto_valid_until');
+
+ $bridge->addMultiSort('gr2o_patient_nr', $HTML->raw('; '), 'respondent_name');
+ $bridge->addMultiSort('ggp_name', array($this->getActionLinks($bridge)));
+
+ $bridge->tr();
+ $bridge->addSortable('gto_mail_sent_date');
+ $bridge->addSortable('gto_completion_time');
+
+ if ($this->escort instanceof Gems_Project_Tracks_SingleTrackInterface) {
+ $bridge->addMultiSort('calc_round_description', $HTML->raw('; '), 'gsu_survey_name');
+ } else {
+ $model->set('calc_track_info', 'tableDisplay', 'smallData');
+ $model->set('calc_round_description', 'tableDisplay', 'smallData');
+ $bridge->addMultiSort(
+ 'calc_track_name', 'calc_track_info',
+ $bridge->calc_track_name->if($HTML->raw(' » ')),
+ 'gsu_survey_name', 'calc_round_description');
+ }
+
+ $bridge->addSortable('assigned_by');
+ }
+
+ public function getActionLinks(MUtil_Model_TableBridge $bridge)
+ {
+ // Get the other token buttons
+ if ($menuItems = $this->menu->findAll(array('controller' => array('track', 'survey'), 'action' => array('email', 'answer'), 'allowed' => true))) {
+ $buttons = $menuItems->toActionLink($this->request, $bridge);
+ $buttons->appendAttrib('class', 'rightFloat');
+ } else {
+ $buttons = null;
+ }
+ // Add the ask button
+ if ($menuItem = $this->menu->find(array('controller' => 'ask', 'action' => 'take', 'allowed' => true))) {
+ $askLink = $menuItem->toActionLink($this->request, $bridge);
+ $askLink->appendAttrib('class', 'rightFloat');
+
+ if ($buttons) {
+ // Show previous link if show, otherwise show ask link
+ $buttons = array($buttons, $askLink);
+ } else {
+ $buttons = $askLink;
+ }
+ }
+
+ return $buttons;
+ }
+
+ public function getTokenLinks(MUtil_Model_TableBridge $bridge)
+ {
+ // Get the token buttons
+ if ($menuItems = $this->menu->findAll(array('controller' => array('track', 'survey'), 'action' => 'show', 'allowed' => true))) {
+ $buttons = $menuItems->toActionLink($this->request, $bridge, $this->_('+'));
+ $buttons->title = $bridge->gto_id_token->strtoupper();
+
+ return $buttons;
+ }
+ }
+
+ public function processFilterAndSort(MUtil_Model_ModelAbstract $model)
+ {
+ if (!empty($this->filter)) {
+ $model->setFilter($this->filter);
+ }
+
+ parent::processFilterAndSort($model);
+
+ if (!empty($this->filter)) {
+ $filter = $model->getFilter();
+ unset($filter['gto_id_token']);
+ $model->setFilter($filter);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/library/classes/Gems/Util/DbLookup.php
===================================================================
--- trunk/library/classes/Gems/Util/DbLookup.php 2012-10-02 14:38:55 UTC (rev 971)
+++ trunk/library/classes/Gems/Util/DbLookup.php 2012-10-08 09:35:02 UTC (rev 972)
@@ -185,6 +185,44 @@
}
}
+ /**
+ * Get the filter to use on the tokenmodel when working with a mailjob.
+ *
+ * @param array $job
+ * @return array
+ */
+ public function getFilterForMailJob($job)
+ {
+ // Set up filter
+ $filter = array(
+ 'can_email' => 1,
+ 'gtr_active' => 1,
+ 'gsu_active' => 1,
+ 'grc_success' => 1,
+ 'gto_completion_time' => NULL,
+ 'gto_valid_from <= CURRENT_DATE',
+ '(gto_valid_until IS NULL OR gto_valid_until >= CURRENT_TIMESTAMP)'
+ );
+
+ if ($job['gmj_filter_mode'] == 'R') {
+ $filter[] = 'gto_mail_sent_date <= DATE_SUB(CURRENT_DATE, INTERVAL ' . $job['gmj_filter_days_between'] . ' DAY)';
+ $filter[] = 'gto_mail_sent_num < ' . $job['gmj_filter_max_reminders'];
+ } else {
+ $filter['gto_mail_sent_date'] = NULL;
+ }
+ if ($job['gmj_id_organization']) {
+ $filter['gto_id_organization'] = $job['gmj_id_organization'];
+ }
+ if ($job['gmj_id_track']) {
+ $filter['gto_id_track'] = $job['gmj_id_track'];
+ }
+ if ($job['gmj_id_survey']) {
+ $filter['gto_id_survey'] = $job['gmj_id_survey'];
+ }
+
+ return $filter;
+ }
+
public function getGroups()
{
static $groups;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|