From: <gem...@li...> - 2012-02-07 12:27:04
|
Revision: 457 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=457&view=rev Author: mennodekker Date: 2012-02-07 11:24:23 +0000 (Tue, 07 Feb 2012) Log Message: ----------- Merged all changes up to rev 455 (=tags/1.5.0) Revision Links: -------------- http://gemstracker.svn.sourceforge.net/gemstracker/?rev=455&view=rev Modified Paths: -------------- trunk/library/classes/Gems/Auth/Adapter/Callback.php trunk/library/classes/Gems/Communication/RespondentWriter.php trunk/library/classes/Gems/Controller/BrowseEditAction.php trunk/library/classes/Gems/Controller/ModelActionAbstract.php trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php trunk/library/classes/Gems/Default/DatabaseAction.php trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/Gems/Default/SourceAction.php trunk/library/classes/Gems/Default/StaffAction.php trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/Gems/Default/TrackAction.php trunk/library/classes/Gems/Default/TrackActionAbstract.php trunk/library/classes/Gems/Default/TrackMaintenanceAction.php trunk/library/classes/Gems/Form/TableForm.php trunk/library/classes/Gems/Menu.php trunk/library/classes/Gems/Model/DbaModel.php trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php trunk/library/classes/Gems/Snippets/ModelFormSnippetGeneric.php trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php trunk/library/classes/Gems/Snippets/ModelTableSnippetGeneric.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php trunk/library/classes/Gems/Tracker/Model/TrackModel.php trunk/library/classes/Gems/Tracker/RespondentTrack.php trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php trunk/library/classes/Gems/Tracker.php trunk/library/classes/Gems/Upgrades.php trunk/library/classes/Gems/UpgradesAbstract.php trunk/library/classes/Gems/User/OldStaffUserDefinition.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/MUtil/Controller/Action.php trunk/library/classes/MUtil/Html/Creator.php trunk/library/classes/MUtil/Html/HtmlElement.php trunk/library/classes/MUtil/Html/ImgElement.php trunk/library/classes/MUtil/Html/TBodyElement.php trunk/library/classes/MUtil/Html.php trunk/library/classes/MUtil/Lazy.php trunk/library/classes/MUtil/Model/FormBridge.php trunk/library/classes/MUtil/Model/VerticalTableBridge.php trunk/library/classes/MUtil/Snippets/ModelFormSnippetAbstract.php trunk/library/configs/db/patches.sql trunk/library/configs/db/tables/gems__radius_config.999.sql trunk/library/layouts/scripts/gemsnew.phtml trunk/library/snippets/AddTracksSnippet.php trunk/library/snippets/EditTrackEngineSnippet.php trunk/library/snippets/EditTrackSnippet.php trunk/library/snippets/Generic/AutosearchForm.php trunk/library/snippets/Generic/CurrentButtonRow.php trunk/library/snippets/Generic/ModelFormSnippet.php trunk/library/snippets/Generic/ModelItemTableSnippet.php trunk/library/snippets/Generic/ModelItemYesNoDeleteSnippet.php trunk/library/snippets/Generic/ModelTabFormSnippet.php trunk/library/snippets/Generic/ModelTableSnippet.php trunk/library/snippets/Mail/Log/MailLogBrowseSnippet.php trunk/library/snippets/Organization/ChooseOrganizationSnippet.php trunk/library/snippets/Organization/OrganizationEditSnippet.php trunk/library/snippets/Organization/OrganizationTableSnippet.php trunk/library/snippets/Respondent/MultiOrganizationTab.php trunk/library/snippets/RespondentTokenSnippet.php trunk/library/snippets/ShowTrackTokenSnippet.php trunk/library/snippets/Track/AvailableTracksSnippets.php trunk/new_project/htdocs/gems/css/gems-new.css trunk/new_project/htdocs/gems/css/gems.css Added Paths: ----------- trunk/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php Property Changed: ---------------- trunk/ trunk/library/ Property changes on: trunk ___________________________________________________________________ Modified: svn:mergeinfo - /branches/1.5.0-pulse:306-342,344,346 /tags/1.5.0beta1:305 + /branches/1.5.0-pulse:306-430 /branches/1.5.x:426-455 /tags/1.5.0beta1:305 Property changes on: trunk/library ___________________________________________________________________ Modified: svn:mergeinfo - /branches/1.5.0-pulse/library:306-344,346 /branches/newUser:113-150 /branches/newUser2:175-207 /branches/userloader:259-324 /tags/1.5.0beta1/library:305 + /branches/1.5.0-pulse/library:306-344,346 /branches/1.5.x/library:426-455 /branches/newUser:113-150 /branches/newUser2:175-207 /branches/userloader:259-324 /tags/1.5.0beta1/library:305 Modified: trunk/library/classes/Gems/Auth/Adapter/Callback.php =================================================================== --- trunk/library/classes/Gems/Auth/Adapter/Callback.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Auth/Adapter/Callback.php 2012-02-07 11:24:23 UTC (rev 457) @@ -43,8 +43,25 @@ */ class Gems_Auth_Adapter_Callback implements Zend_Auth_Adapter_Interface { + /** + * The callback to use + * + * @var callback + */ private $_callback; + + /** + * The identity to check + * + * @var string + */ private $_identity; + + /** + * The optional parameters to pass to the callback + * + * @var array + */ private $_params; /** @@ -54,9 +71,9 @@ * return true or false and in that case this adapter will wrap the result * in a Zend_Auth_Result * - * @param type $callback A valid callback - * @param type $identity The identity to use - * @param type $params Array of parameters needed for the callback + * @param callback $callback A valid callback + * @param string $identity The identity to use + * @param array $params Array of parameters needed for the callback */ public function __construct($callback, $identity, $params) { Modified: trunk/library/classes/Gems/Communication/RespondentWriter.php =================================================================== --- trunk/library/classes/Gems/Communication/RespondentWriter.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Communication/RespondentWriter.php 2012-02-07 11:24:23 UTC (rev 457) @@ -41,9 +41,11 @@ interface Gems_Communication_RespondentWriter { /** - * Writes the respondent + * Writes the respondent, creating a new one or updating the existing record + * * @param Gems_Communication_RespondentContainer $respondent - * @return int The internal id of the created/updated respondent + * @param int $userId + * @return boolean True if a new respondent was added, false if one was updated * @throws Gems_Communication_Exception */ public function writeRespondent(Gems_Communication_RespondentContainer $respondent, &$userId); Modified: trunk/library/classes/Gems/Controller/BrowseEditAction.php =================================================================== --- trunk/library/classes/Gems/Controller/BrowseEditAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Controller/BrowseEditAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -292,7 +292,7 @@ */ public function beforeFormDisplay ($form, $isNew) { - if ($this->useTabbedForms) { + if ($this->useTabbedForms || $form instanceof Gems_Form_TableForm) { /* Not needed anymore @@TODO: Remove when proven, as there is a set tab //Create the tabs tried in $form->render() but somehow that is never reached if ($form instanceof Gems_TabForm) { @@ -304,8 +304,11 @@ $element = new MUtil_Form_Element_Html('formLinks'); $element->setValue($links); $element->setOrder(999); - $form->resetContext(); + if ($form instanceof Gems_TabForm) { + $form->resetContext(); + } $form->addElement($element); + $form->addDisplayGroup(array('formLinks'), 'form_buttons'); } } else { $table = new MUtil_Html_TableElement(array('class' => 'formTable')); @@ -359,6 +362,7 @@ $form = new Gems_TabForm($options); } else { $form = parent::createForm($options); + //$form = new Gems_Form_TableForm($options); } return $form; @@ -713,6 +717,9 @@ $data = $newData + $data; } + if ($form instanceof Gems_TabForm) { + $form->resetContext(); + } return $form; } Modified: trunk/library/classes/Gems/Controller/ModelActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Controller/ModelActionAbstract.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Controller/ModelActionAbstract.php 2012-02-07 11:24:23 UTC (rev 457) @@ -147,13 +147,30 @@ } } + /** + * Return the current request ID, if any. + * + * Overrule this function if the last item in the page title + * should be something other than te value of + * MUtil_Model::REQUEST_ID. + * + * @return mixed + */ public function getInstanceId() { - if ($id = $this->request->getParam(MUtil_Model::REQUEST_ID)) { + if ($id = $this->_getParam(MUtil_Model::REQUEST_ID)) { return $id; } } + /** + * Returns the current html/head/title for this page. + * + * If the title is an array the seperator concatenates the parts. + * + * @param string $separator + * @return string + */ public function getTitle($separator = null) { if ($title_set = parent::getTitle($separator)) { Modified: trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-02-07 11:24:23 UTC (rev 457) @@ -208,6 +208,47 @@ } /** + * Return the current request ID, if any. + * + * Overrule this function if the last item in the page title + * should be something other than te value of + * MUtil_Model::REQUEST_ID. + * + * @return mixed + */ + public function getInstanceId() + { + if ($id = $this->_getParam(MUtil_Model::REQUEST_ID)) { + return $id; + } + } + + /** + * Returns the current html/head/title for this page. + * + * If the title is an array the seperator concatenates the parts. + * + * @param string $separator + * @return string + */ + public function getTitle($separator = null) + { + if ($title_set = parent::getTitle($separator)) { + return $title_set; + } + + $title = array(); + foreach($this->menu->getActivePath($this->getRequest()) as $menuItem) { + $title[] = $menuItem->get('label'); + } + if ($id = $this->getInstanceId()) { + $title[] = $id; + } + + return implode($separator, $title); + } + + /** * Intializes the html component. * * @param boolean $reset Throws away any existing html output when true Modified: trunk/library/classes/Gems/Default/DatabaseAction.php =================================================================== --- trunk/library/classes/Gems/Default/DatabaseAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/DatabaseAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -48,50 +48,6 @@ { public $sortKey = array('group' => SORT_ASC, 'type' => SORT_ASC, 'name' => SORT_ASC); - private function _runScript(array $data, $includeResultSets = false) - { - $results = array(); - $this->_runScripts($data, $results, $includeResultSets); - return $results; - } - - private function _runScripts(array $data, array &$results, $includeResultSets = false) - { - if ($data['script']) { - $queries = MUtil_Parser_Sql_WordsParser::splitStatements($data['script'], false); - $qCount = count($queries); - - $results[] = sprintf($this->_('Executed %2$s creation script %1$s:'), $data['name'], $this->_(strtolower($data['type']))); - $i = 1; - $resultSet = 1; - - foreach ($queries as $query) { - $sql = (string) $query; - try { - $stmt = $this->db->query($sql); - if ($rows = $stmt->rowCount()) { - if ($includeResultSets && ($data = $stmt->fetchAll())) { - $results[] = sprintf($this->_('%d record(s) returned as result set %d in step %d of %d.'), $rows, $resultSet, $i, $qCount); - $results[] = $data; - $resultSet++; - } else { - $results[] = sprintf($this->_('%d record(s) updated in step %d of %d.'), $rows, $i, $qCount); - } - } else { - $results[] = sprintf($this->_('Script ran step %d of %d succesfully.'), $i, $qCount); - } - } catch (Zend_Db_Statement_Exception $e) { - $results[] = $e->getMessage() . $this->_(' in step ') . $i . ':<pre>' . $sql . '</pre>'; - } - $i++; - } - } else { - $results[] = sprintf($this->_('No script for %1$s.'), $data['name']); - } - - return $results; - } - /** * Set the parameters needed by the menu. * @@ -168,10 +124,7 @@ $model->set('location', 'label', $this->_('Location')); } // $model->set('path', 'label', $this->_('Path')); - $model->set('state', 'label', $this->_('Status'), 'multiOptions', array( - Gems_Model_DbaModel::STATE_CREATED => $this->_('created'), - Gems_Model_DbaModel::STATE_DEFINED => $this->_('not created'), - Gems_Model_DbaModel::STATE_UNKNOWN => $this->_('unknown'))); + $model->set('state', 'label', $this->_('Status')); if ($detailed) { $model->set('script', 'label', $this->_('Script'), 'itemDisplay', 'pre'); @@ -482,7 +435,7 @@ $model = $this->getModel(); $data = $model->loadFirst(); - $results = $this->_runScript($data); + $results = $model->runScript($data); $this->addMessage($results); $this->_reroute(array('action' => 'show')); @@ -497,11 +450,13 @@ if ($this->_getParam('confirmed')) { if ($objects) { + $results = array(); $results[] = sprintf($this->_('Starting %d object creation scripts.'), $oCount) . '<br/>'; $i = 1; foreach ($objects as $data) { - $this->_runScripts($data, $results); + $result = $model->runScript($data); + $results = array_merge($results, $result); $results[] = sprintf($this->_('Finished %s creation script for object %d of %d'), $this->_(strtolower($data['type'])), $i, $oCount) . '<br/>'; $i++; } @@ -559,7 +514,8 @@ $data['name'] = ''; $data['type'] = $this->_('raw'); - $results = $this->_runScript($data, true); + $model = $this->getModel(); + $results = $model->runScript($data, true); $resultSet = 1; $echos = MUtil_Html::create()->array(); foreach ($results as $result) { Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -166,7 +166,8 @@ if($model->has('gor_user_class')) { $definitions = $this->loader->getUserLoader()->getAvailableStaffDefinitions(); //Use first element as default - $default = array_shift(array_keys($definitions)); + $tmp = array_keys($definitions); + $default = array_shift($tmp); $model->set('gor_user_class', 'default', $default); if (count($definitions)>1) { if ($action !== 'create') { Modified: trunk/library/classes/Gems/Default/SourceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SourceAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/SourceAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -231,7 +231,7 @@ { $source = $this->getSourceById(); - if ($source->checkSourceActive($this->session->user_id)) { + if ($source->checkSourceActive($this->loader->getCurrentUser()->getUserId())) { $this->addMessage($this->_('This installation is active.')); } else { $this->addMessage($this->_('Inactive installation.')); @@ -244,7 +244,7 @@ { $source = $this->getSourceById(); - if ($messages = $source->synchronizeSurveys($this->session->user_id)) { + if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { $this->addMessage($messages); } else { $this->addMessage($this->_('No changes.')); @@ -263,7 +263,7 @@ $source = $this->getSourceById($row['gso_id_source']); $this->addMessage(sprintf($this->_('Synchronization of source %s:'), $row['gso_source_name'])); - if ($messages = $source->synchronizeSurveys($this->session->user_id)) { + if ($messages = $source->synchronizeSurveys($this->loader->getCurrentUser()->getUserId())) { $this->addMessage($messages); } else { $this->addMessage($this->_('No changes.')); Modified: trunk/library/classes/Gems/Default/StaffAction.php =================================================================== --- trunk/library/classes/Gems/Default/StaffAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/StaffAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -188,9 +188,6 @@ $this->_instanceId = $data['gsf_login']; } - $sql = "SELECT ggp_id_group,ggp_role FROM gems__groups WHERE ggp_id_group = " . (int) $data['gsf_id_primary_group']; - $groups = $this->db->fetchPairs($sql); - if (!isset($data['gsf_id_organization']) || empty($data['gsf_id_organization'])) { $data['gsf_id_organization'] = $this->menu->getParameterSource()->getMenuParameter('gsf_id_organization', $this->loader->getCurrentUser()->getCurrentOrganizationId()); } Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -69,7 +69,7 @@ // Add pdf button if allowed if ($menuItem = $this->findAllowedMenuItem('pdf')) { - $bridge->addItemLink(iif($bridge->gsu_has_pdf,$menuItem->toActionLinkLower($this->getRequest(), $bridge))); + $bridge->addItemLink(MUtil_Lazy::iif($bridge->gsu_has_pdf, $menuItem->toActionLinkLower($this->getRequest(), $bridge))); } } Modified: trunk/library/classes/Gems/Default/TrackAction.php =================================================================== --- trunk/library/classes/Gems/Default/TrackAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/TrackAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -71,8 +71,9 @@ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { $bridge->gr2t_id_respondent_track; //For show and edit button - $bridge->tr()->appendAttrib('class', $bridge->row_class); + $bridge->tbody()->getFirst(true)->appendAttrib('class', $bridge->row_class); + // Add edit button if allowed, otherwise show, again if allowed if ($menuItem = $this->findAllowedMenuItem('show-track')) { $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); @@ -461,6 +462,9 @@ } } + /** + * Show information on a single track assigned to a respondent + */ public function showTrackAction() { $request = $this->getRequest(); @@ -498,9 +502,9 @@ $fieldValues = $this->db->fetchAll($sql, array('gr2t2f_id_respondent_track' => $data['gr2t_id_respondent_track'])); foreach ($fieldValues as $field) { + $table->tr(); $table->tdh($field['gtf_field_name']); $table->td($field['gr2t2f_value']); - $table->tr(); } $this->html[] = $table; Modified: trunk/library/classes/Gems/Default/TrackActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Default/TrackActionAbstract.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/TrackActionAbstract.php 2012-02-07 11:24:23 UTC (rev 457) @@ -203,6 +203,7 @@ { $model = $this->loader->getTracker()->getRespondentTrackModel(); + $model->resetOrder(); $model->set('gtr_track_name', 'label', $this->_('Track')); $model->set('gr2t_track_info', 'label', $this->_('Description'), 'description', $this->_('Enter the particulars concerning the assignment to this respondent.')); Modified: trunk/library/classes/Gems/Default/TrackMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/TrackMaintenanceAction.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Default/TrackMaintenanceAction.php 2012-02-07 11:24:23 UTC (rev 457) @@ -1,6 +1,5 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -46,6 +45,13 @@ */ class Gems_Default_TrackMaintenanceAction extends Gems_Controller_BrowseEditAction { + /** + * Mode for the current addBrowse drawing. + * + * @var string + */ + protected $browseMode; + public $sortKey = array('gtr_track_name' => SORT_ASC); public $summarizedActions = array('index', 'autofilter', 'check-all'); @@ -61,20 +67,27 @@ */ protected function addBrowseTableColumns(MUtil_Model_TableBridge $bridge, MUtil_Model_ModelAbstract $model) { - if ($this->getRequest()->getActionName() == 'index') { - if ($menuItem = $this->findAllowedMenuItem('show')) { - $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); - } - if ($menuItem = $this->findAllowedMenuItem('edit')) { - $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); - } + $request = $this->getRequest(); + + $actionKey = $request->getActionKey(); + $contrKey = $request->getControllerKey(); + $controller = $this->browseMode ? $this->browseMode : $request->getControllerName(); + + if ($menuItem = $this->menu->find(array($contrKey => $controller, $actionKey => 'show'))) { + $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); } + $menuItem = $this->menu->find(array($contrKey => $controller, $actionKey => 'edit')); + foreach($model->getItemsOrdered() as $name) { if ($label = $model->get($name, 'label')) { $bridge->addSortable($name, $label); } } + + if ($menuItem) { + $bridge->addItemLink($menuItem->toActionLinkLower($this->getRequest(), $bridge)); + } } /** @@ -283,24 +296,13 @@ $model = $this->getModel(); $repeatable = $model->loadRepeatable(); + $this->browseMode = 'track-' . $mode; + $table = $this->getBrowseTable($baseurl); $table->setOnEmpty(sprintf($this->_('No %s found'), $this->_($mode))); $table->getOnEmpty()->class = 'centerAlign'; $table->setRepeater($repeatable); - $url = array( - 'controller' => 'track-' . $mode, - 'action' => 'edit' - ); - - foreach ($keys as $idx => $key) { - $url[$idx] = $repeatable->$key; - } - - $href = new MUtil_Html_HrefArrayAttribute($url); - $body = $table->tbody(); - $body[0]->onclick = array('location.href=\'', $href, '\';'); - $this->html->h3(sprintf($this->_('%s in track'), $this->_(ucfirst($mode)))); $this->html[] = $table; $this->html->actionLink(array('controller' => 'track-' . $mode, 'action' => 'create', 'id' => $this->getRequest()->getParam(MUtil_Model::REQUEST_ID)), $this->_('Add')); Modified: trunk/library/classes/Gems/Form/TableForm.php =================================================================== --- trunk/library/classes/Gems/Form/TableForm.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Form/TableForm.php 2012-02-07 11:24:23 UTC (rev 457) @@ -28,7 +28,7 @@ * Short description of file * * @package Gems - * @subpackage + * @subpackage Form * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License * @version $Id$ Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Menu.php 2012-02-07 11:24:23 UTC (rev 457) @@ -282,7 +282,7 @@ $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'); + ->addHiddenParameter(Gems_Model::TRACK_ID, $this->escort->getTrackId(), 'gtr_track_type', $trType); $tkPages[$trType] = $subPage->addAction($this->_('Token'), 'pr.token', 'show') ->addNamedParameters(MUtil_Model::REQUEST_ID, 'gto_id_token') Modified: trunk/library/classes/Gems/Model/DbaModel.php =================================================================== --- trunk/library/classes/Gems/Model/DbaModel.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Model/DbaModel.php 2012-02-07 11:24:23 UTC (rev 457) @@ -60,6 +60,10 @@ protected $file_encoding; protected $locations; protected $mainDirectory; + /** + * @var Zend_Translate_Adapter + */ + protected $translate; private $_sorts; @@ -73,6 +77,9 @@ $this->db = $db; + //Grab translate object from the Escort + $this->translate = GemsEscort::getInstance()->translate; + $this->set('group', 'maxlength', 40, 'type', MUtil_Model::TYPE_STRING); $this->set('name', 'key', true, 'maxlength', 40, 'type', MUtil_Model::TYPE_STRING); $this->set('type', 'maxlength', 40, 'type', MUtil_Model::TYPE_STRING); @@ -86,8 +93,25 @@ $this->set('script', 'type', MUtil_Model::TYPE_STRING); $this->set('lastChanged', 'type', MUtil_Model::TYPE_DATETIME); $this->set('location', 'maxlength', 12, 'type', MUtil_Model::TYPE_STRING); + $this->set('state', 'multiOptions', array( + Gems_Model_DbaModel::STATE_CREATED => $this->_('created'), + Gems_Model_DbaModel::STATE_DEFINED => $this->_('not created'), + Gems_Model_DbaModel::STATE_UNKNOWN => $this->_('unknown'))); } + /** + * proxy for easy access to translations + * + * @param string $messageId Translation string + * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale + * identifier, @see Zend_Locale for more information + * @return string + */ + private function _($messageId, $locale = null) + { + return $this->translate->_($messageId, $locale); + } + private function _getGroupName($name) { if ($pos = strpos($name, '__')) { @@ -374,6 +398,56 @@ return $this->loadFirst(array('name' => $tableName), false); } + /** + * Run a sql statement from an object loaded through this model + * + * $data is an array with the following keys: + * script The sql statement to be executed + * name The name of the table, used in messages + * type Type of db element (table or view), used in messages + * + * @param array $data + * @param type $includeResultSets + * @return type + */ + public function runScript(array $data, $includeResultSets = false) + { + $results = array(); + if ($data['script']) { + $queries = MUtil_Parser_Sql_WordsParser::splitStatements($data['script'], false); + $qCount = count($queries); + + $results[] = sprintf($this->_('Executed %2$s creation script %1$s:'), $data['name'], $this->_(strtolower($data['type']))); + $i = 1; + $resultSet = 1; + + foreach ($queries as $query) { + $sql = (string) $query; + try { + $stmt = $this->db->query($sql); + if ($rows = $stmt->rowCount()) { + if ($includeResultSets && ($data = $stmt->fetchAll())) { + $results[] = sprintf($this->_('%d record(s) returned as result set %d in step %d of %d.'), $rows, $resultSet, $i, $qCount); + $results[] = $data; + $resultSet++; + } else { + $results[] = sprintf($this->_('%d record(s) updated in step %d of %d.'), $rows, $i, $qCount); + } + } else { + $results[] = sprintf($this->_('Script ran step %d of %d succesfully.'), $i, $qCount); + } + } catch (Zend_Db_Statement_Exception $e) { + $results[] = $e->getMessage() . $this->_(' in step ') . $i . ':<pre>' . $sql . '</pre>'; + } + $i++; + } + } else { + $results[] = sprintf($this->_('No script for %1$s.'), $data['name']); + } + + return $results; + } + public function save(array $newValues, array $filter = null) { // TODO: Save of data Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2012-02-07 11:24:23 UTC (rev 457) @@ -193,7 +193,7 @@ */ public function getAccountDelayFactor() { - if (isset($this->account['delayFactor'])) { + if (isset($this->account) && isset($this->account['delayFactor'])) { return intval($this->account['delayFactor']); } else { return 4; @@ -225,6 +225,24 @@ } /** + * Returns an (optional) default organization from the project settings + * + * @return int Organization number or -1 when not set + */ + public function getDefaultOrganization() + { + if ($this->offsetExists('organization')) { + $orgs = $this->offsetGet('organization'); + + if (isset($orgs['default'])) { + return $orgs['default']; + } + } + + return -1; + } + + /** * Returns the public name of this project. * @return string */ @@ -275,7 +293,7 @@ public function getSuperAdminName() { if (isset($this->admin) && isset($this->admin['user'])) { - return $this->admin['user']; + return trim($this->admin['user']); } } @@ -287,7 +305,7 @@ protected function getSuperAdminPassword() { if (isset($this->admin) && isset($this->admin['pwd'])) { - return $this->admin['pwd']; + return trim($this->admin['pwd']); } } Modified: trunk/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelFormSnippetAbstract.php 2012-02-07 11:24:23 UTC (rev 457) @@ -167,8 +167,9 @@ } /** + * Retrieve the header title to display * - * @return string The header title to display + * @return string */ protected function getTitle() { Modified: trunk/library/classes/Gems/Snippets/ModelFormSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelFormSnippetGeneric.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelFormSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -27,7 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * - * @package MUtil + * @package Gems * @subpackage Snippets * @author Matijs de Jong <mj...@ma...> * @copyright Copyright (c) 2011 Erasmus MC @@ -44,7 +44,7 @@ * their naming conventions, but exists only to make it simple to extend this class * for a specific implementation. * - * @package MUtil + * @package Gems * @subpackage Snippets * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License Modified: trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php 2012-02-07 11:24:23 UTC (rev 457) @@ -88,7 +88,7 @@ * 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_VerticalTableBridge $bridge * @param MUtil_Model_ModelAbstract $model * @return void */ @@ -167,7 +167,7 @@ * Overrule this function to set the header differently, without * having to recode the core table building code. * - * @param MUtil_Model_TableBridge $bridge + * @param MUtil_Model_VerticalTableBridge $bridge * @param MUtil_Model_ModelAbstract $model * @return void */ Modified: trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -27,7 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * - * @package MUtil + * @package Gems * @subpackage Snippets * @author Matijs de Jong <mj...@ma...> * @copyright Copyright (c) 2011 Erasmus MC @@ -45,7 +45,7 @@ * their naming conventions, but exists only to make it simple to extend this class * for a specific implementation. * - * @package MUtil + * @package Gems * @subpackage Snippets * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License Modified: trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -27,7 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * - * @package MUtil + * @package Gems * @subpackage Snippets * @author Matijs de Jong <mj...@ma...> * @copyright Copyright (c) 2011 Erasmus MC @@ -46,7 +46,7 @@ * their naming conventions, but exists only to make it simple to extend this class * for a specific implementation. * - * @package MUtil + * @package Gems * @subpackage Snippets * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License Modified: trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelTabFormSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -56,6 +56,19 @@ protected $_form; /** + * Simple default function for making sure there is a $this->_saveButton. + * + * As the save button is not part of the model - but of the interface - it + * does deserve it's own function. + */ + protected function addSaveButton() + { + $this->_form->resetContext(); + parent::addSaveButton(); + } + + + /** * Perform some actions on the form, right before it is displayed but already populated * * Here we add the table display to the form. Modified: trunk/library/classes/Gems/Snippets/ModelTableSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Snippets/ModelTableSnippetGeneric.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Snippets/ModelTableSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -27,7 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * - * @package MUtil + * @package Gems * @subpackage Snippets * @author Matijs de Jong <mj...@ma...> * @copyright Copyright (c) 2011 Erasmus MC @@ -45,7 +45,7 @@ * their naming conventions, but exists only to make it simple to extend this class * for a specific implementation. * - * @package MUtil + * @package Gems * @subpackage Snippets * @copyright Copyright (c) 2011 Erasmus MC * @license New BSD License Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/TabForm.php 2012-02-07 11:24:23 UTC (rev 457) @@ -33,6 +33,8 @@ */ /** + * Creates a form using tab-layout where each tab is a subform + * * @package Gems * @subpackage Form * @copyright Copyright (c) 2011 Erasmus MC @@ -41,6 +43,8 @@ class Gems_TabForm extends Gems_Form { /** + * Holds the last tab we added information to + * * @var Gems_Form_TabSubForm */ private $currentTab = null; @@ -168,7 +172,7 @@ /** * Retrieve a named tab (subform) and set the active tab to this one * - * @param type $name + * @param string $name * @return Gems_Form_TabSubForm */ public function getTab($name) @@ -316,6 +320,11 @@ $jquery->addOnLoad($js); } + /** + * Load the default decorators + * + * @return void + */ public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; @@ -335,6 +344,8 @@ } /** + * Reset the currentTab to be the main form again + * * As addElement and addDisplayGroup provide a fluent way of working with subforms * we need to provide a method to skip back to the main form again. */ @@ -342,6 +353,11 @@ $this->currentTab = null; } + /** + * Select a tab by it's numerical index + * + * @param int $tabIdx + */ public function selectTab($tabIdx) { $this->getElement('tab')->setValue($tabIdx); $this->setAttrib('selected', $tabIdx); Modified: trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Tracker/Engine/StepEngineAbstract.php 2012-02-07 11:24:23 UTC (rev 457) @@ -311,7 +311,12 @@ */ public function checkTokensFromStart(Gems_Tracker_RespondentTrack $respTrack, $userId) { - return $this->checkTokensFrom($respTrack, $respTrack->getFirstToken(), $userId); + $token = $respTrack->getFirstToken(); + if ($token instanceof Gems_Tracker_Token) { + return $this->checkTokensFrom($respTrack, $respTrack->getFirstToken(), $userId); + } else { + return 0; + } } /** Modified: trunk/library/classes/Gems/Tracker/Model/TrackModel.php =================================================================== --- trunk/library/classes/Gems/Tracker/Model/TrackModel.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Tracker/Model/TrackModel.php 2012-02-07 11:24:23 UTC (rev 457) @@ -95,7 +95,7 @@ * Sets the labels, format functions, etc... * * @param boolean $detailed True when shopwing detailed information - * @return Gems_Tracker_Model_StandardTokenModel + * @return Gems_Tracker_Model_TrackModel */ public function applyFormatting($detailed = false) { @@ -110,6 +110,8 @@ $this->set('gtr_active', 'label', $this->translate->_('Active'), 'multiOptions', $translated->getYesNo()); $this->set('gtr_date_start', 'label', $this->translate->_('From'), 'dateFormat', $translated->dateFormatString, 'formatFunction', $translated->formatDate); $this->set('gtr_date_until', 'label', $this->translate->_('Use until'), 'dateFormat', $translated->dateFormatString, 'formatFunction', $translated->formatDateForever); + + return $this; } /** Modified: trunk/library/classes/Gems/Tracker/RespondentTrack.php =================================================================== --- trunk/library/classes/Gems/Tracker/RespondentTrack.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Tracker/RespondentTrack.php 2012-02-07 11:24:23 UTC (rev 457) @@ -201,7 +201,7 @@ /** * Makes sure the respondent data is part of the $this->_respTrackData */ - private function _ensureRespondentData() + protected function _ensureRespondentData() { if (! isset($this->_respTrackData['grs_id_user'], $this->_respTrackData['gr2o_id_user'], $this->_respTrackData['gco_code'])) { $sql = "SELECT * @@ -452,6 +452,16 @@ } /** + * Returns the description of this track as stored in the fields. + * + * @return string + */ + public function getFieldsInfo() + { + return $this->_respTrackData['gr2t_track_info']; + } + + /** * Returns the first token in this track * * @return Gems_Tracker_Token Modified: trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php =================================================================== --- trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Tracker/Snippets/AnswerModelSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -90,6 +90,13 @@ protected $showButtons = true; /** + * Switch to put the display of the headers on or off + * + * @var boolean + */ + protected $showHeaders = true; + + /** * Switch to put the display of the current token as select to true or false. * * @var boolean @@ -204,14 +211,16 @@ if ($this->tokenId) { if ($this->token->exists) { - $htmlDiv->h3(sprintf($this->_('%s answers for patient number %s'), $this->token->getSurveyName(), $this->token->getPatientNumber())); + if ($this->showHeaders) { + $htmlDiv->h3(sprintf($this->_('%s answers for patient number %s'), $this->token->getSurveyName(), $this->token->getPatientNumber())); - $htmlDiv->pInfo(sprintf( - $this->_('Answers for token %s, patient number %s: %s.'), - strtoupper($this->tokenId), - $this->token->getPatientNumber(), - $this->token->getRespondentName())) - ->appendAttrib('class', 'noprint'); + $htmlDiv->pInfo(sprintf( + $this->_('Answers for token %s, patient number %s: %s.'), + strtoupper($this->tokenId), + $this->token->getPatientNumber(), + $this->token->getRespondentName())) + ->appendAttrib('class', 'noprint'); + } $table = parent::getHtmlOutput($view); $table->setPivot(true, 2, 1); Copied: trunk/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php (from rev 455, branches/1.5.x/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php) =================================================================== --- trunk/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php (rev 0) +++ trunk/library/classes/Gems/Tracker/Snippets/EditTrackEngineSnippetGeneric.php 2012-02-07 11:24:23 UTC (rev 457) @@ -0,0 +1,304 @@ +<?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: EditTrackEngineSnippetGeneric.php 203 2012-01-01t 12:51:32Z matijs $ + */ + +/** + * Basic snippet for editing track engines instances + * + * @package Gems + * @subpackage Tracker + * @copyright Copyright (c) 2012 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Gems_Tracker_Snippets_EditTrackEngineSnippetGeneric extends Gems_Snippets_ModelFormSnippetAbstract +{ + /** + * + * @var string Field for storing the old track class + */ + protected $_oldClassName = 'old__gtr_track_class'; + + /** + * + * @var Zend_Db_Adapter_Abstract + */ + protected $db; + + /** + * Required + * + * @var Gems_Loader + */ + protected $loader; + + /** + * Optional, required when creating or $trackId should be set + * + * @var Gems_Tracker_Engine_TrackEngineInterface + */ + protected $trackEngine; + + /** + * Optional, required when creating or $engine should be set + * + * @var int Track Id + */ + protected $trackId; + + /** + * @var Gems_Util + */ + protected $util; + + /** + * Adds elements from the model to the bridge that creates the form. + * + * Overrule this function to add different elements to the browse table, without + * having to recode the core table building code. + * + * @param MUtil_Model_FormBridge $bridge + * @param MUtil_Model_ModelAbstract $model + */ + protected function addFormElements(MUtil_Model_FormBridge $bridge, MUtil_Model_ModelAbstract $model) + { + if (! $this->createData) { + $bridge->addHidden('gtr_id_track'); + } + $bridge->addText('gtr_track_name', 'size', 30, 'minlength', 4, 'validator', $model->createUniqueValidator('gtr_track_name')); + + // gtr_track_class + if ($this->trackEngine) { + $options = $model->get('gtr_track_class', 'multiOptions'); + $alternatives = $this->trackEngine->getConversionTargets($options); + if (count($alternatives) > 1) { + $options = $alternatives; + + $bridge->addHidden($this->_oldClassName); + + if (! isset($this->formData[$this->_oldClassName])) { + $this->formData[$this->_oldClassName] = $this->formData['gtr_track_class']; + } + + $classEdit = true; + } else { + $classEdit = false; + } + } else { + $tracker = $this->loader->getTracker(); + $options = $tracker->getTrackEngineList(true, true); + $classEdit = true; + } + $model->set('gtr_track_class', 'multiOptions', $options, 'escape', false); + if ($classEdit) { + $bridge->addRadio( 'gtr_track_class'); + } else { + $bridge->addExhibitor('gtr_track_class'); + } + + $bridge->addDate('gtr_date_start'); + $bridge->addDate('gtr_date_until'); + if (! $this->createData) { + $bridge->addCheckbox('gtr_active'); + } + $bridge->addMultiCheckbox('gtr_organizations', 'label', $this->_('Organizations'), 'multiOptions', $this->util->getDbLookup()->getOrganizations(), 'required', true); + } + + /** + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required are missing. + */ + public function checkRegistryRequestsAnswers() + { + return $this->db && $this->loader && parent::checkRegistryRequestsAnswers(); + } + + /** + * Creates the model + * + * @return MUtil_Model_ModelAbstract + */ + protected function createModel() + { + $model = $this->loader->getTracker()->getTrackModel(); + $model->applyFormatting(true); + + return $model; + } + + /** + * + * @return Gems_Menu_MenuList + * / + protected function getMenuList() + { + $links = $this->menu->getMenuList(); + $links->addParameterSources($this->request, $this->menu->getParameterSource()); + + $links->addByController('track', 'show-track', $this->_('Show track')) + ->addByController('track', 'index', $this->_('Show tracks')) + ->addByController('respondent', 'show', $this->_('Show respondent')); + + return $links; + } // */ + + /** + * Helper function to allow generalized statements about the items in the model to used specific item names. + * + * @param int $count + * @return $string + */ + public function getTopic($count = 1) + { + return $this->plural('track', 'tracks', $count); + } + + /** + * + * @return string The header title to display + */ + protected function getTitle() + { + if ($this->createData) { + return $this->_('Add new track'); + } else { + return parent::getTitle(); + } + } + + /** + * 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() + { + if ($this->trackEngine && (! $this->trackId)) { + $this->trackId = $this->trackEngine->getTrackId(); + } + + if ($this->trackId) { + // We are updating + $this->createData = false; + + // Try to get $this->trackEngine filled + if (! $this->trackEngine) { + // Set the engine used + $this->trackEngine = $this->loader->getTracker()->getTrackEngine($this->trackId); + } + + } else { + // We are inserting + $this->createData = true; + $this->saveLabel = $this->_($this->_('Add new track')); + } + + return parent::hasHtmlOutput(); + } + + /** + * Hook that loads the form data from $_POST or the model + * + * Or from whatever other source you specify here. + */ + protected function loadFormData() + { + parent::loadFormData(); + + // feature request #200 + if (isset($this->formData['gtr_organizations']) && (! is_array($this->formData['gtr_organizations']))) { + $this->formData['gtr_organizations'] = explode('|', trim($this->formData['gtr_organizations'], '|')); + } + } + + /** + * Hook containing the actual save code. + * + * Call's afterSave() for user interaction. + * + * @see afterSave() + */ + protected function saveData() + { + // feature request #200 + if (isset($this->formData['gtr_organizations']) && is_array($this->formData['gtr_organizations'])) { + $this->formData['gtr_organizations'] = '|' . implode('|', $this->formData['gtr_organizations']) . '|'; + } + if ($this->trackEngine) { + $this->formData['gtr_survey_rounds'] = $this->trackEngine->calculateRoundCount(); + } else { + $this->formData['gtr_survey_rounds'] = 0; + } + + parent::saveData(); + + // Check for creation + if ($this->createData) { + if (isset($this->formData['gtr_id_track'])) { + $this->trackId = $this->formData['gtr_id_track']; + } + } elseif ($this->trackEngine && + isset($this->formData[$this->_oldClassName], $this->formData['gtr_track_class']) && + $this->formData[$this->_oldClassName] != $this->formData['gtr_track_class']) { + + // Track conversion + $this->trackEngine->convertTo($this->formData['gtr_track_class']); + } + } + + /** + * Set what to do when the form is 'finished'. + * + * @return EditTrackEngineSnippet (continuation pattern) + */ + protected function setAfterSaveRoute() + { + // Default is just go to the index + if ($this->routeAction && ($this->request->getActionName() !== $this->routeAction)) { + $this->afterSaveRouteUrl = array($this->request->getActionKey() => $this->routeAction, MUtil_Model::REQUEST_ID => $this->trackId); + } + + return $this; + } +} Modified: trunk/library/classes/Gems/Tracker.php =================================================================== --- trunk/library/classes/Gems/Tracker.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Tracker.php 2012-02-07 11:24:23 UTC (rev 457) @@ -842,9 +842,9 @@ $batch = $this->_loadClass('Batch_ProcessTokensBatch', true, array($batch_id)); if (! $batch->isLoaded()) { - $tokenRows = $tokenSelect->fetchAll(); - - foreach ($tokenRows as $tokenData) { + $statement = $tokenSelect->getSelect()->query(); + //Process one row at a time to prevent out of memory errors for really big resultsets + while ($tokenData = $statement->fetch()) { $batch->addToken($tokenData['gto_id_token'], $userId); } } @@ -898,16 +898,16 @@ public function recalculateTokensBatch($batch_id, $userId = null, $cond = null) { $userId = $this->_checkUserId($userId); - $tokenSelect = $this->getTokenSelect(); - $tokenSelect->andReceptionCodes() - ->andRespondents() - ->andRespondentOrganizations() - ->andConsents(); + $tokenSelect = $this->getTokenSelect(array('gto_id_token')); + $tokenSelect->andReceptionCodes(array()) + ->andRespondents(array()) + ->andRespondentOrganizations(array()) + ->andConsents(array()); if ($cond) { $tokenSelect->forWhere($cond); } //Only select surveys that are active in the source (so we can recalculate inactive in Gems) - $tokenSelect->andSurveys(); + $tokenSelect->andSurveys(array()); $tokenSelect->forWhere('gsu_surveyor_active = 1'); self::$verbose = true; Modified: trunk/library/classes/Gems/Upgrades.php =================================================================== --- trunk/library/classes/Gems/Upgrades.php 2012-02-07 11:12:45 UTC (rev 456) +++ trunk/library/classes/Gems/Upgrades.php 2012-02-07 11:24:23 UTC (rev 457) @@ -61,14 +61,42 @@ /** * To upgrade from 143 to 15 we need to do some work: - * 1. execute db patches + * 1. execute db patches 42 and 43 + * 2. create new tables */ public function Upgrade143to15() { + $this->addMessage($this->_('Executing patchlevel 42')); $this->patcher->executePatch(42); - + $this->addMessage($this->_('Executing patchlevel 43')); + $this->patcher->executePatch(43); + $this->invalidateCache(); + $this->addMessage($this->_('Creating new tables')); + $this->createNewTables(); + + $this->invalidateCache(); + + $this->addMessage($this->_('Syncing surveys for all sources')); + //Now sync the db sources to allow limesurvey source to add a field to the tokentable + $model = new MUtil_Model_TableModel('gems__sources'); + $data = $model->load(false); + + $tracker = $this->loader->getTracker(); + + foreach... [truncated message content] |