Re: Views filter rooms by occupacy
LluĂs Forns <[email protected]> Mon, 19 Jan 2015 16:48:14 +0100
| Newsgroups | gmane.comp.php.drupal.support |
|---|---|
| Message-ID | <CAGTZhB5_KfzMzqZ8wEDTam3mCQTbC-48N-Wv0k2x9iLVeZb3PA@mail.gmail.com> |
--===============1223150121146126907== Content-Type: multipart/alternative; boundary=047d7bacc2c04d7209050d0341af --047d7bacc2c04d7209050d0341af Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I was trying to make it without coding a new module; the steps and the result are: 1. created a join, which is no required I can list all the rooms with the nid of bookings (if avaliable). 2. Created a filter per dates: only rooms with bookings for that night are available 3. Filter for NULL related booking nid No room listed I think the filter should affect only joined content, but it it is affecting the full content. How can I limit to the join? 2015-01-19 16:07 GMT+01:00 Jamie Holly <[email protected]>: > How are you associating the rooms content type to the reservations one? > If you're using entity reference, then you would want to create a > relationship with the reservations content type through that reference > field. Make sure you don't check "require this relationship" then add a > filter so that the related node (reservations) nid is NULL. > > The other option is in a custom module, using hook_views_query_alter. Loa= d > the reserved room nids, through a normal DB query, then add a NOT IN > condition to the list of nids. Here's the documentation on that hook: > > > https://api.drupal.org/api/views/views.api.php/function/hook_views_query_= alter/7 > > Jamie Hollyhttp://hollyit.net > > On 1/19/2015 9:37 AM, Llu=C3=ADs Forns wrote: > > I have a site with 2 content types: rooms and reservations. I want to > list all the rooms without a reservation for an interval, and also for > services, capacity, .... > > I tried creating a view with a PHP filter to check free rooms, but then > if the page lists 10 rooms, sometimes there are 7, 2, or 0; because the > filter lists the 10 rooms and after remove the occupied ones. > > I have tried to create a "subview" filter to select nodes "not in (view > of occupied rooms); but I haven't find a way to do so. > > Any idea of how to accomplish this? > > thanks > -- > *Ser freak no =C3=A9s imprescindible per ser inform=C3=A0tic, per=C3=B2 a= juda. > > > > > -- > [ Drupal support list | http://lists.drupal.org/ ] > --=20 *Ser freak no =C3=A9s imprescindible per ser inform=C3=A0tic, per=C3=B2 aju= da. *La vida no ha de ser feli=C3=A7, ha de ser plena. *Abans d'imprimir aquest missatge, pensa en el medi ambient. --047d7bacc2c04d7209050d0341af Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">I was trying to make it without coding a new module; the s= teps and the result are:<div><br></div><div>1. created a join, which is no = required</div><div>I can list all the rooms with the nid of bookings (if av= aliable).</div><div>2. Created a filter per dates:</div><div>only rooms wit= h bookings for that night are available</div><div>3. Filter for NULL relate= d booking nid</div><div>No room listed</div><div><br></div><div>I think the= filter should affect only joined content, but it it is affecting the full = content. How can I limit to the join?</div><div><br></div><div><br></div></= div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">2015-01-19 16= :07 GMT+01:00 Jamie Holly <span dir=3D"ltr"><<a href=3D"mailto:hovercraf= [email protected]" target=3D"_blank">[email protected]</a>></sp= an>:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border= -left:1px #ccc solid;padding-left:1ex"> =20 =20 =20 <div bgcolor=3D"#FFFFFF" text=3D"#000000"> <div>How are you associating the rooms content type to the reservations one? If you're using entity reference, then you would want to create a relationship with the reservations content type through that reference field. Make sure you don't check "require this relationship" then add a = filter so that the related node (reservations) nid is NULL. <br> <br> The other option is in a custom module, using hook_views_query_alter. Load the reserved room nids, through a normal DB query, then add a NOT IN condition to the list of nids. Here's the documentation on that hook:<br> <br> <a href=3D"https://api.drupal.org/api/views/views.api.php/function/hook_vie= ws_query_alter/7" target=3D"_blank">https://api.drupal.org/api/views/views.= api.php/function/hook_views_query_alter/7</a><span class=3D"HOEnZb"><font c= olor=3D"#888888"><br> <br> <pre cols=3D"72">Jamie Holly <a href=3D"http://hollyit.net" target=3D"_blank">http://hollyit.net</a></pr= e></font></span><div><div class=3D"h5"> On 1/19/2015 9:37 AM, Llu=C3=ADs Forns wrote:<br> </div></div></div><div><div class=3D"h5"> <blockquote type=3D"cite"> <div dir=3D"ltr"> <div>I have a site with 2 content types: rooms and reservations. I want to list all the rooms without a reservation for an interval, and also for services, capacity, ....<br> </div> <div><br> </div> <div>I tried creating a view with a PHP filter to check free rooms, but then if the page lists 10 rooms, sometimes there are 7, 2, or 0; because the filter lists the 10 rooms and after remove the occupied ones.<br clear=3D"all"> <div><br> </div> <div>I have tried to create a "subview" filter to selec= t nodes "not in (view of occupied rooms); but I haven't find a= way to do so.</div> <div><br> </div> <div>Any idea of how to accomplish this?</div> <div><br> </div> <div>thanks</div> -- <br> <div>*Ser freak no =C3=A9s imprescindible per ser inform=C3=A0tic, per=C3=B2 ajuda.<br> </div> </div> </div> <br> <fieldset></fieldset> <br> </blockquote> <br> </div></div></div> <br>--<br> [ Drupal support list | <a href=3D"http://lists.drupal.org/" target=3D"_bla= nk">http://lists.drupal.org/</a> ]<br></blockquote></div><br><br clear=3D"a= ll"><div><br></div>-- <br><div class=3D"gmail_signature">*Ser freak no =C3= =A9s imprescindible per ser inform=C3=A0tic, per=C3=B2 ajuda.<br>*La vida n= o ha de ser feli=C3=A7, ha de ser plena.<br>*Abans d'imprimir aquest mi= ssatge, pensa en el medi ambient.</div> </div> --047d7bacc2c04d7209050d0341af-- --===============1223150121146126907== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- [ Drupal support list | http://lists.drupal.org/ ] --===============1223150121146126907==--