![]() |
Xataface 2.0
Xataface Application Framework
|
00001 <?php 00002 /*------------------------------------------------------------------------------- 00003 * Xataface Web Application Framework 00004 * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca) 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 *------------------------------------------------------------------------------- 00020 */ 00021 /******************************************************************************* 00022 * File: Dataface/Vocabulary.php 00023 * Author: Steve Hannah <shannah@sfu.ca> 00024 * Created: Sept. 2, 2005 00025 * Description: 00026 * Encapsulates vocabularies that can be used in select lists and auto complete widgets 00027 * to limit the input to a field. 00028 ******************************************************************************/ 00029 00030 class Dataface_Vocabulary { 00031 00032 var $_options = array(); 00033 var $_name; 00034 function Dataface_Vocabulary($name,$options){ 00035 $this->_name = $name; 00036 $this->_options = $options; 00037 } 00038 00039 00043 public static function &getVocabulary($name){ 00044 $vocabularies =& Dataface_Vocabulary::getVocabularies(); 00045 00046 if ( !isset( $vocabularies[$name] ) ){ 00047 $vocabularies[$name] = new Dataface_Vocabulary($name, array()); 00048 } 00049 00050 00051 return $vocabularies[$name]; 00052 } 00053 00054 00055 public static function &getVocabularies(){ 00056 if ( !isset( $vocabularies ) ){ 00057 static $vocabularies = array(); 00058 } 00059 return $vocabularies; 00060 } 00061 00062 function register($name, $vocab){ 00063 $vocabs =& Dataface_Vocabulary::getVocabularies(); 00064 00065 if ( is_array($vocab) ){ 00066 $vocab = new Dataface_Vocabulary($name, $vocab); 00067 } 00068 00069 $vocabs[$name] =& $vocab; 00070 } 00071 00072 00073 00074 function &options(){ 00075 return $this->_options; 00076 } 00077 00078 function setOptions($options){ 00079 $this->_options = $options; 00080 } 00081 00082 function addOption($key,$value=''){ 00083 if ( !$value ) { 00084 $value = $key; 00085 } 00086 00087 $this->_options[$key] = $value; 00088 } 00089 00090 function removeOptions($key){ 00091 unset($this->_options[$key]); 00092 } 00093 } 00094