From: <gem...@li...> - 2012-06-21 14:57:22
|
Revision: 779 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=779&view=rev Author: matijsdejong Date: 2012-06-21 14:57:13 +0000 (Thu, 21 Jun 2012) Log Message: ----------- Refined use of multiple organizations - organizations switches cause less errors - fixed bug in respondent save - organization is displayed when user has multi org - multi org right means always show multi org browse (correctable) Modified Paths: -------------- trunk/library/changelog.txt trunk/library/classes/Gems/Default/RespondentAction.php trunk/library/classes/Gems/Model/RespondentModel.php trunk/library/classes/Gems/Model.php trunk/library/classes/GemsEscort.php Modified: trunk/library/changelog.txt =================================================================== --- trunk/library/changelog.txt 2012-06-21 12:21:32 UTC (rev 778) +++ trunk/library/changelog.txt 2012-06-21 14:57:13 UTC (rev 779) @@ -2,7 +2,7 @@ ============================================================ Internally code no longer uses the 'Hidden Organization' but expects both an id1/patientNr plus an id2/organizationId to be specified Externally the organization id is still left out of the url when not needed -Check all your (snippet) extensions to RespondentAction and project specific versions of ShowTrackTokenSnippet and ShowSingleSurveySnippet: you may need to specify extra parameters as the menu items need to know the organization id +UPGRADE WARNING: Check all your (snippet) extensions to RespondentAction and project specific versions of ShowTrackTokenSnippet and ShowSingleSurveySnippet: you may need to specify extra parameters as the menu items need to know the organization id Important changes from 1.5.3 => 1.5.4 ============================================================ Modified: trunk/library/classes/Gems/Default/RespondentAction.php =================================================================== --- trunk/library/classes/Gems/Default/RespondentAction.php 2012-06-21 12:21:32 UTC (rev 778) +++ trunk/library/classes/Gems/Default/RespondentAction.php 2012-06-21 14:57:13 UTC (rev 779) @@ -120,7 +120,11 @@ $phonesep = $bridge->itemIf($bridge->grs_phone_1, MUtil_Html::raw('☏ ')); $citysep = $bridge->itemIf($bridge->grs_zipcode, MUtil_Html::raw(' ')); - $bridge->addMultiSort('gr2o_patient_nr', $br, 'gr2o_opened'); + if ($this->loader->getCurrentUser()->hasPrivilege('pr.respondent.multiorg')) { + $bridge->addMultiSort('gr2o_patient_nr', $br, 'gor_name'); //, MUtil_Html::raw(' '), 'gr2o_opened'); + } else { + $bridge->addMultiSort('gr2o_patient_nr', $br, 'gr2o_opened'); + } $bridge->addMultiSort('name', $br, 'grs_email'); $bridge->addMultiSort('grs_address_1', $br, 'grs_zipcode', $citysep, 'grs_city'); $bridge->addMultiSort('grs_birthday', $br, $phonesep, 'grs_phone_1'); @@ -153,19 +157,21 @@ } $model->set('grs_ssn', 'description', sprintf($this->_('Random Example BSN: %s'), $num)); - } else { $model->set('grs_ssn', 'description', $this->_('Enter a 9-digit SSN number.')); } $ucfirst = new Zend_Filter_Callback('ucfirst'); + // MUtil_Echo::track($data); + $bridge->addTab( 'caption1')->h4($this->_('Identification')); //Add the hidden fields after the tab, so validation will work. They need to be in the //same tab where they are needed $bridge->addHidden( 'grs_id_user'); $bridge->addHidden( 'gr2o_id_organization'); $bridge->addHidden( $model->getKeyCopyName('gr2o_patient_nr')); + $bridge->addHidden( $model->getKeyCopyName('gr2o_id_organization')); $bridge->addText( 'grs_ssn', 'label', $this->_('SSN'), 'size', 10, 'maxlength', 12) ->addValidator( new MUtil_Validate_Dutch_Burgerservicenummer()) @@ -344,15 +350,46 @@ } /** + * Returns a text element for autosearch. Can be overruled. + * + * The form / html elements to search on. Elements can be grouped by inserting null's between them. + * That creates a distinct group of elements + * + * @param MUtil_Model_ModelAbstract $model + * @param array $data The $form field values (can be usefull, but no need to set them) + * @return array Of Zend_Form_Element's or static tekst to add to the html or null for group breaks. + */ + protected function getAutoSearchElements(MUtil_Model_ModelAbstract $model, array $data) + { + $elements = parent::getAutoSearchElements($model, $data); + + if ($model->isMultiOrganization()) { + $availableOrganizations = $this->util->getDbLookup()->getOrganizationsWithRespondents(); + $allowedOrganizations = $this->loader->getCurrentUser()->getAllowedOrganizations(); + + $options = array_intersect($availableOrganizations, $allowedOrganizations); + + $elements[] = $this->_createSelectElement(MUtil_Model::REQUEST_ID2, $options, $this->_('(all organizations)')); + } + + return $elements; + } + + /** * Returns the currently used organization * + * @param int $default Optional default value * @return int An organization id */ - protected function getOrganizationId() + protected function getOrganizationId($default = null) { - if ($orgId = $this->_getParam(MUtil_Model::REQUEST_ID2)) { + if ($orgId = $this->_getParam(MUtil_Model::REQUEST_ID2, $default)) { return $orgId; } + $data = $this->getCachedRequestData(false); + if (isset($data[MUtil_Model::REQUEST_ID2])) { + return $data[MUtil_Model::REQUEST_ID2]; + } return $this->loader->getCurrentUser()->getCurrentOrganizationId(); } @@ -361,10 +398,10 @@ { switch ($name) { case 'gr2o_patient_nr': - return $this->_getParam(MUtil_Model::REQUEST_ID, $this->_getParam(MUtil_Model::REQUEST_ID1, $default)); + return $this->_getParam(MUtil_Model::REQUEST_ID1, $default); case 'gr2o_id_organization': - return $this->_getParam(MUtil_Model::REQUEST_ID2, $default ? $default : $this->loader->getCurrentUser()->getCurrentOrganizationId()); + return $this->getOrganizationId($default); case 'gto_id_token': return null; @@ -397,7 +434,7 @@ { $user = $this->loader->getCurrentUser(); - if ($user->hasPrivilege('pr.respondent.multiorg') || $this->loader->getOrganization()->canHaveRespondents()) { + if ($user->hasPrivilege('pr.respondent.multiorg') || $user->getCurrentOrganization()->canHaveRespondents()) { parent::indexAction(); } else { $this->addSnippet('Organization_ChooseOrganizationSnippet'); @@ -482,7 +519,7 @@ } $params['model'] = $model; - $params['baseUrl'] = array(MUtil_Model::REQUEST_ID => $this->_getParam(MUtil_Model::REQUEST_ID)); + $params['baseUrl'] = array(MUtil_Model::REQUEST_ID1 => $this->_getParam(MUtil_Model::REQUEST_ID1), MUtil_Model::REQUEST_ID2 => $this->_getParam(MUtil_Model::REQUEST_ID2)); $params['buttons'] = $this->createMenuLinks(); $params['onclick'] = $this->findAllowedMenuItem('edit'); if ($params['onclick']) { Modified: trunk/library/classes/Gems/Model/RespondentModel.php =================================================================== --- trunk/library/classes/Gems/Model/RespondentModel.php 2012-06-21 12:21:32 UTC (rev 778) +++ trunk/library/classes/Gems/Model/RespondentModel.php 2012-06-21 14:57:13 UTC (rev 779) @@ -104,7 +104,7 @@ $filter = parent::_checkFilterUsed($filter); if (! isset($filter['gr2o_id_organization'])) { - if ($this->user->hasPrivilege('pr.respondent.multiorg') && (! $this->user->getCurrentOrganization()->canHaveRespondents())) { + if ($this->isMultiOrganization()) { $filter[] = 'gr2o_id_organization IN (' . implode(', ', array_keys($this->user->getAllowedOrganizations())) . ')'; } else { $filter['gr2o_id_organization'] = $this->getCurrentOrganization(); @@ -126,7 +126,7 @@ */ public function addLoginCheck() { - $this->addLeftTable('gems__user_logins', array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), 'gul'); + $this->addLeftTable('gems__user_logins', array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), 'gul', false); $this->addColumn("CASE WHEN gul_id_user IS NULL OR gul_user_class = 'NoLogin' OR gul_can_login = 0 THEN 0 ELSE 1 END", 'has_login'); return $this; @@ -166,9 +166,10 @@ public function copyKeys($reset = false) { $keys = $this->_getKeysFor('gems__respondent2org'); - $key = reset($keys); - $this->addColumn('gems__respondent2org.' . $key, $this->getKeyCopyName($key)); + foreach ($keys as $key) { + $this->addColumn('gems__respondent2org.' . $key, $this->getKeyCopyName($key)); + } return $this; } @@ -182,17 +183,15 @@ return $model; } - public function save(array $newValues, array $filter = null, array $saveTables = null) + /** + * True when the default filter can contain multiple organizations + * + * @return boolean + */ + public function isMultiOrganization() { - if ((null === $filter) || (! array_key_exists('gr2o_id_organization', $filter))) { - $filter['gr2o_id_organization'] = $this->getCurrentOrganization(); - } - - if (! (isset($newValues['gr2o_id_organization']) && $newValues['gr2o_id_organization'])) { - $newValues['gr2o_id_organization'] = $filter['gr2o_id_organization']; - } - - return parent::save($newValues, $filter, $saveTables); + // return ($this->user->hasPrivilege('pr.respondent.multiorg') && (! $this->user->getCurrentOrganization()->canHaveRespondents())); + return $this->user->hasPrivilege('pr.respondent.multiorg'); } } Modified: trunk/library/classes/Gems/Model.php =================================================================== --- trunk/library/classes/Gems/Model.php 2012-06-21 12:21:32 UTC (rev 778) +++ trunk/library/classes/Gems/Model.php 2012-06-21 14:57:13 UTC (rev 779) @@ -204,6 +204,10 @@ $translated = $this->util->getTranslated(); $model->setIfExists('gr2o_patient_nr', 'label', $this->translate->_('Respondent nr')); + if ((! $detailed) && $model->isMultiOrganization()) { + $model->addTable('gems__organizations', array('gr2o_id_organization' => 'gor_id_organization')); + $model->setIfExists('gor_name', 'label', $this->translate->_('Organization')); + } $model->setIfExists('gr2o_opened', 'label', $this->translate->_('Opened'), 'formatFunction', $translated->formatDateTime); $model->setIfExists('gr2o_consent', 'label', $this->translate->_('Consent'), 'multiOptions', MUtil_Lazy::call($this->util->getDbLookup()->getUserConsents), 'default', $this->util->getDefaultConsent()); Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-06-21 12:21:32 UTC (rev 778) +++ trunk/library/classes/GemsEscort.php 2012-06-21 14:57:13 UTC (rev 779) @@ -875,12 +875,14 @@ // Organization switcher $orgSwitch = MUtil_Html::create('div', array('id' => 'organizations')); $currentId = $user->getCurrentOrganizationId(); - $currentUri = base64_encode($this->view->url()); + $params = $this->request->getParams(); + unset($params[Gems_Util_RequestCache::RESET_PARAM]); + $currentUri = $this->view->url($params, null, true); - $url = $this->view->getHelper('url')->url(array('controller' => 'organization', 'action' => 'change-ui'), null, true); + $url = $this->view->url(array('controller' => 'organization', 'action' => 'change-ui'), null, true); $formDiv = $orgSwitch->form(array('method' => 'get', 'action' => $url))->div(); - $formDiv->input(array('type' => "hidden", 'name' => "current_uri", 'value' => $currentUri)); + $formDiv->input(array('type' => "hidden", 'name' => "current_uri", 'value' => base64_encode($currentUri))); $select = $formDiv->select(array('name' => "org", 'onchange' => "javascript:this.form.submit();")); foreach ($orgs as $id => $org) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |