I use Resource Conflict 7.x-3.x-dev (2012-Jun-14).

I want to build "Booking rooms for events" like http://drupal.org/node/756622

Step 5: Enable resource conflict

The last choice ("check Room to indicate that Rooms can never be booked at the same time.") is impossible. The field "Room" is not visible.

Something is wrong.

Comments

ohthehugemanatee’s picture

Status: Active » Closed (works as designed)

Hi wusel.

The documentation link you offered is for Drupal 6. The D7 version is a complete rewrite, and it works very differently. It uses Rules to create the resource conflict events. For what you want:

  • enable the module
  • enable the content type "Drupal user-group meeting" (from the doc link) for conflict checking in the content type "edit" page.
  • Create a new rules component, with three parameters: Room, Room_unsaved, and form.
    • In this component, add a condition: if Room = Room_unsaved
    • in this component, add a reaction: set a form validation error. Enter your own error message text, and use the form parameter when required.
  • edit the built-in Rules configuration at admin/config/workflow/rules/reaction/manage/rules_display_conflict_message_on_node_save .
    • in this Rule, delete the "set a form validation error" inside the loop.
    • In this Rule, add a reaction inside the loop to run your new component. Pass it the "room" from the current conflict list item, the "room" from the unsaved node, and the form.
wusel’s picture

@ohthehugemanatee:
Thanks for your quick answer.

But I don't know, how to do the steps 3 and 4 of your answer at "http://example.com/admin/config/workflow/rules" and how I have to answer the dialogs.

It may be useful to me and others to add a new page like "Booking rooms for events for Drupal 7".

If someone would type the steps here more detailed, then I will build an page for Drupal 7.

wusel’s picture

Title: Booking rooms for events » Booking rooms for events for Drupal 7
Category: bug » support
Status: Closed (works as designed) » Active

We should add a new page like "Booking rooms for events for Drupal 7".

ohthehugemanatee’s picture

Component: Code » Documentation

How to use Rules is not really in scope for this project... but it's really worth learning. It's the closest thing a non-programmer can get to programming. :)

The best place to start is their own ">documentation, or nodeone's excellent screencast series.

timothykc’s picture

I'd also like to see detailed instructions and/or an clear example for how to configure rules for this purpose. Thanks!

pat redmond’s picture

ohthehugemanatee, I agree that learning how to program rules is out of the scope of this issue queue, but I don't think that a step-by-step guide on how to create that rule for this module is. And we would all REALLY appreciate it!

If you write the steps for the rule, I will contribute the rest of the D7 tutorial - acknowledgements provided of course.

pat redmond’s picture

More specifically, is the component plugin a "Condition Set (AND)", "Condition Set (OR)", "Action Set", "Rule" or "Rule Set"?

When trying to select parameters, I can see 'Form', but not 'Room' or 'Room_unsaved'.

I have 3 rooms, so I need to be able to tell 'Resource Conflict' that there is only a conflict when the booking is for the same room. Currently I can only book one of the rooms at any time...

ohthehugemanatee’s picture

Assigned: Unassigned » ohthehugemanatee

I hear you, and I'll do it. Actually, the module comes with a rule that does the basics for you, it's all simple after that anyway. :)

jessico’s picture

Just to chime in, I've also been having trouble with configuration and would be very grateful for a bit more guidance.

My scenario is that I have about 7 room that get booked by Calendar events that I'd like to do conflict checking on. I've tried the steps from comment #1, but can't seem to get it right. Perhaps I'm missing a few details.

I have used Rules successfully for other features on my site, but am still fairly new at it.

Thank you very much for your time!

pat redmond’s picture

ohthehugemanatee - that would be fantastic!!
The rule that comes with the module seems to only work for one item - so it is OK if you have one room, but if you have 3 then it doesn't check that the booking conflict is with the same room. Even some directions on how to modify the existing rule would be brilliant.

I was thinking that I could work on developing an additional rule for the module, so that it is easier for others to customise. For now, I am running short on time for this project, so adding that will have to wait for several weeks.

pat redmond’s picture

ohthehugemanatee, just wondering if you've had a chance to look at this? Would I be able to entice you with a small cash contribution?

wusel’s picture

@ohthehugemanatee:
please add a more detailed description.

I want to add a new page like "Booking rooms for events for Drupal 7", but I don't know the steps.

Thanks from all, which will view the new page.

pat redmond’s picture

Hey Wusel, if you go here (http://drupal.org/node/756582), and scroll down to the bottom, you will see a link "Add child page". It is just above the "Looking for support..." text.
Clicking that should allow you to post the information you have.

If you don't see that link, you may need to post an issue to the webmaster queue. I don't remember if you need to have one of the webmasters give you access to edit the documentation. Alternatively, post it here, and I will put it up there for you.

wusel’s picture

@Pat Redmond:
thank you for your explanation. But that's not my/our problem. I have created several new doc-pages in the past.

But this issue (main text) does not work on my/our d7-websites yet. If I get an minimal explanation what we have to do to get it working, then I will start a new page very soon.

@all:
Please help. Something is wrong, I don't know what (e.g. look at #2, #5 - #7, #12).

FNGR’s picture

Can't get this to work... my head explodes

epbarta’s picture

I have a very similar problem to #7... three separate rooms. I have a taxonomy field attached to the "room" content type to distinguish between the rooms, and I just need the resource conflict rule to check the taxonomy term along with the date.

This blog post alludes to this exact functionality, but I just can't piece it all together. Any help would be greatly appreciated! I'd also help contributing to a blog post/tutorial on the subject if we can get it documented.

bolecha’s picture

Did you succeed?

Like it is said in the blog post :
"Hard" conflicts are when two bookings at the same time reference the same user or taxonomy term. Hard conflicts throw a form error and prevent saving the node. This is just like the above case, and it's a really simple modification on the default Rule."

but I can´t figure it out :-(

Help would be really appreciated

gcaudle’s picture

I am working on setting this up now. If I succeed, I will post back here. My use case is very similar to #16 - I have a content type created for event, displayed in a calendar, with multiple rooms categorized by taxonomy. ohthehugemanatee, thank you for taking over this module, and for adding taxonomy support. I think once the setup steps are documented exactly for a sample use case like that with #16 and my own, we're all going to see just how handy this module will be.

laboratory.mike’s picture

Hi everyone,

I've figured out one solution for this issue. I have not yet figured out how to get my site to generate an error message showing the right conflicting nodes (this issue will actually go into a bug report), but I have figured out how to get error detection working for booking resources, such that the site will block node creation and display an error message "A resource conflict has been detected, Please check the calendar." When I get proper node detection/list building working, I will post instructions for that also.

In my use case, I have equipment in a lab, and people reserve equipment by creating "Reservation" nodes that are tagged with the taxonomy terms "Equipment" and "Advisor," and the reservation time is a Date field (not ISO or UNIX timestamp). I wanted to have the site throw an error if two people are trying to reserve the same time on the same "Equipment." I am running the most up-to-date versions of all relevant modules.

Here is what I did:

  1. I went to admin/config/workflow/rules and edited "Display conflict message on node save." Namely, I deleted the "set a form validation error."
  2. Next, I created a rule component. When you start, choose "Rule" from the list of possible component plugins.
  3. On the next page, give the rule component a meaningful name. I used "Check for reserved equipment." A bad name doesn't break the site but makes it easier to find later.
  4. For variables, you will need two "Entity -> Any Entity" and a "Rules Forms -> Form." I called the "any entities" are called reservation and reservation-unsaved. These are all Parameters, and you can label them whatever you like.
  5. Next, you will come to a page where you can add conditions and actions. For this step, you will add five conditions and one action:
    • First, add two "Entity has field" conditions. For the first one, the data selector is "reservation" (or whatever your first "any entity" was from Step 4), and the field is the field you want to check for a conflict. In my case, it is the Equipment taxonomy field, but I noticed that you can choose ANY field you have set up on your site. The next "Entity has field is the same as the first, except that now you use reservation-unsaved.
    • Next, add two "Entity is of type" conditions. Again, one is for "reservation" and the other is for "reservation-unsaved." And for both, the entity type is "node."
    • For the last condition, add a "Data comparison." What you need to put in will be very specific to what you need to do, but for my specific case my first data selector was reservation:field-equipment-2:tid, i.e. [node/entity-you-are-using-for-bookings]:[field-you-are-checking]:[nid/tid/whatever-you-want-to-compare]. I then selected "equal to" for the operator and then reservation-unsaved:field-equipment-2:tid. In other words, the same field and thing to compare in that field, but for reservation and reservation-unsaved.
    • Finally, add an action "set a form validation error." I'm having trouble with this part right now, so for now I just have the message "Resource conflict detected - Please check the reservation calendar."
  6. Okay, your rule component is ready! Go back to your original Rule, and add an action. Go to the bottom of the list, and you will see your Rule Component! Select this, And select "conflict-list:0 for reservation, "node" for reservation-unsaved, and "form" for Form. Note that the site uses your labels instead of machine names on this page.
  7. Back on the main page of your Rule, move the Rule Component so that it is a child of your Loop. Congrats! You are done!

Summary: This rule component and rule modification will still begin like the original case and detect a problem any time that two nodes appear to conflict. But with the rule component, it will not throw an error UNLESS two conflicting nodes have the same value for a particular field. However, I notice that the error contains all nodes regardless of the field value I checked for, and I beleive it is because of the way I am building conflict_list in the original rule. I will post more when I get the form validation error part working; feel free to post any corrections you see to my method.

PascalAnimateur’s picture

Thank you so much for these clear instructions ! You made my day...

I have the same problem with the error message : tokens don't get replaced in the actual message. The strange thing is they work on the original rule... I'll let you know if I ever find a way around this.

PascalAnimateur’s picture

I got it working by adding an action that retrieves the reservation node before the "Set a form validation error". I named this "conflicting_reservation" and used tokens from this new variable instead of "reservation" (i.e. "Conflict detected with reservation [conflicting_reservation:title] !")

Hope this helps !

PascalAnimateur’s picture

I think step 6 should use list-item instead of conflict-list:0 for reservation ... as this would only check against the first conflicting resource ?

laboratory.mike’s picture

Thanks for pointing that out. I'll have to try the change.

gcaudle’s picture

laboratory.mike - If you are ever in Birmingham Alabama, I'll happily buy you lunch. I've been fighting this issue for a couple of months and following post #19 I was able to get my room reservation system up and running with conflict checking for each room. You da man!

gcaudle’s picture

Well, this worked great for items that had only one taxonomy term, but unfortunately my use case involves allowing the end user to book multiple rooms for a large event (meaning multiple "space requested" taxonomy terms for the same node) and this solution fails to trigger a conflict against those. I'm assuming what I need to do is to somehow loop through all the tids associated with that node in the data comparison, but I'm at a loss where to begin on that. Any ideas?

gcaudle’s picture

OK, I've come up with a method, but it's tedious. Working off laboratory.mike's step 5, in the data comparison bullet: To check for conflicts when multiple rooms (taxonomy terms) are allowed to be booked for the same event (node) one has to compare all the possibilities. In this case, 5 possible rooms checked when creating a new event against 5 possible rooms listed in existing event nodes. I added an OR statement, moved the first data comparison into that OR group, then added another comparison to the OR group that compared reservation:field_spacerequested:1:tid to reservation_unsaved:field_spacerequested:0:tid. This compares the second term listed on an existing page to the first term selected on the unsaved event. Then I repeated that process for all five possible rooms. However, that only handles the first room selected in the new request. Because they can book multiple rooms, the conflict checker rule has to have 25 data comparisons, 5 for each possible room (taxonomy term) selected by the user creating the new event. It's not pretty, but it works. If anyone has a more elegant solution, I'd love to hear it, because I can not imagine doing this for a use case with a lot more rooms.

gcaudle’s picture

PascalAnimateur, if you see this and have a chance, could you expand on how you did #21? I've not been able to accomplish that yet.

PascalAnimateur’s picture

You need to add a "Fetch entity by ID" action before "Set a form validation error" in your rules component that checks for conflicts. This action should fetch the Node from the reservation:nid parameter and return a named entity you will use to access the title of the conflicting node in the form validation error.
Hope this helps...

Anonymous’s picture

Thank you thank you thank you laboratory.mike, I was just lining up a room of monkeys, some keyboards and setting aside several million years. I don't know how you worked that out but you have saved me a huge amount of time and put my project, and more importantly my clients project back on track. thank you again.

Renee S’s picture

I did this a bit differently than laboratory.mike, as I had a use-case similar to gcaudle. I used two components for the evaluation: the first provides an outer and an inner loop through a) the existing field values and then for each of those b) the new field values. Within the inner loop is a component that does the data comparison of the list items, and form error if it evaluates to true. The trick is figuring out the parameters that you should be passing to each component, and in what format the parameters need to be passed around between the components. It can also get a bit intensive, if you have an event with a lot of repeats (n^n), but otherwise seems solid. If anybody needs this let me know and I can write it up a bit more thoroughly.

Anonymous’s picture

Renee S: I definitely need this. A detailed write-up would be very much appreciated.

Renee S’s picture

It's a but rough, let me know if you have questions :)

Clone the existing resource conflict rule. That rule finds any node that has an overlapping date. Obviously, we don't want to raise a conflict at that point: we want to make sure there are other things in common between the conflicting nodes, for example if the same room(s) is/are selected.

Remove the form error on the resource conflict rule loop. We'll add two rule components to it instead: one that loops through each selected room on the node, and then loop through each selected room on the conflicting node; and then a second inside the first, to compare those two values and set an error if they match.

First component:

The first component does the work of looping through all the different fields. Note: This is an n^n problem so probably won't scale well if you have a huge system with lots of concurrently-booked rooms. Call it "Resource Conflict: Check rooms":

Give it three parameters:
- Node: the new booking. Call it "resource_booking_new"
- Node: the conflicting node item. Call it "resource_booking_conflict"
- Form: The form to pass down to the next loop where we raise the error. Call it "resource_exists_notification"

Add two conditions:
- entity has field. Check "resource-booking-new" for the existence of the entityref booking field of your choice (eg resource-booking-new:field-rooms)
- entity has field. Check "resource-booking-conflict" for the existence of the entityref booking field of your choice

Add three actions:
1. Loop: This loops through the conflicting node and gets all the field items.
- List: the entityrefs on the conflicting node: resource-booking-conflict:[your field]
- Current list item: Call it "existing_room_booking"

2. Add a Loop in the first loop. This loops through the new booking and gets all the field items.
- List is resource-booking-new:[your field]
- Current list item, call it "new_room_booking"

3. Now, go and create the second component to do the comparison of these two values. We'll come back and add it as an action to the second loop when it's finished.

Second component:

This component does a straight-up data comparison, and if it finds a match, raises a form error.

Give it four parameters:
- Node: the conflicting node, call it Conflicting Node, "conflicting_node"
- [Entity]/Node: the first entity reference being compared (this might be a node id; but in our case we reference an ECK entity). Call it "eid-first"
- [Entity]/Node: the second entity reference being compared. Call it "eid-second"
- Form: the form to return the error. Call it "return_form".

Conditions:
- Data comparison: compare Entity/Node
- Data to compare [eid-first:id] - this may also be eid-first:nid if it's a node
- Data value: [eid-second:id]

Actions:
- Set an error on the form
- Parameter: form: [return-form]
- Form element: [return_form].
- Message: {your message}

Now go back to the fist component, and add the second component to the second loop.

Give it these parameter values:
- Conflicting Node: resource-booking-conflict
- First entity: new-meeting-room
- Second entity: existing-meeting-room
- Form: resource-exists-notification

Then, go back to the original rule.

Add an action to its loop [conflict list] the first component you made, giving its parameters as:

- New resource booking: [node]
- Existing resource booking: [conflict-list-item]
- Error: exists: [form]

Anonymous’s picture

Thanks so much for that walkthrough. It works for me.

I used this in conjunction with the technique by PascalAnimateur at #28 to print the titles of the nodes referenced by the conflicting entity reference fields in the error message. Since it's a multivalue field, I used the below code in the message configuration to loop through the values to print them:

Vehicle conflict detected: <?php
$array = array();
foreach ($conflicting_reservation->field_vehicle_reservation['und'] as $vehicle) {
$node = node_load($vehicle['target_id']);
$array[] = $node->title;
}
echo implode(', ', $array);
?>
 already reserved for <?php
print '<a href="';
?>[conflicting-node:url]<?php
print '">' . $conflicting_node->title . '</a>';
?>.

In case it might help anyone.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

bkosborne’s picture

Issue summary: View changes
bkosborne’s picture

Status: Active » Closed (fixed)

Documentation has been updated on how to setup a rule to do this: https://drupal.org/node/2090487.

perlgal’s picture

Hi Renee,

First, Thank you very much for the step by step instructions (#32)!

I am trying to follow the steps you have listed.
I cannot find "Form" in the list to add as a parameter while creating the first component.
How do I enable/add the third parameter that you refer to as Form?

Thanks

ArVar’s picture

Hi perlgal, you need to install "Rules Forms Support" first.
Another thing:
rhclayto in #33 has posted, how to print a summary of conflicts. Where is the point to get a proper conflicting_reservation variable? I tried different places in the rules setup, bot it didn't work so far.

Anyone, who has done it successfully?

Anonymous’s picture

I used the technique described by PascalAnimateur at #21 & #28. You add a 'Fetch entity by id' action before the 'Set a form validation error' action in your component that checks for conflicts. (If using the Renee S. method I used, this component is the one she describes at #32 under the heading 'Second component:'.) Within that 'Fetch entity by id' action, under the 'Provided variables' heading, 'Variable name' is set to 'conflicting_reservation'.

In short, follow the description used by Renee S in #32, but in the second component make a 'Fetch entity by id' action before the 'Set a form validation error' action (Entity type = node; Identifier = conflicting-node:nid; Fetched entity = conflicting_reservation). In the 'Set a form validation error' action, 'Message to display' can be simple such as PascalAnimateur's example (i.e., "Conflict detected with reservation [conflicting_reservation:title] !") or can print a comma-separated list of the values of multiple-value fields using the code I provided at #33.