Hi! You can implement it creating a new field type enum
and set their values from a function instead of options.
For example, I will add it a related field and enum. The idea is to create a field grilla_resultado
which will be add it to my editviewdefs.php instead of gcoop_grilla_name
.
'gcoop_grilla_id' => array (
'name' => 'gcoop_grilla_id',
'type' => 'id',
'len' => 36,
),
'gcoop_grilla_name' => array (
'source' => 'non-db',
'name' => 'gcoop_grilla_name',
'vname' => 'LBL_GCOOP_GRILLA_NAME',
'type' => 'relate',
'len' => '255',
'id_name' => 'gcoop_grilla_id',
'module' => 'gcoop_Grilla',
'link'=>'gcoop_grilla_link',
'join_name'=>'gcoop_grilla',
'rname' => 'name',
),
'gcoop_grilla_link' => array (
'name' => 'gcoop_grilla_link',
'type' => 'link',
'relationship' => 'gcoop_grilla_gcoop_gestionobjetivos',
'link_type'=>'one',
'side'=>'right',
'source'=>'non-db',
),
'grilla_resultado' => array(
'name' => 'grilla_resultado',
'type' => 'enum',
'len' => 255,
'vname' => 'LBL_GRILLARESULTADO',
'audited' => false,
'function' => array(
'name' => 'get_grillas',
'include' => 'modules/gcoop_GestionObjetivos/Helper.php',
),
),
Then, you need to create a file called Helper.php
inside of your module and defined a new function called get_grilas
. Your function should return an array with key and value items.
function get_grillas($focus, $field, $value, $view)
{
$query = "SELECT id,
name
FROM gcoop_grilla
WHERE
confirmado = 1
AND deleted = 0";
$db = DBManagerFactory::getInstance();
$resultado_query = $db->query($query);
$resultados = array();
while ($row = $db->fetchByAssoc($resultado_query))
{
$resultados [] = $row;
}
$arr_resultados = array('' => '<Seleccionar>');
if ((!empty($resultados)) && (is_array($resultados)))
{
foreach ($resultados as $resultado) {
$arr_resultados[$resultado['id']] = $resultado['name'];
}
}
return $arr_resultados;
}
Of course, the only problem, is that your relationship field would not be filled with the value of your dropdown.
So, you need to implement the save()
function on your Bean of your module.
Your save function should be something like this:
public function save($check_notify = false)
{
LoggerManager::getLogger()->debug("IImplemts saving Bean GestionOjetivos {$this->id}");
$this->gcoop_grilla_id = $this->grilla_resultado;
$result = parent::save($check_notify);
return($result);
}
Hope it helps!