Plugin modify Item table?

Hello,

I am in the middle of developing a plugin and have a question to some basic functionality.

I have to add a distinction to each item, which is in essence on the same level as "Public" and "Featured". Currently those two fields get stored in the items table itself, and any user with the appropriate permissions can toggle each value in the admin view.

Now, the most straight forward way to implement that seems to me to simply expand the item table with that particular column and update the admin view to accommodate the new value. But I am somewhat hesitant to do that, for obvious reasons.

What would be the most elegant way for a plugin to add this functionality?

Thanks for any input!

Yeah, it would definitely be a bad idea to modify the item table directly.

You'd probably need to create your own Model and table with the values, mapped to the item:

id | item_id | your_value

You'd use the item_save hook to save values, and you'd add to the form with admin_<type>_form hook or one of the similar ones.

The items_browse_sql sounds like it might also come in handy. There, you could join item browse queries to your table to filter values as needed.

Does that sound like it gets at what you need?

Thanks!

Yes, that does sound like it might work. Do you know offhand an example of a plugin that uses a similar approach?

Well, there are lots of plugins that in some way or another add related data to an Item, but generally they have a lot more going on than what you are looking for. The closest, simplest analogy might be Geolocation, but that, too adds on a lot more than you are doing. That said, looking at the Location model and how the plugin goes about installing tables might give you something to look at.

Hi,

You can check the Rating plugin too (each item or other record can be rated via ajax).

Sincerely,

Daniel Berthereau
Infodoc & Knowledge management

Thanks for the input - I will weed my way through the suggestions to incorporate the functionality.