[eluser]OverZealous[/eluser]
That's awesome. Please
do include my features if you think they are 'worthy'! I've been using the get_[whatever] pattern all over. I often have get_visible() or get_enabled() for items that can be hidden or disabled. These just add a where() into the stream. It's awesome as in $user->tasks->get_today().
I have one other object I meant to share. It's still a prototype, and I haven't begun to use it yet, but here's the gist:
I often have a collection of items that are sorted by an arbitrary field. I want to be able to get this collection sorted, update the sort order, and insert new items in a consistent manner.
So, I subclassed my DataMapperExt (again) and added functions to handle most of this. I overrode the get and save functions to handle inserting new items, and retrieving the set sorted. You usually only have to interact with one method:
update_order: Pass in an array of ids, and it will look through the table and update the order to match the array.
It's customizable, so if you have a table that is sorted based on a grouping, you can easily override 2 functions and keep everything else.
Example of this last part:
Say you have a table of WidgetTypes, each of which belongs to a WidgetCompany. Each WidgetCompany's WidgetTypes are sorted independently. (Note: this only works if each WidgetType has a unique WidgetCompany, meaning a one-to-many relationship.)
WidgetType simply needs to subclass SortableModel and have a sort_field (by default, sortorder). Then override the two functions
next_sort_index and
bump_sort_index, which retrieve the next sort index, and bumps every item up, respectively. These functions will need to be rewritten to filter based on the WidgetCompany.
OK, just had an inspiration. Now those two methods above can be called with a model as the argument. To filter, simply override, create the filtered model, and call
parent::next_sort_index($my_model). I'll work on providing better examples at some point.
EDIT: Please don't use the attached file. I've had to do a lot of reworking on this concept, and it isn't ready for public consumption yet. It might work on whole-table sorts, but that's about it.