/** * Visit a fixed organizer and return the GUI component [a container] * that corresponds to it. Traverse-to/add child components. * * @param object FixedOrganizerSiteComponent $organizer * @return object Component * @access public * @since 4/3/06 */ public function visitFixedOrganizer(FixedOrganizerSiteComponent $organizer) { $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $organizer->getQualifierId())) { $tdStyles = 'border: 1px solid #F00; padding: 6px;'; } else { $tdStyles = ''; } $guiContainer = new Container(new TableLayout($organizer->getNumColumns(), $tdStyles), BLANK, 1); // Add controls bar and border $authZ = Services::getService("AuthZ"); $idManager = Services::getService("Id"); if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $organizer->getQualifierId())) { $canAdd = true; } else { $canAdd = false; } $numCells = $organizer->getTotalNumberOfCells(); for ($i = 0; $i < $numCells; $i++) { $child = $organizer->getSubcomponentForCell($i); if (is_object($child)) { $childComponent = $child->acceptVisitor($this); if ($childComponent) { $guiContainer->add($childComponent, $child->getWidth(), null, null, TOP); } else { $childComponent = $guiContainer->add(new Blank(), $child->getWidth(), null, null, TOP); } } else { $this->_emptyCellContainers[$organizer->getId() . '_cell:' . $i] = $guiContainer; $this->_emptyCellPlaceholders[$organizer->getId() . '_cell:' . $i] = $guiContainer->addPlaceholder(); $childComponent = $guiContainer->getComponent($this->_emptyCellPlaceholders[$organizer->getId() . '_cell:' . $i]); } if ($canAdd) { $this->wrapAsDroppable($childComponent, $organizer->getId() . "_cell:" . $i, array_keys($organizer->getVisibleComponentsForPossibleAdditionToCell($i))); } } if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $organizer->getQualifierId())) { $controlsHTML = $this->getBarPreHTML('#F00', $organizer, '1px') . $this->getControlsHTML($organizer, $organizer->getDisplayName(), $organizer->acceptVisitor($this->_controlsVisitor), '#F00', '#F99', '#F66', 0, '1px'); $guiContainer->setPreHTML($controlsHTML . "\n<div style='z-index: 0;'>" . $guiContainer->getPreHTML($null = null)); $guiContainer->setPostHTML($guiContainer->getPostHTML($null = null) . "</div>" . $this->getBarPostHTML()); if (count($organizer->getVisibleDestinationsForPossibleAddition())) { $this->wrapAsDraggable($guiContainer, $organizer->getId(), 'FixedOrganizer'); } } return $guiContainer; }
function test_generic_container() { $comp = new Container(new FlowLayout(), MENU, 5); $c = new Component("Hello!", FOOTER, 4); $c1 = $comp->add($c, "12px", "2em", LEFT, BOTTOM); $this->assertReference($c1, $c); $this->assertReference($comp->getComponent(1), $c); $this->assertIdentical($comp->getComponentWidth(1), "12px"); $this->assertIdentical($comp->getComponentHeight(1), "2em"); $this->assertIdentical($comp->getComponentAlignmentX(1), LEFT); $this->assertIdentical($comp->getComponentAlignmentY(1), BOTTOM); $this->assertIdentical($comp->getComponentsCount(), 1); $c = new Component("Hello!", MENU_ITEM_LINK_SELECTED, 2); $c2 = $comp->add($c, "16px", "6em", RIGHT, CENTER); $this->assertReference($c2, $c); $this->assertReference($comp->getComponent(2), $c); $this->assertIdentical($comp->getComponentsCount(), 2); $c = new Component("Hello!", MENU_ITEM_LINK_UNSELECTED, 5); $c3 = $comp->add($c, "6px", "2em", CENTER, TOP); $this->assertReference($c3, $c); $this->assertReference($comp->getComponent(3), $c); $this->assertIdentical($comp->getComponentsCount(), 3); $c = $comp->remove(2); $this->assertReference($c, $c2); $this->assertNull($comp->getComponent(2)); $this->assertIdentical($comp->getComponentsCount(), 2); $comp->removeAll(); $this->assertIdentical($comp->_components, array()); $this->assertIdentical($comp->getComponentsCount(), 0); }