RV: RV: Automatic hierselects with DBDOFB UPDATED!!!! Almost got it
| From: | Jose Manuel Zea | Date: | Fri, 12 May 2006 12:22:00 +0000 |
| Subject: | RV: RV: Automatic hierselects with DBDOFB UPDATED!!!! Almost got it | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-24054@lists.php.net to get a copy of this message | ||
Hi all, again!
I almost got it. Adapting the code from the example
http://opensource.21st.de/25.html#A11.
But I need to improve it in two ways:
1) The first one is that the automatic setting of the values is not working.
2) The second is that code I did it´s not very elegant, I tried to do it
with a recursive function but I couldn´t.
I´m going to explain what I´ve done.
The thing it´s that if I defined the $conditionalFields to get Country ->
Province -> City -> Area as:
var $conditionalFields = array(
'codzonacodmunicipio' => array(
'codpais:paises' => array('codpais'),
'codprovincia:provincias' =>
array('codpais','codprovincia'),
'codmunicipio:municipios' =>
array('codprovincia','codmunicipio'),
'codzona:zonas' => array('codmunicipio', 'codzona')
)
);
The code from the example works looking up the values, but for a multi
hierselect the array values must be in my example something like this:
* 0 =>
o 1 => España
* 1 =>
o 1 =>
+ 4 => Almería
+ 6 => Granada
* 2 =>
o 1 =>
+ 4 =>
# 33 => Aguadulce
# 40 => Roquetas
+ 6 =>
# 36 => Motril
* 3 =>
o 1 =>
+ 4 =>
# 33 =>
* 3 => Campillo
* 53 => Puerto
# 40 =>
* 54 => Urba
* 55 => Pueblo
+ 6 =>
# 36 =>
* 47 => Puerto
And the code from the example, defining the conditionalFields like I did
creates the values as:
* 0 =>
o 1 => España
* 1 =>
o 1 =>
+ 4 => Almería
+ 6 => Granada
* 2 =>
o 6 =>
+ 36 => Loja
o 4 =>
+ 33 => Aguadulce
+ 40 => Roquetas
* 3 =>
o 33 =>
+ 3 => Campillo
+ 53 => Puerto
o 36 =>
+ 47 => Pueblo de Loja
o 40 =>
+ 54 => Urba
+ 55 => Gran Plaza
So what I need it´s a function that converts this array in the desired. What
I did, (not very elegant) is changed the coded, once I get this last array
called $select, to this:
$select1 = $select[0];
foreach ($select1 as $key=>$value){
$select2[$key]=$select[1][$key];
}
foreach ($select1 as $key=>$value){
foreach ($select2[$key] as $key2=>$value2){
$select3[$key][$key2]=$select[2][$key2];
}}
}
foreach ($select1 as $key=>$value){
foreach ($select2[$key] as $key2=>$value2){
foreach ($select3[$key][$key2] as $key3=>$value3){echo $key3;
$select4[$key][$key2][$key3]=$select[3][$key3];
}
}
}
$sel =&
HTML_QuickForm::createElement('hierselect',$fb->getFieldName($virtualfield),
$desc);
$options = array($select1, $select2,$select3,$select4);
$sel->setOptions($options);
/* init the hierselect with the values from the database */
foreach ($this->conditionalFields as $virtualfield => $cf) {
$a = array();
foreach ($cf as $key=>$fields) {
list($localfield, $tmp) = explode(':', $key);
$a[] = $this->$localfield;
}
$this->$virtualfield =& $a;
}
$this->fb_preDefElements[$virtualfield] = $sel;
And this it´s working, I get my hierselect with 4 selects. Even the
preProcessForm it´s working also. The only thing that doesn´t work it´s the
initialization of the values. I can do it when I get the form using
setDefaults, but I would like to do it automatically like in the example.
I´ve this not only to see if someone can help with this, also because this
can be a trick for someone trying to do something similar, because I´ve
explored the whole Internet and there´s nothing related to this except the
good example I mentioned.
Can anyone give any help, please? Thanks in advanced for your time.
-----Mensaje original-----
De: Jose Manuel Zea [mailto:jmzeag@yahoo.es]
Enviado el: miércoles, 10 de mayo de 2006 14:22
Para: 'pear-general@lists.php.net'
Asunto: Automatic hierselects with DBDOFB
Importancia: Alta
Hi all:
I followed the example in http://opensource.21st.de/25.html#A11 for Creating
automatic hierselects with DB_DataObject_FormBuilder and it worked
perfectly. The only thing it´s that I need the same but with 4 select
components, to get Country -> Province -> City -> Area.
I tried it first with 3 Province -> City -> Area (Provincia->Municipio->Zona
in spanish), changing the var $conditionalFields to something like:
var $conditionalFields = array(
'codzonacodmunicipio' => array(
'codprovincia:provincias' => array('codprovincia'),
'codmunicipio:municipios' =>
array('codprovincia','codmunicipio'),
'codzona:zonas' => array('codmunicipio', 'codzona')
)
);
In this way I get 3 selects, where I can select the Province and
automatically filters the city, but the third select doesn´t work.
Does anyone how to achieve it following the Creating automatic hierselects
example?
Thanks in advanced.
Best regards.
Jose Manuel Zea
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice.yahoo.com