|
From: <gem...@li...> - 2013-03-13 15:48:18
|
Revision: 1175
http://sourceforge.net/p/gemstracker/code/1175
Author: matijsdejong
Date: 2013-03-13 15:48:13 +0000 (Wed, 13 Mar 2013)
Log Message:
-----------
RespondentNewAction.php works
Getting the current menu is made more simple
Fixed some bugs in default project setup
Modified Paths:
--------------
trunk/library/classes/Gems/Default/RespondentAction.php
trunk/library/classes/Gems/Default/RespondentNewAction.php
trunk/library/classes/Gems/Menu.php
trunk/library/classes/Gems/Model/RespondentModel.php
trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php
trunk/library/classes/Gems/Snippets/RespondentDetailSnippetAbstract.php
trunk/library/classes/Gems/TabForm.php
trunk/library/classes/MUtil/Snippets/TabSnippetAbstract.php
trunk/library/snippets/RespondentDetailsSnippet.php
Modified: trunk/library/classes/Gems/Default/RespondentAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentAction.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/Default/RespondentAction.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -182,7 +182,9 @@
$bridge->addCheckBox('calc_email', 'label', $this->_('Respondent has no e-mail'));
$bridge->addText( 'grs_address_1', 'size', 40, 'description', $this->_('With housenumber'))
->addFilter( $ucfirst);
- $bridge->addText( 'grs_address_2', 'size', 40);
+ if ($model->has('grs_address_2')) {
+ $bridge->addText( 'grs_address_2', 'size', 40);
+ }
$bridge->addText( 'grs_zipcode', 'size', 7, 'description', '0000 AA');
$bridge->addFilter( 'grs_zipcode', new Gems_Filter_DutchZipcode());
$bridge->addText( 'grs_city')
@@ -252,6 +254,7 @@
$options = $this->util->getReceptionCodeLibrary()->getRespondentDeletionCodes();
+ $this->useTabbedForms = false;
$bridge = new MUtil_Model_FormBridge($model, $this->createForm());
$bridge->addSelect('gr2o_reception_code',
'label', $this->_('Rejection code'),
Modified: trunk/library/classes/Gems/Default/RespondentNewAction.php
===================================================================
--- trunk/library/classes/Gems/Default/RespondentNewAction.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/Default/RespondentNewAction.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -47,6 +47,18 @@
abstract class Gems_Default_RespondentNewAction extends Gems_Controller_ModelSnippetActionAbstract
{
/**
+ * The parameters used for the create and edit actions.
+ *
+ * When the value is a function name of that object, then that functions is executed
+ * with the array key as single parameter and the return value is set as the used value
+ * - unless the key is an integer in which case the code is executed but the return value
+ * is not stored.
+ *
+ * @var array Mixed key => value array for snippet initialization
+ */
+ protected $createEditParameters = array('resetRoute' => true);
+
+ /**
* The snippets used for the create and edit actions.
*
* @var mixed String or array of snippets name
@@ -54,12 +66,55 @@
protected $createEditSnippets = 'ModelTabFormSnippetGeneric';
/**
+ * The snippets used for the delete action.
*
+ * @var mixed String or array of snippets name
+ */
+ public $deleteSnippets = array('RespondentDetailsSnippet');
+
+ /**
+ * The snippets used for the export action.
+ *
+ * @var mixed String or array of snippets name
+ */
+ public $exportSnippets = array('RespondentDetailsSnippet');
+
+ /**
+ *
* @var Gems_Loader
*/
public $loader;
/**
+ * The snippets used for the show action
+ *
+ * @var mixed String or array of snippets name
+ */
+ protected $showSnippets = array(
+ 'Generic_ContentTitleSnippet',
+ 'RespondentDetailsSnippet',
+ 'AddTracksSnippet',
+ 'RespondentTokenTabsSnippet',
+ 'RespondentTokenSnippet',
+ );
+
+ /**
+ * The parameters used for the show action
+ *
+ * When the value is a function name of that object, then that functions is executed
+ * with the array key as single parameter and the return value is set as the used value
+ * - unless the key is an integer in which case the code is executed but the return value
+ * is not stored.
+ *
+ * @var array Mixed key => value array for snippet initialization
+ */
+ protected $showParameters = array(
+ 'baseUrl' => 'getItemUrlArray',
+ 'onclick' => 'getEditLink',
+ 'respondentData' => 'getRespondentData',
+ );
+
+ /**
* 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
@@ -89,6 +144,110 @@
}
/**
+ * Adjusted delete action
+ */
+ public function deleteAction()
+ {
+ $model = $this->getModel();
+ $params = $this->_processParameters($this->showParameters);
+ $data = $params['respondentData'];
+ $request = $this->getRequest();
+
+ $options = $this->util->getReceptionCodeLibrary()->getRespondentDeletionCodes();
+
+ $bridge = new MUtil_Model_FormBridge($model, new Gems_Form());
+ $bridge->addSelect('gr2o_reception_code',
+ 'label', $this->_('Rejection code'),
+ 'multiOptions', $options,
+ 'required', true,
+ 'size', max(7, min(3, count($options) + 1)));
+
+ $form = $bridge->getForm();
+
+ $save = new Zend_Form_Element_Submit('save_button', array('label' => $this->_('Delete respondent'), 'class' => 'button'));
+ $form->addElement($save);
+
+ if ($request->isPost()) {
+ $data = $_POST + $data;
+ if ($form->isValid($data )) {
+
+ $code = $this->util->getReceptionCode($data['gr2o_reception_code']);
+
+ // Is the respondent really removed
+ if (! $code->isSuccess()) {
+ $userId = $this->loader->getCurrentUser()->getUserId();
+
+ // Cascade to tracks
+ // the responsiblilty to handle it correctly is on the sub objects now.
+ $tracks = $this->loader->getTracker()->getRespondentTracks($data['gr2o_id_user'], $data['gr2o_id_organization']);
+ foreach ($tracks as $track) {
+ $track->setReceptionCode($code, null, $userId);
+ }
+
+ // Perform actual save, but not simple stop codes.
+ if ($code->isForRespondents()) {
+ $values['gr2o_reception_code'] = $data['gr2o_reception_code'];
+ $values['gr2o_changed'] = new MUtil_Db_Expr_CurrentTimestamp();
+ $values['gr2o_changed_by'] = $userId;
+
+ $where = 'gr2o_id_user = ? AND gr2o_id_organization = ?';
+ $where = $this->db->quoteInto($where, $data['gr2o_id_user'], null, 1);
+ $where = $this->db->quoteInto($where, $data['gr2o_id_organization'], null, 1);
+
+ $this->db->update('gems__respondent2org', $values, $where);
+
+ $this->addMessage($this->_('Respondent deleted.'));
+ $this->_reroute(array('action' => 'index'), true);
+ } else {
+ // Just a stop code
+ $this->addMessage($this->_('Respondent tracks stopped.'));
+ $this->_reroute(array('action' => 'show'));
+ }
+ } else {
+ $this->addMessage($this->_('Choose a reception code to delete.'));
+ }
+ } else {
+ $this->addMessage($this->_('Input error! No changes saved!'));
+ }
+ }
+ $form->populate($data);
+
+ $table = new MUtil_Html_TableElement(array('class' => 'formTable'));
+ $table->setAsFormLayout($form, true, true);
+ $table['tbody'][0][0]->class = 'label'; // Is only one row with formLayout, so all in output fields get class.
+
+ $this->addSnippets($this->deleteSnippets, $params);
+
+ $this->html[] = $form;
+ }
+
+ /**
+ * Action for dossier export
+ */
+ public function exportAction()
+ {
+ $params = $this->_processParameters($this->showParameters);
+ $data = $params['respondentData'];
+
+ $this->addSnippets($this->exportSnippets, $params);
+
+ //Now show the export form
+ $export = $this->loader->getRespondentExport($this);
+ $form = $export->getForm();
+ $this->html->h2($this->_('Export respondent archive'));
+ $div = $this->html->div(array('id' => 'mainform'));
+ $div[] = $form;
+
+ $request = $this->getRequest();
+
+ $form->populate($request->getParams());
+
+ if ($request->isPost()) {
+ $export->render((array) $data['gr2o_patient_nr'], $this->getRequest()->getParam('group'), $this->getRequest()->getParam('format'));
+ }
+ }
+
+ /**
* Set column usage to use for the browser.
*
* Must be an array of arrays containing the input for TableBridge->setMultisort()
@@ -122,6 +281,25 @@
}
/**
+ * Get the link to edit respondent
+ *
+ * @return MUtil_Html_HrefArrayAttribute
+ */
+ public function getEditLink()
+ {
+ $request = $this->getRequest();
+
+ $item = $this->menu->find(array(
+ $request->getControllerKey() => $request->getControllerName(),
+ $request->getActionKey() => 'edit',
+ 'allowed' => true));
+
+ if ($item) {
+ return $item->toHRefAttribute($request);
+ }
+ }
+
+ /**
* Helper function to get the title for the index action.
*
* @return $string
@@ -132,6 +310,48 @@
}
/**
+ * Return the array with items that should be used to find this item
+ *
+ * @return array
+ */
+ public function getItemUrlArray()
+ {
+ return array(
+ MUtil_Model::REQUEST_ID1 => $this->_getParam(MUtil_Model::REQUEST_ID1),
+ MUtil_Model::REQUEST_ID2 => $this->_getParam(MUtil_Model::REQUEST_ID2)
+ );
+ }
+
+ /**
+ * Retrieve the respondent data in advance
+ * (So we don't need to repeat that for every snippet.)
+ *
+ * @return array
+ */
+ public function getRespondentData()
+ {
+ $model = $this->getModel();
+ $data = $model->applyRequest($this->getRequest(), true)->loadFirst();
+
+ if (! isset($data['grs_id_user'])) {
+ $this->addMessage(sprintf($this->_('Unknown %s requested'), $this->getTopic()));
+ $this->_reroute(array('action' => 'index'), true);
+ return array();
+ }
+
+ // Log
+ $this->openedRespondent($data['gr2o_patient_nr'], $data['gr2o_id_organization'], $data['grs_id_user']);
+
+ // Check for completed tokens
+ if ($this->loader->getTracker()->processCompletedTokens($data['grs_id_user'], $this->session->user_id, $data['gr2o_id_organization'])) {
+ //As data might have changed due to token events... reload
+ $data = $model->applyRequest($this->getRequest(), true)->loadFirst();
+ }
+
+ return $data;
+ }
+
+ /**
* Helper function to allow generalized statements about the items in the model.
*
* @param int $count
@@ -156,4 +376,26 @@
$this->addSnippet('Organization_ChooseOrganizationSnippet');
}
}
+
+ /**
+ * Log the respondent opening
+ *
+ * @param string $patientId
+ * @param int $orgId
+ * @param int $userId
+ * @return \Gems_Default_RespondentNewAction
+ */
+ protected function openedRespondent($patientId, $orgId = null, $userId = null)
+ {
+ if ($patientId) {
+ $where['gr2o_patient_nr = ?'] = $patientId;
+ $where['gr2o_id_organization = ?'] = $orgId ? $orgId : $this->escort->getCurrentOrganization();
+ $values['gr2o_opened'] = new MUtil_Db_Expr_CurrentTimestamp();
+ $values['gr2o_opened_by'] = $this->session->user_id;
+
+ $this->db->update('gems__respondent2org', $values, $where);
+ }
+
+ return $this;
+ }
}
Modified: trunk/library/classes/Gems/Menu.php
===================================================================
--- trunk/library/classes/Gems/Menu.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/Menu.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -137,7 +137,7 @@
$page->addAction(sprintf($this->_('About %s'), $project->getName()), null, 'about');
$page->addAction(sprintf($this->_('About %s'), $this->_('GemsTracker')), 'pr.contact.gems', 'gems');
-
+
if ($project->hasBugsUrl()) {
$page->addAction($this->_('Reporting bugs'), 'pr.contact.bugs', 'bugs');
}
@@ -518,7 +518,38 @@
}
/**
+ * Menulist populated with current items
*
+ * @param Zend_Controller_Request_Abstract $request
+ * @param $parentLabel
+ * @return Gems_Menu_MenuList
+ */
+ public function getCurrentMenuList(Zend_Controller_Request_Abstract $request, $parentLabel = null)
+ {
+ $controller = $request->getControllerName();
+ $action = $request->getActionName();
+
+ $menuList = $this->getMenuList();
+
+ if ($controller !== 'index') {
+ $menuList->addByController($controller, 'index', $parentLabel);
+ }
+
+ foreach ($this->getCurrentParent()->getChildren() as $child) {
+ if ($child instanceof Gems_Menu_SubMenuItem) {
+ $chAction = $child->get('action');
+ $chContr = $child->get('controller');
+ if (! ($controller == $chContr && $action == $chAction)) {
+ $menuList->addByController($chContr, $chAction);
+ }
+ }
+ }
+ return $menuList;
+ }
+
+
+ /**
+ *
* @return Gems_Menu_SubMenuItem
*/
public function getCurrentParent()
Modified: trunk/library/classes/Gems/Model/RespondentModel.php
===================================================================
--- trunk/library/classes/Gems/Model/RespondentModel.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/Model/RespondentModel.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -268,7 +268,7 @@
'tab', $translator->_('Contact information'));
$this->setIfExists('grs_address_1', 'label', $translator->_('Street'));
- $this->setIfExists('grs_address_2', 'label', $translator->_(' '));
+ $this->setIfExists('grs_address_2', 'label', ' ');
// MUtil_Echo::track($this->getItemsOrdered());
//MUtil_Echo::track($this->getItemsOrdered(), $this->getOrder('grs_email'));
Modified: trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php
===================================================================
--- trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -173,14 +173,9 @@
*/
protected function setShowTableFooter(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
{
- $controller = $this->request->getControllerName();
+ $menuList = $this->menu->getCurrentMenuList($this->request, $this->_('Cancel'));
+ $menuList->addParameterSources($bridge);
- $menuList = $this->menu->getMenuList();
- $menuList->addParameterSources($bridge)
- ->addByController($controller, 'index', $this->_('Cancel'))
- ->addByController($controller, 'edit')
- ->addByController($controller, 'delete');
-
$bridge->tfrow($menuList, array('class' => 'centerAlign'));
}
}
Modified: trunk/library/classes/Gems/Snippets/RespondentDetailSnippetAbstract.php
===================================================================
--- trunk/library/classes/Gems/Snippets/RespondentDetailSnippetAbstract.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/Snippets/RespondentDetailSnippetAbstract.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -102,6 +102,11 @@
{
if ($this->buttons) {
$bridge->tfrow($this->buttons, array('class' => 'centerAlign'));
+ } else {
+ $menuList = $this->menu->getCurrentMenuList($this->request, $this->_('Cancel'));
+ $menuList->addParameterSources($bridge);
+
+ $bridge->tfrow($menuList, array('class' => 'centerAlign'));
}
}
Modified: trunk/library/classes/Gems/TabForm.php
===================================================================
--- trunk/library/classes/Gems/TabForm.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/Gems/TabForm.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -112,7 +112,7 @@
$this->addToOtherGroup($element);
$element->removeDecorator('DtDdWrapper');
-
+
return $this;
}
@@ -127,15 +127,16 @@
$this->addToOtherGroup($element);
- $element->removeDecorator('DtDdWrapper');
-
if ($element instanceof Zend_Form_Element_Hidden) {
//Remove decorators
$element->removeDecorator('HtmlTag');
$element->removeDecorator('Label');
+ $element->removeDecorator('DtDdWrapper');
} elseif ($element instanceof Zend_Form_Element) {
+ $element->removeDecorator('DtDdWrapper');
+
$error = $element->getDecorator('Errors');
if ($error instanceof Zend_Form_Decorator_Errors) {
$element->removeDecorator('Errors');
Modified: trunk/library/classes/MUtil/Snippets/TabSnippetAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/TabSnippetAbstract.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/classes/MUtil/Snippets/TabSnippetAbstract.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -52,7 +52,7 @@
*
* @var array
*/
- protected $baseurl = array();
+ protected $baseUrl = array();
/**
* Shortfix to add class attribute
Modified: trunk/library/snippets/RespondentDetailsSnippet.php
===================================================================
--- trunk/library/snippets/RespondentDetailsSnippet.php 2013-03-12 20:13:10 UTC (rev 1174)
+++ trunk/library/snippets/RespondentDetailsSnippet.php 2013-03-13 15:48:13 UTC (rev 1175)
@@ -61,8 +61,10 @@
$br = $HTML->br();
$address[] = $bridge->grs_address_1;
$address[] = $br;
- $address[] = $bridge->grs_address_2;
- $address[] = $bridge->itemIf('grs_address_2', $br);
+ if ($this->model->has('grs_address_2')) {
+ $address[] = $bridge->grs_address_2;
+ $address[] = $bridge->itemIf('grs_address_2', $br);
+ }
$address[] = $bridge->grs_zipcode;
$address[] = $bridge->itemIf('grs_zipcode', new MUtil_Html_Raw(' '));
$address[] = $bridge->grs_city;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|