name = $name; $this->title = $name; } /** * Returns the name of this pane * * @return string */ public function getName() { return $this->name; } /** * Returns the title of this pane * * @return string */ public function getTitle() { return $this->title; } /** * Overwrite the title of this pane * * @param string $title The new title to use for this pane * * @return self */ public function setTitle($title) { $this->title = $title; return $this; } /** * Return true if a component with the given title exists in this pane * * @param string $id The id of the component to check for existence * * @return bool */ public function hasComponent($id) { return array_key_exists($id, $this->components); } /** * Return a component with the given name if existing * * @param string $id The id of the component to return * * @return Component The component with the given title * @throws ProgrammingError If the component doesn't exist */ public function getComponent($id) { if ($this->hasComponent($id)) { return $this->components[$id]; } throw new ProgrammingError( 'Trying to access invalid component: %s', $id ); } /** * Removes the component with the given id if it exists in this pane * * @param string $id The pane * @return Pane $this */ public function removeComponent($id) { if ($this->hasComponent($id)) { unset($this->components[$id]); } return $this; } /** * Return all components added at this pane * * @return array */ public function getComponents() { return $this->components; } /** * @see Widget::render */ public function render() { return implode("\n", $this->components) . "\n"; } /** * Add a component to this pane, optionally creating it if $component is a string * * @param string $id An unique Identifier * @param string|Component $component The component object or title * (if a new component will be created) * @param string|null $url An Url to be used when component is a string * * @return self * @throws \Icinga\Exception\ConfigurationError */ public function addComponent($id, $component, $url = null) { if ($component instanceof Component) { $this->components[$component->getId()] = $component; } elseif (is_string($id) && is_string($component) && $url !== null) { $this->components[$id] = new Component($id, $component, $url, $this); } else { throw new ConfigurationError('Invalid component added: %s', $component); } return $this; } /** * Add new components to existing components * * @param array $components * @return $this */ public function addComponents(array $components) { /* @var $component Component */ foreach ($components as $component) { if (array_key_exists($component->getId(), $this->components)) { if (preg_match('/-(\d+)$/', $component->getId(), $m)) { $name = preg_replace('/-\d+$/', $m[1]++, $component->getId()); } else { $name = $component->getId() . '-2'; } $this->components[$name] = $component; } else { $this->components[$component->getId()] = $component; } } return $this; } /** * Add a component to the current pane * * @param $id * @param $title * @param null $url * @return mixed * * @see addComponent() */ public function add($id, $title, $url = null) { $this->addComponent($id, $title, $url); return $this->components[$id]; } /** * Return the this pane's structure as array * * @return array */ public function toArray() { $array = array($this->getName() => array('title' => $this->getTitle())); foreach ($this->components as $title => $component) { $array[$this->getName() . ".$title"] = $component->toArray(); } return $array; } /** * Create a new pane with the title $title from the given configuration * * @param $title The title for this pane * @param Zend_Config $config The configuration to use for setup * * @return Pane */ public static function fromIni($title, Zend_Config $config) { $pane = new Pane($title); if ($config->get('title', false)) { $pane->setTitle($config->get('title')); } return $pane; } }