If I extrapolate from the original comparing of node references over these 3 issues #749852: Add userreference as a type of "resource", #750500: handle "organic group" resources by member set intersection and #750520: handle "organic group" resources as a resource pool, I can see that I can't see which ideas come next. So I suggest to make resource_conflict extensible by giving other modules a chance to decide whether two resource usages are conflicting or not. One idea to do that could be a hook like this:
function hook_resource_conflict_info() {
$info = array(
'handlername_a' => array(
'type' => 'field',
'fieldtype' => 'nodereference', // as in DB table {content_node_field}
'callback to test for conflict' => 'my_module_resource_conflict_nodereference_compare_callback',
// [...]
),
'handlername_b' => array(
'type' => 'node',
'callback to test for conflict' => 'my_module_resource_conflict_node_compare_callback',
// [...]
),
);
return $info;
}
The exact interface format, i.e. the layout of that $info array and the signatures of the callback functions, will be developed in this issue.
Comments
Comment #1
deviantintegral commentedThis seems reasonable.
Are you suggesting that virtually every implementation of the hook would include a 'node' callback? The module declares that it can detect conflict for nodes, and the types of fields that it can check for? Other then nodes and users, what types of data could be checked?
We're going to need file and path keys like hook_theme().
Comment #2
raphaelhuefner commentedOk, my post wasn't that clear.
A module implementing this hook should have a chance to offer as many different conflict detection methods as it sees fit. Some of these conflict detection methods might only need to look at one field (and will probably be able to do so only for fields of a certain type), and some other conflict detection methods might have to consider the whole booking node, maybe in order to check for value combinations of several fields or whatever I don't know yet.
For example, two different implementations of the hook could look like this:
For now, I would prefer to wrap the detection method definitions into that 'conflict_detectors'-sub-array to be able to extend this hook interface later with other sub-arrays. And I didn't have an idea yet whether to make a difference between single-value and multi-value fields or not, maybe it's possible to make really simple single-value field detectors like this:
Comment #3
raphaelhuefner commentedAnd if I come to think about it, some conflict detectors will even have to see all the time-conflicting booking nodes which the resource_conflict-module found out so far, the pool-checking in #750520: handle "organic group" resources as a resource pool will be such a case, very probably.
Comment #4
raphaelhuefner commentedHere comes a "first draft" which is intended to replicate the original behavior only, but by implementing a hook and several callbacks.
As it turned out, the original behavior is of the "consider the whole node"-type (see #2), as it announces a conflict even if the same resource is referenced by different nodereference fields. (Imagine for example, a "course" node_type which can refer to teaching equipment [like beamers, and so on] as "field_teaching_equipment" and another node_type "service" which can refer to the same teaching equipment as "field_serviceable_object" [when service has to schedule to call in a beamer to change it's bulb, or whatever].)
"Still to be done" is handling of conflict detectors for individual fields and whole groups of overlapping nodes. (Both the original motivation to begin with hooks and callbacks in the first place.)
In the uploaded tar-file you can find a small additional module which implements the userreference conflict detector as seen in #749852: Add userreference as a type of "resource". I did this only because I already had an implementation to compare it with and to have more than 1 detector type (to learn to handle plural) and to have an example for an external detector module.
Maybe this resource_conflict is "polluted" with some patches from the issue queue. I am willing to sort this out finally, but IMHO I don't think this would be a real obstacle for having a "first look".
Documentation is lacking. Sorry for that, but I think I will be motivated enough to document if I get a little echo on this first draft.
Please have a look and tell me what you think!
Comment #5
raphaelhuefner commented"Second" draft, 2 bugfixes and removed some misleading defaults.
Comment #6
raphaelhuefner commentedDraft 3, some bugfixes and heavy renaming / refactoring. It's scary how renaming only some variables gives a whole new perspective... ;-)
Comment #7
ohthehugemanatee commentedRebuilt the module in Entities and Rules for just this purpose. Rules integration will be backported to D6, which makes this irrelevant.