You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2011-12-02 21:19:52

amac
Member
Registered: 2011-09-21
Posts: 10

Generic Object Plugin adding custom fields

Hi All.

I have the generic object plugin on a dev server and im trying to add some custom fields. Not really sure what im doing wrong. Sorry i dont have very much experience with PHP, everything else is working fine, i can add objects and add the pre built controls/items but nothing custom comes thru.

I have created a file called test.php in plugins/genericobject/fields/constants/

it contains the following

<php?
$GO_FIELDS['plugin_genericobject_mytypecolors_id']['name']=$LANG['genericobject']['test'][2];
$GO_FIELDS['plugin_genericobject_mytypecolors_id']['field']='color';
$GO_FIELDS['plugin_genericobject_mytypecolors_id']['input_type']='text';

It says in the wiki that i need to activate this field, but im not sure where i do that?

Edit: OK i have made it work using the fields folder rather than constant. This is fine for our needs.
How can i set the values of the drop down using 1 list? I figure it would be in the Locales\en_GB.php
I can set the max and min but how do you set all the options for the dropdown

So far i have the below in en_GB.php
$LANG['genericobject']['customFields'][0] = "Webbing (Cuts, wear, burns, marks, other damage)";
$LANG['genericobject']['customFields'][1] = "Test";

and in fields\myConstant.php
$GO_FIELDS['webbing']['min'] = $LANG['genericobject']['customFields'][1];
basically im looking for something like this:
$GO_FIELDS['webbing'][option_value][1] = 'Pass';
$GO_FIELDS['webbing'][option_value][2] = 'Watch';

Also are there any plans for RFID or barcode support in the future?

Thanks for any help!
Andy

Last edited by amac (2011-12-03 01:10:28)

Offline

#2 2011-12-03 14:24:58

wawa
GLPI-DEV
From: Montpellier / France
Registered: 2006-07-03
Posts: 6,019
Website

Re: Generic Object Plugin adding custom fields

hello
version of the plugin and glpi ?

Offline

#3 2011-12-03 18:50:17

amac
Member
Registered: 2011-09-21
Posts: 10

Re: Generic Object Plugin adding custom fields

Thanks for the reply

It is glpi version 0.80 and GenericObject is version 2.0

Thanks again

Offline

#4 2011-12-08 19:08:15

amac
Member
Registered: 2011-09-21
Posts: 10

Re: Generic Object Plugin adding custom fields

I have another question.
Is there anyway to track the history of an object?
Like show changes that were made on a certain date or something similar?

Offline

#5 2011-12-09 12:23:34

wawa
GLPI-DEV
From: Montpellier / France
Registered: 2006-07-03
Posts: 6,019
Website

Re: Generic Object Plugin adding custom fields

hello,

amac wrote:

Also are there any plans for RFID or barcode support in the future?

what kind of support are looking for ?

amac wrote:

Is there anyway to track the history of an object?
Like show changes that were made on a certain date or something similar?

when you create your object, set "use history" to true.

Offline

#6 2011-12-09 19:34:47

amac
Member
Registered: 2011-09-21
Posts: 10

Re: Generic Object Plugin adding custom fields

Thanks once again for the reply.
By support i meant the plugin had the ability to create barcodes for us. It really wouldnt be much trouble to have a seperate plugin/or application to handle that for us if its not already implemented.

Thanks for the "Use history". That is exactly what i am looking for.

I'm still having problems filling values in a drop down though. Not sure if its a PHP thing or GO thing

$GO_FIELDS['webbing'][option_value][1] = 'Pass';
$GO_FIELDS['webbing'][option_value][2] = 'Watch';

How can i do something like the above to populate the values of a drop down?

(Is there some more thorough documentation that i should have read through? i didnt see much on the site i d/l'ed from)

thanks again for the help
Andy

Offline

#7 2011-12-11 19:59:26

amac
Member
Registered: 2011-09-21
Posts: 10

Re: Generic Object Plugin adding custom fields

Ok im getting a little further into this. From what i have seen there is no way to do this without customizing one of the modules.

So for anyone out there interested, this is what i have done.

In GenericObjects\Fields i have created a file called myConstant.php This is where you define custom fields from what i gather. I have set the following

$GO_FIELDS['attachmentPoint']['name']= $LANG['genericobject']['customFields'][2];
$GO_FIELDS['attachmentPoint']['field']='attachmentPoint';
$GO_FIELDS['attachmentPoint']['input_type']='dropdown';
$GO_FIELDS['attachmentPoint']['Ziptrek'] = 1;

By adding the ['Ziptrek'] line i am setting a 'searchoption' which i will use later to define my dropdown.

Inside of inc/object.class.php there is a function displayField (for me this is line 322). Inside this function is a switch case clause which handles the beginning of the creation of the dropdownlist. in the case "int11" (line 340) i have the following

                                        if (isset($searchoption['Ziptrek'])){
                                      //$firephp -> log('Ziptrek');
                    Dropdown::showZiptrekList($name,$value);
               }

This calls the dropdown class file inc/dropdown.class.php. Inside this class i have created a function called showZiptrekList($myname,$value) and then i create the dropdown list the way i want. Note, for me at present, i must set the value to be an integer not a string as it writes the value to the DB, not the display and it appears the DB only likes int's

Now i just need a way to either save the value as a string or edit the historical data page to get that to display a string instead of the value and ill be set.

please leave this open so i can add more notes.

Last edited by amac (2011-12-11 20:01:37)

Offline

#8 2011-12-11 22:10:48

amac
Member
Registered: 2011-09-21
Posts: 10

Re: Generic Object Plugin adding custom fields

The log changing section was quite easy.

I just skipped down to line 582 (for me anyway). inside the if(empty($tmp['change'])) step i have (it always seem to be empty for me)

if(substr($itemtype,0,19) == 'PluginGenericobject'){
                switch($data["old_value"]){
                    case 1:
                        $data["old_value"] = "Pass";
                        break;
                    case 2:
                        $data["old_value"] = "Watch";
                        break;
                    case 3:
                        $data["old_value"] = "Repair";
                        break;
                    case 4:
                        $data["old_value"] = "Fail";
                        break;    
                }
                switch($data["new_value"]){
                    case 1:
                        $data["new_value"] = "Pass";
                        break;
                    case 2:
                        $data["new_value"] = "Watch";
                        break;
                    case 3:
                        $data["new_value"] = "Repair";
                        break;
                    case 4:
                        $data["new_value"] = "Fail";
                        break;    
                }

then i leave the rest untouched. ie $tmp['change'] = "\"".$data["old_value"]."\" --> \"". $data["new_value"]."\"";
seems to work so far, only problem is if one of the other fields has a value from 1-4 it gets changed in the log display (not a prob for us)

Offline

Board footer

Powered by FluxBB