Sorry for the long title :)

This is a highly experimental patch for this module to add the following features to this module:
- Allows to fetch a list of items from an SQL SELECT statement
- Item list is now keyed so we use string references instead of the item name (the plain item list format is now "REF|item name" on each line)
- Added a textfield widget (useful for high quantities)
- Added a new field formatter to omit items with zero value (handy for big lists)
- Changed the key in the inventory_items DB table to include the fieldname (fieldset), so we can have multiple inventory fields on a single content type (I'm not sure this is the right way to fix it, but worked)

Be warned that this patch has not gone through much testing, so there are probably a lot of bugs. I post it to get some feedback from the community since I'm new to Drupal, so I could be missing some evident coding standards. Any feedback or suggestions are welcome, since I'll try to submit a cleaner review of this in the next days.

P.S: This patch was generated quickly from my code. You can get the tested code from http://prodicus.rovira.cat/inventory_ng.tar.gz, although you will need to remove some debug(..) calls from the code.

Comments

quimrovira’s picture

BTW, I forgot to mention that making the SQL Select item list origin might be a security risk somehow. Since it uses no parameters, I think it might be a good idea, since it allows something as powerful as:

select A.nid as confnid, CONCAT(B.title," -> ",A.title) as itemname from node as A, content_type_configuracioelementdefoc as CEF, node as B WHERE A.type='configuracioelementdefoc' AND A.nid=CEF.nid AND B.nid=CEF.field_elementdefoc_nid;

To explain it a little, I've got a content type (A) whith a nodereference to another kind of content type (B). The select statement above would make an item list keyed using A's nid and named as "A's title -> B's title". This in my case allows to select from a list of elements with variations (CEF). A little weird, I know.

A simpler statement would be:

select A.nid as confnid, A.title as itemname from node as A WHERE A.type='configuracioelementdefoc';

Which lists all nodes of an specific content type as items keyed using their nids.

Also useful is straight from a user-created table:

SELECT reference,description from mytable;
quimrovira’s picture

Status: Needs review » Needs work

This patch is horribly broken, sorry... I'll update it with a "cleaner" patch implementing the same functionality asap.

quimrovira’s picture

StatusFileSize
new421 bytes
new13.18 KB

This is the same patch as before, but it should now apply in a clean way.
The db table changed since the introduction of item keying, so you will have to modify it. The install file is also being attached for you to see this changes.

There are still some inconsistences I'd like to take a closer look at before considering this patch ready. Feel free to test it and report any bugs.

quimrovira’s picture

Feature requests:

http://drupal.org/node/228631
http://drupal.org/node/128623

Marked as duplicate of this issue.

quimrovira’s picture

Status: Needs work » Closed (fixed)

Patch has been reviewed and applied to the 2.x-dev version of inventory_module. Be aware that this module still needs proper in-depth testing.

I branched a new version to keep the previous behaviour available due to compatibility.