Re: Views filter rooms by occupacy

Steve Kessler <[email protected]> Mon, 19 Jan 2015 08:52:22 -0700
Newsgroups gmane.comp.php.drupal.support
Message-ID <CAHqNq+1neeGk=f-nP6mhZDut1dYMajP5LQPXFoQ9KAmcJ8SjeA@mail.gmail.com>
--===============6397792549693749194==
Content-Type: multipart/alternative; boundary=089e0102ee02d62b58050d034e2b

--089e0102ee02d62b58050d034e2b
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

If you require the relationship it should fix that.

On Monday, January 19, 2015, Llu=C3=ADs Forns <[email protected]> wrote:

> 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]
> <javascript:_e(%7B%7D,'cvml','[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.
>> Load the reserved room nids, through a normal DB query, then add a NOT I=
N
>> 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 =
ajuda.
>>
>>
>>
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>
>
> --
> *Ser freak no =C3=A9s imprescindible per ser inform=C3=A0tic, per=C3=B2 a=
juda.
> *La vida no ha de ser feli=C3=A7, ha de ser plena.
> *Abans d'imprimir aquest missatge, pensa en el medi ambient.
>


--=20
Steve Kessler
Owner and Lead Consultant
Denver DataMan, LLC
303-587-4428

--089e0102ee02d62b58050d034e2b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

If you require the relationship it should fix that.<span></span><br><br>On =
Monday, January 19, 2015, Llu=C3=ADs Forns &lt;<a href=3D"mailto:enboig@gma=
il.com">[email protected]</a>&gt; wrote:<br><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr">I was trying to make it without coding a new module; the st=
eps and the result are:<div><br></div><div>1. created a join, which is no r=
equired</div><div>I can list all the rooms with the nid of bookings (if ava=
liable).</div><div>2. Created a filter per dates:</div><div>only rooms with=
 bookings for that night are available</div><div>3. Filter for NULL related=
 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 c=
ontent. How can I limit to the join?</div><div><br></div><div><br></div></d=
iv><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">&lt;<a href=3D"javascript:_e(%7B=
%7D,&#39;cvml&#39;,&#39;[email protected]&#39;);" target=3D"_blank=
">[email protected]</a>&gt;</span>:<br><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex">
 =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&#39;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&#39;t check &quot;require this relationship&quot; 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&#39;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><font color=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>
      On 1/19/2015 9:37 AM, Llu=C3=ADs Forns wrote:<br>
    </div></div></div><div><div>
    <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 &quot;subview&quot; filter to selec=
t nodes
            &quot;not in (view of occupied rooms); but I haven&#39;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>*Ser freak no =C3=A9s imprescindible per ser=
 inform=C3=A0tic, per=C3=B2 ajuda.<br>*La vida no ha de ser feli=C3=A7, ha =
de ser plena.<br>*Abans d&#39;imprimir aquest missatge, pensa en el medi am=
bient.</div>
</div>
</blockquote><br><br>-- <br>Steve Kessler<div>Owner and Lead Consultant=C2=
=A0</div><div>Denver DataMan, LLC=C2=A0</div><div>303-587-4428</div><br>

--089e0102ee02d62b58050d034e2b--

--===============6397792549693749194==
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/ ]
--===============6397792549693749194==--