Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
Vocabulary.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
21 /*******************************************************************************
22  * File: Dataface/Vocabulary.php
23  * Author: Steve Hannah <shannah@sfu.ca>
24  * Created: Sept. 2, 2005
25  * Description:
26  * Encapsulates vocabularies that can be used in select lists and auto complete widgets
27  * to limit the input to a field.
28  ******************************************************************************/
29 
31 
32  var $_options = array();
33  var $_name;
34  function Dataface_Vocabulary($name,$options){
35  $this->_name = $name;
36  $this->_options = $options;
37  }
38 
39 
43  public static function &getVocabulary($name){
44  $vocabularies =& Dataface_Vocabulary::getVocabularies();
45 
46  if ( !isset( $vocabularies[$name] ) ){
47  $vocabularies[$name] = new Dataface_Vocabulary($name, array());
48  }
49 
50 
51  return $vocabularies[$name];
52  }
53 
54 
55  public static function &getVocabularies(){
56  if ( !isset( $vocabularies ) ){
57  static $vocabularies = array();
58  }
59  return $vocabularies;
60  }
61 
62  function register($name, $vocab){
64 
65  if ( is_array($vocab) ){
66  $vocab = new Dataface_Vocabulary($name, $vocab);
67  }
68 
69  $vocabs[$name] =& $vocab;
70  }
71 
72 
73 
74  function &options(){
75  return $this->_options;
76  }
77 
78  function setOptions($options){
79  $this->_options = $options;
80  }
81 
82  function addOption($key,$value=''){
83  if ( !$value ) {
84  $value = $key;
85  }
86 
87  $this->_options[$key] = $value;
88  }
89 
90  function removeOptions($key){
91  unset($this->_options[$key]);
92  }
93 }
94