From: <gem...@li...> - 2012-02-21 18:06:41
|
Revision: 506 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=506&view=rev Author: matijsdejong Date: 2012-02-21 18:06:31 +0000 (Tue, 21 Feb 2012) Log Message: ----------- Simplified finding menu items through controller / action SubMenuItems can be sorted in their display order Added functions for respondent login Added renderClosingTag to HtmlElement.php Modified Paths: -------------- trunk/library/classes/Gems/Default/MailJobAction.php trunk/library/classes/Gems/Menu/MenuAbstract.php trunk/library/classes/Gems/Menu.php trunk/library/classes/Gems/Model/RespondentModel.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/RespondentUserDefinition.php trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/User/UserDefinitionAbstract.php trunk/library/classes/Gems/User/UserDefinitionInterface.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Html/HtmlElement.php Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2012-02-21 18:06:31 UTC (rev 506) @@ -189,7 +189,7 @@ $this->addMessage(sprintf($this->_('Automatic mails have been turned off since %s.'), $lock->getLockTime())); $request = $this->getRequest(); - if ($menuItem = $this->menu->findFirst(array($request->getControllerKey() => 'cron', $request->getActionKey() => 'cron-lock'))) { + if ($menuItem = $this->menu->findController('cron', 'cron-lock')) { $menuItem->set('label', $this->_('Turn Automatic Mail Jobs ON')); } } Modified: trunk/library/classes/Gems/Menu/MenuAbstract.php =================================================================== --- trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Menu/MenuAbstract.php 2012-02-21 18:06:31 UTC (rev 506) @@ -48,6 +48,10 @@ */ abstract class Gems_Menu_MenuAbstract { + /** + * + * @var GemsEscort + */ public $escort; protected $_subItems; @@ -597,4 +601,37 @@ } return $this; } + + /** + * Sorts the childeren on their order attribute (instead of the order the were added) + * + * @return Gems_Menu_MenuAbstract (continuation pattern) + */ + public function sortByOrder() + { + uasort($this->_subItems, array(__CLASS__, 'sortOrder')); + + return $this; + } + + /** + * uasort() function for sortByOrder() + * + * @see sortByOrder(); + * + * @param self $aItem + * @param self $bItem + * @return int + */ + public static function sortOrder($aItem, $bItem) + { + $a = $aItem->get('order'); + $b = $bItem->get('order'); + + if ($a == $b) { + return 0; + } + + return $a > $b ? 1 : -1; + } } Modified: trunk/library/classes/Gems/Menu.php =================================================================== --- trunk/library/classes/Gems/Menu.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Menu.php 2012-02-21 18:06:31 UTC (rev 506) @@ -417,6 +417,18 @@ } } + /** + * Find a menu item through specifying the controller and action + * + * @param string $controller + * @param string $action + * @return Gems_SubMenuItem + */ + public function findController($controller, $action = 'index') + { + return $this->findItem(array('controller' => $controller, 'action' => $action), false); + } + public function findFirst($request) { $find = $this->request2find($request); Modified: trunk/library/classes/Gems/Model/RespondentModel.php =================================================================== --- trunk/library/classes/Gems/Model/RespondentModel.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/Model/RespondentModel.php 2012-02-21 18:06:31 UTC (rev 506) @@ -116,6 +116,19 @@ } /** + * Add the table and field to check for respondent login checks + * + * @return Gems_Model_RespondentModel (continuation pattern) + */ + public function addLoginCheck() + { + $this->addLeftTable('gems__user_logins', array('gr2o_patient_nr' => 'gul_login', 'gr2o_id_organization' => 'gul_id_organization'), 'gul'); + $this->addColumn('CASE WHEN gul_id_user IS NULL THEN 0 ELSE 1 END', 'has_login'); + + return $this; + } + + /** * Apply hash function for array_walk_recursive in _checkFilterUsed() * * @see _checkFilterUsed() Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/Organization.php 2012-02-21 18:06:31 UTC (rev 506) @@ -77,6 +77,16 @@ protected $db; /** + * When true respondents of this organization may login + * + * @return boolean + */ + public function allowsRespondentLogin() + { + return (boolean) $this->_get('gor_respondent_group') && $this->canHaveRespondents(); + } + + /** * Set menu parameters from the organization * * @param Gems_Menu_ParameterSource $source @@ -106,10 +116,10 @@ { return (boolean) $this->_get('gor_has_respondents') || $this->_get('gor_add_respondents'); } - + /** * Returns the $key in organizationData when set otherwise the default value - * + * * @param string $key * @param mixed $default * @return mixed Modified: trunk/library/classes/Gems/User/RespondentUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/RespondentUserDefinition.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/RespondentUserDefinition.php 2012-02-21 18:06:31 UTC (rev 506) @@ -91,4 +91,16 @@ return $select; } + + /** + * Returns true when users using this definition are staff members. + * + * Used only when the definition does not return a user_staff field. + * + * @return boolean + */ + public function isStaff() + { + return false; + } } \ No newline at end of file Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/User.php 2012-02-21 18:06:31 UTC (rev 506) @@ -107,6 +107,12 @@ protected $userLoader; /** + * + * @var Gems_Util + */ + protected $util; + + /** * Creates the class for this user. * * @param mixed $settings Array, Zend_Session_Namespace or ArrayObject for this user. @@ -448,6 +454,38 @@ } /** + * Returns a standard greeting for the current user. + * + * @return int + */ + public function getGreeting() + { + if (! $this->_getVar('user_greeting')) { + $greeting = array(); + $greetings = $this->util->getTranslated()->getGenderGreeting(); + + if (isset($greetings[$this->_getVar('user_gender')])) { + $greeting[] = $greetings[$this->_getVar('user_gender')]; + } + if ($this->_getVar('user_last_name')) { + if ($this->_getVar('user_surname_prefix')) { + $greeting[] = $this->_getVar('user_surname_prefix'); + } + $greeting[] = $this->_getVar('user_last_name'); + } else { + $name = $this->getLoginName(); + $name = substr($name, 0, 3) . str_repeat('*', strlen($name) - 2); + $greeting[] = $name; + } + + $this->_setVar('user_greeting', implode(' ', $greeting)); + } + + return $this->_getVar('user_greeting'); + } + + + /** * Returns the group number of the current user. * * @return int @@ -552,7 +590,7 @@ // Set menu OFF $menu->setVisible(false); - $menuItem = $menu->findFirst(array($request->getControllerKey() => 'option', $request->getActionKey() => 'change-password')); + $menuItem = $menu->findController('option', 'change-password'); // This may not yet be true, but is needed for the redirect. $menuItem->set('allowed', true); $menuItem->set('visible', true); @@ -563,6 +601,8 @@ if ($menuItem) { // Prevent redirecting to the current page. if (! ($menuItem->is('controller', $request->getControllerName()) && $menuItem->is('action', $request->getActionName()))) { + echo $menuItem->get('label') . '<br/>'; + $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoRoute($menuItem->toRouteUrl($request), null, true); } @@ -655,6 +695,16 @@ } /** + * Returns true when this user is a staff member. + * + * @return boolean + */ + public function isStaff() + { + return (boolean) $this->_getVar('user_staff'); + } + + /** * Allowes a refresh of the existing list of organizations * for this user. * Modified: trunk/library/classes/Gems/User/UserDefinitionAbstract.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/UserDefinitionAbstract.php 2012-02-21 18:06:31 UTC (rev 506) @@ -100,6 +100,18 @@ } /** + * Returns true when users using this definition are staff members. + * + * Used only when the definition does not return a user_staff field. + * + * @return boolean + */ + public function isStaff() + { + return true; + } + + /** * Return true if the user has a password. * * @param Gems_User_User $user The user to check Modified: trunk/library/classes/Gems/User/UserDefinitionInterface.php =================================================================== --- trunk/library/classes/Gems/User/UserDefinitionInterface.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/UserDefinitionInterface.php 2012-02-21 18:06:31 UTC (rev 506) @@ -102,6 +102,15 @@ public function getUserData($login_name, $organization); /** + * Returns true when users using this definition are staff members. + * + * Used only when the definition does not return a user_staff field. + * + * @return boolean + */ + public function isStaff(); + + /** * Return true if the user has a password. * * @param Gems_User_User $user The user to check Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/Gems/User/UserLoader.php 2012-02-21 18:06:31 UTC (rev 506) @@ -232,6 +232,9 @@ if (! isset($values['user_active'])) { $values['user_active'] = true; } + if (! isset($values['user_staff'])) { + $values['user_staff'] = $definition->isStaff(); + } $values['__user_definition'] = $defName; Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/GemsEscort.php 2012-02-21 18:06:31 UTC (rev 506) @@ -741,10 +741,10 @@ $p = $div->p(); if ($user->isActive()) { $p->append(sprintf($this->_('You are logged in as %s'), $user->getFullName())); - $item = $this->menu->findFirst(array($this->request->getControllerKey() => 'index', $this->request->getActionKey() => 'logoff')); + $item = $this->menu->findController('index', 'logoff'); $p->a($item->toHRefAttribute(), $this->_('Logoff'), array('class' => 'logout')); } else { - $item = $this->menu->findFirst(array($this->request->getControllerKey() => 'index', $this->request->getActionKey() => 'login')); + $item = $this->menu->findController('index', 'login'); $p->a($item->toHRefAttribute(), $this->_('You are not logged in'), array('class' => 'logout')); } $item->set('visible', false); @@ -947,7 +947,7 @@ $div = MUtil_Html::create()->div($args, array('id' => 'version')); $version = $this->loader->getVersions()->getVersion(); if (($this->menu instanceof Gems_Menu) && - ($item = $this->menu->findFirst(array('controller'=>'project-information', 'action'=>'changelog'))->toHRefAttribute())) { + ($item = $this->menu->findController('project-information', 'changelog')->toHRefAttribute())) { $link = MUtil_Html::create()->a($version, $item); } else { $link = $version; Modified: trunk/library/classes/MUtil/Html/HtmlElement.php =================================================================== --- trunk/library/classes/MUtil/Html/HtmlElement.php 2012-02-21 15:08:06 UTC (rev 505) +++ trunk/library/classes/MUtil/Html/HtmlElement.php 2012-02-21 18:06:31 UTC (rev 506) @@ -504,6 +504,19 @@ ); /** + * Some elements, e.g. iframe elements, must always be rendered with a closing + * tag because otherwise some poor browsers get confused. + * + * Overrules $renderWithoutContent: the element is always rendered when + * $renderClosingTag is true. + * + * @see $renderWithoutContent + * + * @var boolean The element is always rendered with a closing tag. + */ + public $renderClosingTag = false; + + /** * Most elements must be rendered even when empty, others should - according to the * xhtml specifications - only be rendered when the element contains some content. * @@ -1071,7 +1084,7 @@ $content = $this->renderContent($view); $has_content = (null !== $content); - if ($has_content || $this->renderWithoutContent) { + if ($has_content || $this->renderWithoutContent || $this->renderClosingTag) { $html = '<' . $this->tagName; @@ -1079,7 +1092,7 @@ $html .= $this->_htmlAttribs($this->_renderAttributes($view)); } - if ($has_content) { + if ($has_content || $this->renderClosingTag) { $html .= '>'; $html .= $content; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |