25 private $_valuelistsConfig = null;
29 $this->_loadValuelistsIniFile();
35 return DATAFACE_SITE_PATH.
'/valuelists.ini';
52 private function &_loadValuelistsIniFile(){
53 if ( !isset($this->_valuelistsConfig) ){
54 import(
'Dataface/ConfigTool.php');
56 $this->_valuelistsConfig =& $configTool->loadConfig(
'valuelists');
58 return $this->_valuelistsConfig;
74 private function _loadValuelist($name){
75 if ( !isset($this->_valuelists) ){
76 $this->_valuelists = array();
79 if ( !isset($this->_valuelists[$name]) ){
80 $conf =& $this->_loadValuelistsIniFile();
81 if ( isset($conf[$name]) ){
82 $vllist = $conf[$name];
85 $valuelists[$vlname] = array();
86 foreach ( $vllist as $key=>$value ){
87 if ( $key ==
'__sql__' ) {
92 $res = df_query($value, null,
true,
true);
93 if ( is_array($res) ){
95 foreach ($res as $row){
97 $valuevalue = count($row)>1 ? $row[1] : $row[0];
98 $valuelists[$vlname][$valuekey] = $valuevalue;
100 if ( count($row)>2 ){
101 $valuelists[$vlname.
'__meta'][$valuekey] = $row[2];
106 throw new Exception(
"Valuelist query '".$value.
"' failed. ", E_USER_NOTICE);
110 $valuelists[$vlname][$key] = $value;
120 if ( !isset( $this->_valuelists ) ){
121 $this->_valuelists = array();
130 foreach ( $conf as $vlname=>$vllist ){
131 $valuelists[$vlname] = array();
132 if ( is_array( $vllist ) ){
133 foreach ( $vllist as $key=>$value ){
135 if ( $key ==
'__sql__' ) {
140 $res = df_query($value, null,
true,
true);
141 if ( is_array($res) ){
143 foreach ($res as $row){
145 $valuevalue = count($row)>1 ? $row[1] : $row[0];
146 $valuelists[$vlname][$valuekey] = $valuevalue;
148 if ( count($row)>2 ){
149 $valuelists[$vlname.
'__meta'][$valuekey] = $row[2];
153 throw new Exception(
'Valuelist sql query failed: '.$value.
': '.mysql_error(), E_USER_NOTICE);
157 $valuelists[$vlname][$key] = $value;
170 static $instance = 0;
171 if ( $instance === 0 ){
178 if ( !is_a($this,
'Dataface_ValuelistTool') ){
183 $vlt->_loadValuelist($name);
184 if ( isset($vlt->_valuelists[$name] ) ){
186 return $vlt->_valuelists[$name];
189 throw new Exception(
"Request for valuelist '$name' that does not exist in Dataface_ValuelistTool::getValuelist().", E_USER_ERROR);
194 if ( !is_a($this,
'Dataface_ValuelistTool') ){
199 return isset( $vlt->_valuelistsConfig[$name]);
208 if ( !is_a($this,
'Dataface_ValuelistTool') ){
213 $out =& $vlt->_valuelists;
231 import(
'Dataface/ConfigTool.php');
233 $conf = $configTool->loadConfig(
'valuelists',
$table->tablename);
235 $relname = $valuelistName.
'__valuelist';
237 $table->addRelationship( $relname, $conf[$valuelistName]);
238 $rel =&
$table->getRelationship($relname);
251 if ( $checkPerms and !$rrecord->checkPermission(
'edit', array(
'field'=>$valfield)) ){
254 $rrecord->setValue($valfield, $value);
255 if (isset($key) and isset($keyfield) ){
256 if ( $checkPerms and !$rrecord->checkPermission(
'edit', array(
'field'=>$keyfield)) ){
259 $rrecord->setValue($keyfield, $key);
261 import(
'Dataface/IO.php');
263 $res = $io->addRelatedRecord($rrecord);
265 return array(
'key'=>$rrecord->val($keyfield),
'value'=>$rrecord->val($valfield));
279 import(
'Dataface/ConfigTool.php');
281 $conf = $configTool->loadConfig(
'valuelists',
$table->tablename);
282 if ( !@$conf[$valuelistName][
'__sql__'] ){
287 $relname = $valuelistName.
'__valuelist';
289 $table->addRelationship( $relname, $conf[$valuelistName]);
290 $rel =&
$table->getRelationship($relname);
291 $rel->_schema[
'action'][
'visible']=0;