**/ class twIf_Generic_Multi_Selector extends twIf_Generic_Multi { const SELECTOR_CAPTION = 'Select an item'; const SELECTOR_SUBMIT = 'Show'; private $Selector = null; private $Items = array (); private $URL = null; // {{{ __construct /** * Create a new Interface to select an item assigned to all subclasses * * @param array $URL * @param string $Base * * @access friendly * @return void */ function __construct ($URL, $Base, $urlMode = self::MODE_URL) { // Set our base first $this->urlMode = $urlMode; $this->setBase ($Base); $this->URL = $URL; // Retrive the selected value $this->Selector = new twIf_Generic_Multi_Selector_Helper; try { $UUID = $this->getPageUUID (); if ((twIf_Widget_Object::saveObject ($this->Selector, $this->getFields ()) !== false) && $this->setItem ($this->Selector->ItemID)) return; } catch (Exception $e) { // Just ignore this } // Check if there is an item selected for this session if (isset ($_SESSION [$UUID . '_MultiSelectorID']) && isset ($this->Items [$_SESSION [$UUID . '_MultiSelectorID']]) && $this->setItem ($_SESSION [$UUID . '_MultiSelectorID'])) return; // Use the first item we can get foreach ($this->Items as $Key=>$First) if ($this->setItem ($Key)) break; } // }}} // {{{ assignClassItem /** * Assign an item for the selector * * @param string $Class * @param string $Key * @param string $Name * @param mixed $Handle (optional) * * @access protected * @return void **/ protected function assignClassItem ($Class, $Key, $Name, $Handle = null) { $this->Items [$Key] = array ($Class, $Name, $Handle); } // }}} // {{{ setItem /** * Set the current subitem * * @param string $Key * * @access public * @return bool **/ public function setItem ($Key, $URL = null) { // Check if the requested item is available if (!isset ($this->Items [$Key])) return false; if (!is_array ($URL)) $URL = $this->URL; // Remeber the current subitem $_SESSION [$this->getPageUUID () . '_MultiSelectorID'] = $Key; $this->Selector->ItemID = $Key; // Load the subclass $this->loadSubclass ($this->Items [$Key][0], $URL, $this->getBase (), false); return true; } // }}} // {{{ getItem /** * Retrive the Handle of the currently selected item * * @access public * @return mixed **/ public function getItem () { if (isset ($this->Items [$this->Selector->ItemID])) return $this->Items [$this->Selector->ItemID][2]; return false; } // }}} // {{{ getItems /** * Retrive a key/value-pair of all assigned items * * @access public * @return array **/ public function getItems () { $out = array (); foreach ($this->Items as $Key=>$Data) $out [$Key] = $Data [2]; return $out; } // }}} // {{{ getFields /** * Retrive the fields for the selector-widget * * @access protected * @return array **/ protected function getFields () { $Enum = array (); foreach ($this->Items as $ID=>$Data) $Enum [$ID] = $Data [1]; return array ( 'ItemID' => array ( 'Type' => twIf_Widget_Control::TYPE_ENUM, 'Caption' => $this->getSelectorCaption (), 'Level' => 0, 'Enum' => $Enum, ), ); } // }}} // {{{ getSelectorCaption /** * Retrive the caption for the object-selector * * @access protected * @return string **/ protected function getSelectorCaption () { return self::findConstant ('SELECTOR_CAPTION', self::SELECTOR_CAPTION); } // }}} // {{{ getSelectorButtonCaption /** * Retrive caption for the submit-button * * @access protected * @return string **/ protected function getSelectorButtonCaption () { return self::findConstant ('SELECTOR_SUBMIT', self::SELECTOR_SUBMIT); } // }}} // {{{ getDefinition /** * **/ public function getDefinition () { // Retrive the definition from our parent $Definition = parent::getDefinition (); $Interface = array_pop ($Definition); // Append the selector if (count ($this->Items) > 1) { $Enum = array (); foreach ($this->Items as $ID=>$Data) $Enum [$ID] = $Data [1]; $Definition [] = array ( 'Type' => 'Editor', 'Source' => $this->Selector, 'Mode' => 'Edit', 'Feedback' => false, 'Fields' => $this->getFields (), 'msgSubmit' => $this->getSelectorButtonCaption (), ); } $Definition [] = $Interface; return $Definition; } // }}} } ?>