Bug #16340 Dynamic backend problems
Submitted: 10 Jan 2006 14:11 Modified: 12 Jan 2006 16:49
Reporter: Mariano Ronchi Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Eventum Severity:S2 (Serious)
Version:1.7.0 OS:Windows (WINDOWS XP)
Assigned to: Bryan Alsdorf CPU Architecture:Any

[10 Jan 2006 14:11] Mariano Ronchi
Description:
When I'm trying to use the dynamic backend with 2 assosiated fields is not working. When I change selection in master field the deppendant field options wasn't updated.

Sorry about my english!

How to repeat:
On Eventum 1.7.0 version ,I just created 2 custom fields one with the following data:

Id: 1 
Name: BugType
Type: Combo
Options: Enhancement,Incident,New Request

And other with:

Id: 2
Name: BugSubType
Type: Combo
Options: Backend => class.subcategory.php

File class.subcategory.php contents:
---------------------------------------------------------------------
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | Eventum - Issue Tracking System                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003, 2004, 2005 MySQL AB                              |
// |                                                                      |
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or    |
// | (at your option) any later version.                                  |
// |                                                                      |
// | This program is distributed in the hope that it will be useful,      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with this program; if not, write to:                           |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place - Suite 330                                          |
// | Boston, MA 02111-1307, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: Bryan Alsdorf <bryan@mysql.com>                             |
// +----------------------------------------------------------------------+
//

include_once(APP_INC_PATH . "class.user.php");
include_once(APP_INC_PATH . "db_access.php");

/**
 * Custom field backend to assist other backends in dynamically changing the
 * contents of one field or hiding/showing based on another field.
 * 
 * @author Bryan Alsdorf <bryan@mysql.com>
 */
class Subcategory_Custom_Field_Backend
{
    function getList($fld_id)
    {
        $list = array();
        $data = $this->getStructuredData();
        foreach ($data as $row) {
            $list += $row['options'];
        }
        return $list;
    }
    
    
    /**
     * Returns a multi dimension array of data to display. The values listed
     * in the "keys" array are possible values for the controlling field to display
     * options from the "options" array.
     * For example, if you have a field 'name' that you want to display different
     * options in, depending on the contents of the 'color' field the array should
     * have the following structure:
     * array(
     *      array(
     *          "keys" =>   array("male", "dude"),
     *          "options"   =>  array(
     *              "bryan" =>  "Bryan",
     *              "joao"  =>  "Joao",
     *              "bob"   =>  "Bob"
     *          )
     *      ),
     *      array(
     *          "keys"  =>  array("female", "chick"),
     *          "options"   =>  array(
     *              "freya" =>  "Freya",
     *              "becky" =>  "Becky",
     *              "sharon"    =>  "Sharon",
     *              "layla"     =>  "Layla"
     *          )
     *      )
     * );
     * 
     * @return  array An array of data to display
     */
   function getStructuredData()
   {
       
	  return array( 
	  			array( "keys" => array("Enhancement")	, "options" => array("Aplicación de Support Packages") ),
				array( "keys" => array("Incident")	   , "options" => array("Problema infraestructura regional",
  																			"Dificultad en utilizar el sistema",
																			"Requerimiento de configuración de BASIS",
																			"Errores en el sistema",
																			"Mantenimiento de perfil",
																			"Creación de usuario SAP/BW",
																			"Reseteo de password",
																			"BW-Modificación de roles",
																			"BW- Cargar datos de Sapiens a BW",
																			"BW-Tareas de mantenimiento",
																			"BW-Modificación de reportes") ),
				array( "keys" => array("New Request")  , "options" => array("Ajuste de customizing con impacto en template",
																			"Ajuste de WorkBench con impacto en template",
																			"Nuevo Proceso de Negocio con impacto en template",
																			"User Exit con Impacto en template",
																			"Field Exit con Impacto en template",
																			"Aplicación de una nota",
																			"Aplicación de un hot package",
																			"Modificacion de Interfaces / Desarrollos Regionales",
																			"Ajuste de customizing sin impacto en template",
																			"Ajuste de WorkBench sin impacto en template",
																			"Nuevo Proceso de Negocio sin impacto en template",
																			"User Exit sin impacto en template",
																			"Field Exit sin impacto en template",
																			"Nuevo reporte / interfaz",
																			"Aplicación de una nota de impuestos locales",
																			"Aplicación de hot package de impuestos locales",
																			"User Exit sin impacto en template de impuestos",
																			"Field Exit sin impacto en template de impuestos",
																			"Ajuste de Customizing por impuestos",
																			"Ajuste de Reporte / Interfaz por impuestos",
																			"Nuevo Reporte / Interfaz por impuestos",
																			"Nuevo Query / Cambio en query",
																			"Nuevo InfoCubo / Cambio",
																			"Nuevo usuario / perfil para BW",
																			"Configuración de Jobs R/3",
																			"Nuevo Des. Aplicación General Sin Imp",
																			"Ajuste de Formularios sin Imp",
																			"BW-Ajustar el modelo actual",
																			"BW-Nuevo KPI - incluye reportes",
																			"BW- Implementar el acceso a nuevos usuarios",
																			"BW-Parametrización técnica+ajuste/crear modelo" ) ) );
   
   }
   
   
    /**
     * Returns the ID of the "controlling" custom field.
     * 
     * @return   integer The ID of the controlling custom field
     */
    function getControllingCustomFieldID()
    {
        return 1;
    }
   
   
    /**
     * Returns the name of the "controlling" custom field.
     * 
     * @return   string The name of the controlling custom field
     */
    function getControllingCustomFieldName()
    {
        return 'BugType';
    }
    
    
    /**
     * Returns true if this row should be hidden if it has no value
     * 
     * @return  boolean True if this field should be hidden before options are set
     */
    function hideWhenNoOptions()
    {
        return true;
    }
}

?>
---------------------------------------------------------------------
[10 Jan 2006 14:13] Mariano Ronchi
Class Subcategory

Attachment: class.subcategory.php (application/octet-stream, text), 6.93 KiB.

[12 Jan 2006 16:49] Bryan Alsdorf
This is a bug with your backend, not with  Eventum.

Here are two things you need to do to get this to work:
1. Have your subcategory class extend Dynamic_Custom_Field_Backend.
2. Under structured data, the keys ("Enhancement", "Incident", etc) need to be the numeric keys, not the display value. If you view the source of the create issue page you will be able to find these values.

In the future please email the eventum developement list eventum-devel@lists.mysql.com instead of opening a bug.