When defining CCK fields, it's possible to put in some PHP to create an array of "allowed values". But, often you need to re-use that list of allowed values in other CCK fields and node types. So, need a way of storing, naming and managing lists of "allowed values" and Table Manager seems to be a close fit. At a first glance, the only addition would be a function something like tablemanger_get_array($tablename) which would return an array - the table would have only two columns, "key" and "value".

Multi-language: Next step. CCK does not easily allow multi-language versions of "allowed values". Tables could have columns named with a language code, i.e. column 1 = "key", column 2 = "en" column 3 = "es", then the call to tablemanger_get_array($tablename) would return an array of correct values for the current language.

Please let me know if you'd be wiling to support this feature. I'm willing to do some or all of the coding :) or maybe add a module that hooks into yours, but that seems overkill for something so simple (?)

Comments

Andy Inman’s picture

Just thinking, better to make it tablemanager_get_array($tablename, $columname) for better flexibility - can be called as tablemanager_get_array($tablename, $locale) for language purposes.

pobster’s picture

Status: Active » Postponed (maintainer needs more info)

Urrrhhhhhhhh... I'm really not clear with what you're asking? Please could you explain it again - but 1/ Assume I'm an idiot, 2/ Assume I know NOTHING at all about CCK... Because I don't really... And I am an idiot...

Thanks,

Pobster

Andy Inman’s picture

Ok, sorry for not making it clear...

CCK allows you to define your own types of node, and data types (fields) that will be stored there.

So, let's say I have a data type of "Operating System", which stores an integer representing various choices, maybe 11=Windows 2000, 12=Windows XP, 13=Windows Vista, 21=Ubuntu Linux, 22=Debian Linux ... etc.

CCK allows me to define this lists of options in two ways, a simple list like this:

11|Windows 2000
12|Windows XP
etc.

... or PHP code which returns an array, e.g.
return array(11=>'Windows 2000', 12=>'Windows XP', etc)

Problem 1: I don't want to have to duplicate this list or code every time I create a data-type which represents "Operating System".
Problem 2: How can this list of OSs be easily updated when a new OS version/name comes out?
Problem 3: Access to these CCK lists and PHP code normally requires Admin rights - what if I want a lower-privilege user to be able to update the list of allowed values?
Problem 4: Some lists may be multi-language. There are ways of doing this, but it's messy.

So, I need an easy way to create and manage a list of "Operating Systems" where OS_CODE=>OS_NAME, and people who I grant access to can add, edit and delete etc. All CCK needs is PHP code returning an array, so a function like: return tablemanager_get_array('OS') would suffice, where 'OS' is the name of a table.

In summary, the following functions would be great

tablemanager_get_array($table_name)

Returns an array where key=column 1 and value = column 2 from the table

tablemanager_get_array($table_name, $key_column_name, $value_column_name)

Returns an array where key and value come from the named columns. This allows flexibility, including "multi-language" use.

Example if the table named "Colors" contains:

ColorCode ColorName-en ColorName-es
1 Red Rojo
2 Green Verde
3 Blue Azul

... then when $local=='es', tablemanager_get_array('Colors', 'ColorCode', 'ColorName-'.$locale) would return array(1=>'Rojo', 2='Verde', 3='Azul')

Hope it's clearer now?

pobster’s picture

Ahhhh right, so you want the function to simply return the array rather than pass it to theme_table? You know... The simplest way to do this would be to add an extra parameter to tablemanager_display (just a simple flag, on/ off type thing) as the function has to build an array anyway to pass to theme_table. You could just 'break-out' out of the routine and return the array before theme_table is called? It's possibly not ideal as the (Drupal) theme_table function requires quite a complicated array and is possibly a bit too complicated to return to a casual Drupal user?... Spitting it out in its own function is easy enough though, it's probably only ten minutes work... Problem is, I wouldn't add it to the current 5.x branch as well... It's not a proper branch - it's a messy hack of the 4.7.x branch just to get *something* up and running while I worked on other projects.

Pobster

Andy Inman’s picture

Ok, thanks for the pointers, I'll take a look myself. Another way would be a separate module which called the tablemanager_display function and parsed its output, but that would seem messy at best. The final array has to be in the format required by CCK - a simple array(key->value, ...)

I see you're looking at CSV import/export (or only import?) Parsing CSV data would be easier. Or maybe it makes more sense to work directly with the SQL tables. I'll take a look.

I'll let you know how I get on.

pobster’s picture

The CSV import function has been present for well over a year now (hence it does its job pretty well) - the export code is complete and present in the 6.x branch (or maybe HEAD I forget) its based on a previous (unreleased) 5.x dev version I had knocking about, but essentially its the same 'engine' creating the output. I'm going to convert it back to 5.x for Anisa as I completely have a soft spot for her... I'll do it tonight if I can... Although it'll only take probably ten minutes or so I reckon... I'm just out and about tonight so I can't make any guarantees about when I'll put it out.

Pobster

pobster’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (outdated)

Closing as D5.x is now unsupported.