Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Can now provide a site-wide header block.

The header block on individual sites can list the site owners as contacts.
  • Loading branch information...
commit ff8ddef081120f9ffda5762dba37aef6b3700a26 1 parent c27b844
Adam Franco authored
65 main/library/Roles/SegueRoleManager.class.php
@@ -484,6 +484,71 @@ public function getAgentsWithRoleAtLeast (SegueRole $role, Id $rootQualifierId,
484 484 }
485 485
486 486 /**
  487 + * Answer the agents that have roles that are greater than or equal to the role passed.
  488 + *
  489 + * @param object SegueRole $role
  490 + * @param object Id $rootQualifierId
  491 + * @param optional boolean $overrideAzCheck If true, not not check AZs. Used by admin functions to force-set a role.
  492 + * @return array An array of Id objects
  493 + * @access public
  494 + * @since 11/29/07
  495 + */
  496 + public function getAgentsWithExplicitRoleAtLeast (SegueRole $role, Id $rootQualifierId, $overrideAzCheck = false) {
  497 + $authZ = Services::getService("AuthZ");
  498 + $idMgr = Services::getService("Id");
  499 +
  500 + if (!$overrideAzCheck) {
  501 + if (!$authZ->isUserAuthorized(
  502 + $idMgr->getId("edu.middlebury.authorization.view_authorizations"),
  503 + $rootQualifierId))
  504 + throw new PermissionDeniedException("Cannot view authorizations here.");
  505 + }
  506 +
  507 + $qualifier = $authZ->getQualifier($rootQualifierId);
  508 +
  509 + // Go through each qualifier and see who can do all of the functions in the role
  510 + $agentIdStrings = array();
  511 + $qualifierId = $qualifier->getId();
  512 +
  513 + // Build up an array of what agents can do each function
  514 + $agentsForFunctions = array();
  515 + foreach ($role->getFunctions() as $functionId) {
  516 + $agentsForFunctions[$functionId->getIdString()] = array();
  517 + $explicitAZs = $authZ->getExplicitAZs(null, $functionId, $qualifierId);
  518 + while ($explicitAZs->hasNext()) {
  519 + $explicitAZ = $explicitAZs->next();
  520 + $agentIdString = $explicitAZ->getAgentId()->getIdString();
  521 + if (!in_array($agentIdString, $agentIdStrings))
  522 + $agentsForFunctions[$functionId->getIdString()][] = $agentIdString;
  523 + }
  524 + }
  525 +
  526 + // Loop through the agents that can do the first function, if they can
  527 + // do all the others, then they match the role and can be added to the master list.
  528 + foreach (current($agentsForFunctions) as $agentIdString) {
  529 + $hasAllFunctions = true;
  530 + foreach ($role->getFunctions() as $functionId) {
  531 + if (!in_array($agentIdString, $agentsForFunctions[$functionId->getIdString()])) {
  532 + $hasAllFunctions = false;
  533 + break;
  534 + }
  535 + }
  536 +
  537 + if ($hasAllFunctions)
  538 + $agentIdStrings[] = $agentIdString;
  539 + }
  540 +
  541 + $agentIdStrings = array_unique($agentIdStrings);
  542 +
  543 + $agentIds = array();
  544 + foreach ($agentIdStrings as $idString) {
  545 + $agentIds[] = $idMgr->getId($idString);
  546 + }
  547 +
  548 + return $agentIds;
  549 + }
  550 +
  551 + /**
487 552 * Answer true if the authorization is an implicit view AZ cascading up from
488 553 * a descendent and should hence be ignored when determining roles.
489 554 *
35 main/modules/view/html.act.php
@@ -267,6 +267,11 @@ public function addHeaderControls (Component $mainScreen) {
267 267
268 268 $allWrapper = new Container(new YLayout, BLANK, 1);
269 269
  270 + if (defined('SEGUE_SITE_HEADER')) {
  271 + $this->siteMessage = $allWrapper->add(
  272 + new Component($this->getSegueSiteHeader(), BLANK, 1),
  273 + "100%", null, CENTER, TOP);
  274 + }
270 275
271 276 // :: login, links and commands
272 277 $this->headRow = $allWrapper->add(
@@ -596,6 +601,36 @@ protected function getExportControls () {
596 601 return '';
597 602 }
598 603 }
  604 +
  605 + /**
  606 + * Answer the site-wide header customized for this site.
  607 + *
  608 + * @return string
  609 + */
  610 + public function getSegueSiteHeader () {
  611 + if (!defined('SITE_OWNER_MESSAGE') || !$this->isAuthorizedToExecute())
  612 + return str_replace('[[SITE_OWNER_MESSAGE]]', '', SEGUE_SITE_HEADER);
  613 +
  614 + // Build the owner list.
  615 + $admins = array();
  616 + $roleMgr = SegueRoleManager::instance();
  617 + $adminIds = $roleMgr->getAgentsWithExplicitRoleAtLeast($roleMgr->getRole('editor'), SiteDispatcher::getCurrentRootNode()->getQualifierId(), true);
  618 + $adminstratorsGroupId = new HarmoniId('1');
  619 + $agentMgr = Services::getService('Agent');
  620 + foreach ($adminIds as $adminId) {
  621 + if (!$adminId->isEqual($adminstratorsGroupId))
  622 + $admins[] = $agentMgr->getAgent($adminId)->getDisplayName();
  623 + }
  624 +
  625 + if (count($admins) <= 2) {
  626 + $adminString = implode(' and ', $admins);
  627 + } else {
  628 + $admins[count($admins) - 1] = 'and '.$admins[count($admins) - 1];
  629 + $adminString = implode(', ', $admins);
  630 + }
  631 +
  632 + return str_replace('[[SITE_OWNER_MESSAGE]]', str_replace('[[SITE_OWNERS]]', $adminString, SITE_OWNER_MESSAGE), SEGUE_SITE_HEADER);
  633 + }
599 634 }
600 635
601 636 /**
6 main/modules/window/display.act.php
@@ -64,6 +64,12 @@ function execute () {
64 64
65 65
66 66 $mainScreen = new Container($yLayout, BLANK, 1);
  67 +
  68 + if (defined('SEGUE_SITE_HEADER')) {
  69 + $this->siteMessage = $mainScreen->add(
  70 + new Component(str_replace('[[SITE_OWNER_MESSAGE]]', '', SEGUE_SITE_HEADER), BLANK, 1),
  71 + "100%", null, CENTER, TOP);
  72 + }
67 73
68 74 // :: login, links and commands
69 75 $this->headRow = $mainScreen->add(

0 comments on commit ff8ddef

Please sign in to comment.
Something went wrong with that request. Please try again.