From: <gem...@li...> - 2013-01-17 17:34:20
|
Revision: 1110 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=1110&view=rev Author: matijsdejong Date: 2013-01-17 17:34:11 +0000 (Thu, 17 Jan 2013) Log Message: ----------- ComplianceAction.php now looks nice and exports to excel Simple _addPeriodSelectors function, will add to TokenPlanAction and RespondentPlanAction Modified Paths: -------------- trunk/library/classes/Gems/Default/ComplianceAction.php trunk/library/classes/Gems/Default/SummaryAction.php trunk/library/classes/Gems/Snippets/AutosearchFormSnippet.php trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceSearchFormSnippet.php trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php trunk/library/classes/Gems/Snippets/Tracker/Summary/SummarySearchFormSnippet.php trunk/library/classes/Gems/Snippets/Tracker/Summary/SummaryTableSnippet.php Modified: trunk/library/classes/Gems/Default/ComplianceAction.php =================================================================== --- trunk/library/classes/Gems/Default/ComplianceAction.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Default/ComplianceAction.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -79,12 +79,88 @@ 'gr2t_id_organization' => 'gr2o_id_organization' )); $model->addTable('gems__tracks', array('gr2t_id_track' => 'gtr_id_track')); + $model->addTable('gems__reception_codes', array('gr2t_reception_code' => 'grc_id_reception_code')); + $model->addFilter(array('grc_success' => 1)); $model->resetOrder(); $model->set('gr2o_patient_nr', 'label', $this->_('Respondent nr')); $model->set('gr2t_start_date', 'label', $this->_('Start date'), 'dateFormat', 'dd-MM-yyyy'); $model->set('gr2t_end_date', 'label', $this->_('End date'), 'dateFormat', 'dd-MM-yyyy'); + $filter = $this->util->getRequestCache('index')->getProgramParams(); + MUtil_Echo::track($filter); + if (! (isset($filter['gr2t_id_track']) && $filter['gr2t_id_track'])) { + $model->setFilter(array('1=0')); + $this->autofilterParameters['onEmpty'] = $this->_('No track selected...'); + return $model; + } + + // Add the period filter - if any + if ($where = Gems_Snippets_AutosearchFormSnippet::getPeriodFilter($filter, $this->db)) { + $model->addFilter(array($where)); + } + + $select = $this->db->select(); + $select->from('gems__rounds', array('gro_id_round', 'gro_id_order', 'gro_round_description')) + ->joinInner('gems__surveys', 'gro_id_survey = gsu_id_survey', array('gsu_survey_name')) + ->where('gro_id_track = ?', $filter['gr2t_id_track']) + ->order('gro_id_order'); + + if (isset($filter['gsu_id_primary_group']) && $filter['gsu_id_primary_group']) { + $select->where('gsu_id_primary_group = ?', $filter['gsu_id_primary_group']); + } + + $data = $this->db->fetchAll($select); + + if (! $data) { + return $model; + } + + $status = new Zend_Db_Expr(" + CASE + 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 + "); + + $select = $this->db->select(); + $select->from('gems__tokens', array('gto_id_respondent_track', 'gto_id_round', 'status' => $status)) + ->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array()) + ->where('grc_success = 1') + ->where('gto_id_track = ?', $filter['gr2t_id_track']) + ->order('gto_id_respondent_track') + ->order('gto_round_order'); + + // MUtil_Echo::track($this->db->fetchAll($select)); + $newModel = new MUtil_Model_SelectModel($select, 'tok'); + $newModel->setKeys(array('gto_id_respondent_track')); + + $transformer = new MUtil_Model_Transform_CrossTabTransformer(); + $transformer->setCrosstabFields('gto_id_round', 'status'); + + foreach ($data as $row) { + $name = 'col_' . $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'] + ); + } + + $newModel->addTransformer($transformer); + // MUtil_Echo::track($data); + + $joinTrans = new MUtil_Model_Transform_JoinTransformer(); + $joinTrans->addModel($newModel, array('gr2t_id_respondent_track' => 'gto_id_respondent_track')); + + $model->resetOrder(); + $model->set('gr2o_patient_nr'); + $model->set('gr2t_start_date'); + $model->addTransformer($joinTrans); + return $model; } Modified: trunk/library/classes/Gems/Default/SummaryAction.php =================================================================== --- trunk/library/classes/Gems/Default/SummaryAction.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Default/SummaryAction.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -153,7 +153,6 @@ ->joinInner('gems__surveys', 'gro_id_survey = gsu_id_survey', array('gsu_survey_name', 'gsu_id_primary_group')) ->group(array('gro_id_order', 'gro_round_description', 'gsu_survey_name', 'gsu_id_primary_group')); - // ->order('gto_round_order'); // MUtil_Model::$verbose = true; $model = new MUtil_Model_SelectModel($select, 'summary'); @@ -181,7 +180,14 @@ $model->set('gsu_id_primary_group', 'label', $this->_('Filler'), 'multiOptions', $this->util->getDbLookup()->getGroups()); - if (!$this->getTrackId()) { + $data = $this->util->getRequestCache('index')->getProgramParams(); + if (isset($data['gto_id_track'])) { + // Add the period filter + if ($where = Gems_Snippets_AutosearchFormSnippet::getPeriodFilter($data, $this->db)) { + $select->joinInner('gems__respondent2track', 'gto_id_respondent_track = gr2t_id_respondent_track', array()); + $model->addFilter(array($where)); + } + } else { $model->setFilter(array('1=0')); $this->autofilterParameters['onEmpty'] = $this->_('No track selected...'); } @@ -209,16 +215,4 @@ { return $this->plural('token', 'tokens', $count); } - - /** - * - * @return int Return the track id if any or null - */ - public function getTrackId() - { - $data = $this->util->getRequestCache('index')->getProgramParams(); - if (isset($data['gto_id_track'])) { - return $data['gto_id_track']; - } - } } Modified: trunk/library/classes/Gems/Snippets/AutosearchFormSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/AutosearchFormSnippet.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Snippets/AutosearchFormSnippet.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -89,18 +89,71 @@ */ protected $searchButtonId = 'AUTO_SEARCH_TEXT_BUTTON'; + /** + * Generate two date selectors and - depending on the number of $dates passed - + * either a hidden element containing the field name or an radio button or + * dropdown selector for the type of date to use. + * + * @param array $elements Search element array to which the element are added. + * @param mixed $dates A string fieldName to use or an array of fieldName => Label + * @param string $defaultDate Optional element, otherwise first is used. + * @param int $switchToSelect The number of dates where this function should switch to select display + */ + protected function _addPeriodSelectors(array &$elements, $dates, $defaultDate = null, $switchToSelect = 4) + { + if (is_array($dates) && (1 === count($dates))) { + reset($dates); + $dates = key($dates); + } + if (is_string($dates)) { + $element = new Zend_Form_Element_Hidden('dateused'); + $element->setValue($dates); + $fromLabel = $this->_('From'); + } else { + if (count($dates) >= $switchToSelect) { + $element = $this->_createSelectElement('dateused', $dates); + $element->setLabel($this->_('For date')); + + $fromLabel = ''; + } else { + $element = $this->_createRadioElement('dateused', $dates); + $element->setSeparator(' '); + + $fromLabel = html_entity_decode(' » ', ENT_QUOTES, 'UTF-8'); + } + $fromLabel .= $this->_('from'); + + if ((null === $defaultDate) || (! isset($dates[$defaultDate]))) { + // Set value to first key + reset($dates); + $defaultDate = key($dates); + } + $element->setValue($defaultDate); + } + $elements[] = $element; + + $options = array(); + $options['label'] = $fromLabel; + MUtil_Model_FormBridge::applyFixedOptions('date', $options); + $elements[] = new Gems_JQuery_Form_Element_DatePicker('datefrom', $options); + + $options['label'] = ' ' . $this->_('until'); + $elements[] = new Gems_JQuery_Form_Element_DatePicker('dateuntil', $options); + } + /** * Creates a Zend_Form_Element_Select * * If $options is a string it is assumed to contain an SQL statement. * + * @param string $class Name of the class to use * @param string $name Name of the select element * @param string|array $options Can be a SQL select string or key/value array of options * @param string $empty Text to display for the empty selector - * @return Zend_Form_Element_Select + * @return Zend_Form_Element_Multi */ - protected function _createSelectElement($name, $options, $empty = null) + private function _createMultiElement($class, $name, $options, $empty) { if ($options instanceof MUtil_Model_ModelAbstract) { $options = $options->get($name, 'multiOptions'); @@ -113,13 +166,43 @@ if (null !== $empty) { $options = array('' => $empty) + $options; } - $element = new Zend_Form_Element_Select($name, array('multiOptions' => $options)); + $element = new $class($name, array('multiOptions' => $options)); return $element; } } /** + * Creates a Zend_Form_Element_Select + * + * If $options is a string it is assumed to contain an SQL statement. + * + * @param string $name Name of the select element + * @param string|array $options Can be a SQL select string or key/value array of options + * @param string $empty Text to display for the empty selector + * @return Zend_Form_Element_Radio + */ + protected function _createRadioElement($name, $options, $empty = null) + { + return $this->_createMultiElement('Zend_Form_Element_Radio', $name, $options, $empty); + } + + /** + * Creates a Zend_Form_Element_Select + * + * If $options is a string it is assumed to contain an SQL statement. + * + * @param string $name Name of the select element + * @param string|array $options Can be a SQL select string or key/value array of options + * @param string $empty Text to display for the empty selector + * @return Zend_Form_Element_Select + */ + protected function _createSelectElement($name, $options, $empty = null) + { + return $this->_createMultiElement('Zend_Form_Element_Select', $name, $options, $empty); + } + + /** * Called after the check that all required registry values * have been set correctly has run. * @@ -255,7 +338,48 @@ } /** + * Helper function to generate a period query string * + * @param array $data A filter array or $request->getParams() + * @param Zend_Db_Adapter_Abstract $db + * @return string + */ + public static function getPeriodFilter(array $data, Zend_Db_Adapter_Abstract $db) + { + if (isset($data['dateused'])) { + $options = array(); + MUtil_Model_FormBridge::applyFixedOptions('date', $options); + + $outFormat = 'yyyy-MM-dd'; + $inFormat = isset($options['dateFormat']) ? $options['dateFormat'] : null; + + if (isset($data['datefrom']) && $data['datefrom']) { + if (isset($data['dateuntil']) && $data['dateuntil']) { + return sprintf( + '%s BETWEEN %s AND %s', + $db->quoteIdentifier($data['dateused']), + $db->quote(MUtil_Date::format($data['datefrom'], $outFormat, $inFormat)), + $db->quote(MUtil_Date::format($data['dateuntil'], $outFormat, $inFormat)) + ); + } + return sprintf( + '%s >= %s', + $db->quoteIdentifier($data['dateused']), + $db->quote(MUtil_Date::format($data['datefrom'], $outFormat, $inFormat)) + ); + } + if (isset($data['dateuntil']) && $data['dateuntil']) { + return sprintf( + '%s <= %s', + $db->quoteIdentifier($data['dateused']), + $db->quote(MUtil_Date::format($data['dateuntil'], $outFormat, $inFormat)) + ); + } + } + } + + /** + * * @return array The data to fill the form with */ protected function getSearchData() Modified: trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceSearchFormSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceSearchFormSnippet.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceSearchFormSnippet.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -65,6 +65,28 @@ $this->util->getDbLookup()->getOrganizationsWithRespondents(), $this->_('(all organizations)')); + $elements[] = null; + + $dates = array( + 'gr2t_start_date' => $this->_('Track start'), + 'gr2t_end_date' => $this->_('Track end'), + ); + // $dates = 'gto_valid_from'; + $this->_addPeriodSelectors($elements, $dates, 'gto_valid_from'); + + $elements[] = null; + + $sql = "SELECT DISTINCT ggp_id_group, ggp_name + FROM gems__groups INNER JOIN gems__surveys ON ggp_id_group = gsu_id_primary_group + INNER JOIN gems__rounds ON gsu_id_survey = gro_id_survey + INNER JOIN gems__tracks ON gro_id_track = gtr_id_track + WHERE ggp_group_active = 1 AND + gro_active=1 AND + gtr_active=1 AND + gtr_track_type='T' + ORDER BY ggp_name"; + $elements[] = $this->_createSelectElement('gsu_id_primary_group', $sql, $this->_('(all fillers)')); + return $elements; } Modified: trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Snippets/Tracker/Compliance/ComplianceTableSnippet.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -47,126 +47,126 @@ class Gems_Snippets_Tracker_Compliance_ComplianceTableSnippet extends Gems_Snippets_ModelTableSnippetGeneric { /** + * Adds columns from the model to the bridge that creates the browse table. * - * @var Zend_Db_Adapter_Abstract - */ - protected $db; - - /** + * Overrule this function to add different columns to the browse table, without + * having to recode the core table building code. * - * @var Gems_Loader + * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_ModelAbstract $model + * @return void */ - protected $loader; - - /** - * Creates the model - * - * @return MUtil_Model_ModelAbstract - */ - protected function createModel() + protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { - $model = parent::createModel(); - $trackId = $this->getTrackId(); + $table = $bridge->getTable(); + $table->appendAttrib('class', 'compliance'); - if (! $trackId) { - return $model; - } + $thead = $table->thead(); + $th_row = $thead->tr(array('class' => 'rounds')); + $th = $th_row->td(); + $span = 1; + $cRound = null; + $thead->tr(); - $select = $this->db->select(); - $select->from('gems__rounds', array('gro_id_round', 'gro_id_order', 'gro_round_description')) - ->where('gro_id_track = ?', $trackId) - ->order('gro_id_order'); - - $data = $this->db->fetchAll($select); - - if (! $data) { - return $model; + if ($showMenuItem = $this->getShowMenuItem()) { + $bridge->addItemLink($showMenuItem->toActionLinkLower($this->request, $bridge)); } - $status = new Zend_Db_Expr(" - CASE - 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 - "); + foreach($model->getItemsOrdered() as $name) { + if ($label = $model->get($name, 'label')) { + $round = $model->get($name, 'round'); + if ($round == $cRound) { + $span++; + $class = null; + } else { + $th->append($cRound); + $th->colspan = $span; - $select = $this->db->select(); - $select->from('gems__tokens', array('gto_id_respondent_track', 'gto_id_round', 'status' => $status)) - ->joinInner('gems__reception_codes', 'gto_reception_code = grc_id_reception_code', array()) - ->where('grc_success = 1') - ->where('gto_id_track = ?', $trackId) - ->order('gto_id_respondent_track') - ->order('gto_round_order'); + $span = 1; + $cRound = $round; + $class = 'newRound'; + $th = $th_row->td(array('class' => $class)); + } - // MUtil_Echo::track($this->db->fetchAll($select)); - - $newModel = new MUtil_Model_SelectModel($select, 'tok'); - $newModel->setKeys(array('gto_id_respondent_track')); - - $transformer = new MUtil_Model_Transform_CrossTabTransformer(); - $transformer->setCrosstabFields('gto_id_round', 'status'); - - foreach ($data as $row) { - $name = 'col_' . $row['gro_id_round']; - $transformer->set($name, 'label', $row['gro_id_order'], 'description', $row['gro_round_description']); + if ($model->get($name, 'noSort')) { + $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') + ), + ), + array($label, 'title' => $model->get($name, 'description'), 'class' => 'round') + ); + } else { + $tds = $bridge->addSortable($name, $label); + } + if ($class) { + $tds->appendAttrib('class', $class); + } + } } - - $newModel->addTransformer($transformer); - // MUtil_Echo::track($data); - - $joinTrans = new MUtil_Model_Transform_JoinTransformer(); - $joinTrans->addModel($newModel, array('gr2t_id_respondent_track' => 'gto_id_respondent_track')); - - $model->resetOrder(); - $model->set('gr2o_patient_nr'); - $model->set('gr2t_start_date'); - $model->addTransformer($joinTrans); - return $model; + $th->append($cRound); + $th->colspan = $span; } /** - * Returns a show menu item, if access is allowed by privileges + * Returns the class to display the answer * - * @return Gems_Menu_SubMenuItem + * @param string $value Character + * @return string */ - protected function getShowMenuItem() + public function getClassFor($value) { - return $this->findMenuItem('track', 'show-track'); + 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 * - * @return int Return the track id if any or null + * @param string $value Character + * @return string */ - public function getTrackId() + public function getDescriptionFor($value) { - if ($this->requestCache) { - $data = $this->requestCache->getProgramParams(); - if (isset($data['gr2t_id_track'])) { - return $data['gr2t_id_track']; - } - } else { - return $this->request->getParam('gr2t_id_track'); + 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'); } } /** - * Overrule to implement snippet specific filtering and sorting. + * Returns a show menu item, if access is allowed by privileges * - * @param MUtil_Model_ModelAbstract $model + * @return Gems_Menu_SubMenuItem */ - protected function processFilterAndSort(MUtil_Model_ModelAbstract $model) + protected function getShowMenuItem() { - $trackId = $this->getTrackId(); - - if ($trackId) { - parent::processFilterAndSort($model); - } else { - $model->setFilter(array('1=0')); - $this->onEmpty = $this->_('No track selected...'); - } + return $this->findMenuItem('track', 'show-track'); } } Modified: trunk/library/classes/Gems/Snippets/Tracker/Summary/SummarySearchFormSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Tracker/Summary/SummarySearchFormSnippet.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Snippets/Tracker/Summary/SummarySearchFormSnippet.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -66,7 +66,18 @@ $this->_('(all organizations)')); $elements[] = null; - + + $dates = array( + 'gr2t_start_date' => $this->_('Track start'), + 'gr2t_end_date' => $this->_('Track end'), + 'gto_valid_from' => $this->_('Valid from'), + 'gto_valid_until' => $this->_('Valid until'), + ); + // $dates = 'gto_valid_from'; + $this->_addPeriodSelectors($elements, $dates, 'gto_valid_from'); + + $elements[] = null; + $sql = "SELECT DISTINCT ggp_id_group, ggp_name FROM gems__groups INNER JOIN gems__surveys ON ggp_id_group = gsu_id_primary_group INNER JOIN gems__rounds ON gsu_id_survey = gro_id_survey @@ -80,5 +91,4 @@ return $elements; } - } Modified: trunk/library/classes/Gems/Snippets/Tracker/Summary/SummaryTableSnippet.php =================================================================== --- trunk/library/classes/Gems/Snippets/Tracker/Summary/SummaryTableSnippet.php 2013-01-17 14:21:18 UTC (rev 1109) +++ trunk/library/classes/Gems/Snippets/Tracker/Summary/SummaryTableSnippet.php 2013-01-17 17:34:11 UTC (rev 1110) @@ -122,6 +122,10 @@ */ public function showPercentage($part, $total) { - return sprintf($this->_('%d%%'), round($part / $total * 100, 0)); + if ($total) { + return sprintf($this->_('%d%%'), round($part / $total * 100, 0)); + } else { + return $this->_('-'); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |