Stumped on two issues
#1
Posted 15 September 2011 - 11:18 AM
I have built most of a site with processwire and I'm thrilled by the power of it but I've encountered two issues that I can't get my head around.
The site is a tourist accommodation site in which individual cottage owners list their properties for rent during tourist months. They all rent from Saturday to Saturday through the summer but start and end dates can vary. Each property owner edits and keeps track of availability on their individual sites where an availability table displays the period (e.g. September 17 to September 24) cost, deposit and whether it's booked or not.
Problem 1: each member edits their own info and I figure the owner role would be the best way to allow each member to edit only their page but how to set that up? Do I have to create the user account, log in under that name, set up the page for them? I'd like to be able to set a user as owner of a page but that doesn't seem possible.
Probem 2: How to set up availability? The booked or not booked is easy, a simple checkbox field would do but how can I set up a fieldset with a date range, cost, deposit cost and checkbox for if it's available and make it searchable? We need site visitors, looking for accommodation to be able to search a particular date range (September 17 to 24) and have all cottages with availability during the time period show up in search results. Of course there's also the fact that some cottage owners have multiple units available for rent.
Does any of this make sense and is there a way it can be done in a way that will be somewhat user friendly to property owners that are not computer savvy?
Any insight would be very appreciated.
#2
Posted 16 September 2011 - 08:37 AM
Problem 1: each member edits their own info and I figure the owner role would be the best way to allow each member to edit only their page but how to set that up? Do I have to create the user account, log in under that name, set up the page for them? I'd like to be able to set a user as owner of a page but that doesn't seem possible.
With regard to an owner role for editing: there is no owner role in ProcessWire at present. Though the framework is in place to easily support one (and there used to be one in earlier versions). If you are seeing an owner role in your system, you may want to get the latest version of ProcessWire (2.1) as a lot has changed. But unless your site is very small scale and the owners are a trusted group of peers, I wouldn't suggest setting them up with admin account… you certainly could, but you no longer control the experience. And the experience in PW admin is tailored more towards general site management than a specific purpose like yours. Instead, it's better to give them forms on the front-end where you can tailor the experience to the need and control access. ProcessWire's API is designed for this usage and makes this sort of thing much easier. For instance, you might want to reserve some fields on your property page for you to manage, and others for the user to manage. You could have a page reference field to /processwire/access/users/ that would enable you to select what user(s) had access to change what pages.
<?php
// $page->owner is a page reference field you have added
if($page->owner->id == $user->id) {
// user may edit
// output a form of just the fields you want them to edit and/or process them
} else {
// user may not edit
}
The owner field doesn't necessarily need to be on the active page (like if you don't want to manage this stuff on a page-by-page basis). It could be on some parent. That's up to you to determine what access check works best for you.
Probem 2: How to set up availability? The booked or not booked is easy, a simple checkbox field would do but how can I set up a fieldset with a date range, cost, deposit cost and checkbox for if it's available and make it searchable? We need site visitors, looking for accommodation to be able to search a particular date range (September 17 to 24) and have all cottages with availability during the time period show up in search results. Of course there's also the fact that some cottage owners have multiple units available for rent.
The way I've accomplished this on other sites is to build a custom Fieldtype for managing rates. Unfortunately it's not code that I can share because I don't have permission to. But Fieldtypes that extend FieldtypeMulti are a great fit for this sort of need. PW supports Fieldtypes with any number of subfields, and in any quantity. This is one of the reasons (of many) why PW uses one table per field, rather than one table per template. Every subfield is automatically searchable by PW's selector engine (though you do want to choose the appropriate indexes in your DB schema to keep your searches fast). For an example, a selector to perform the search you inquired about might look like this:
<?php
$date_from = strtotime("10/10/2011");
$date_to = strtotime("10/24/2011");
$max_cost = 500;
$cottages = $pages->find("rates.available=1, rates.date_from>=$date_from, rates.date_to<=$date_to, rates.cost<=$max_cost");
Of course, you can add in any other fields from your 'cottage' template to search at the same time.
As a good starting point, I would suggest looking at the existing FieldtypeMulti types, like FieldtypeComments and FieldtypeFile. These give some insight on how to structure a Fieldtype to carry more complex data types (with any number of subfields) in any quantity. If you are comfortable attempting a custom Fieldtype I'll be happy to help with any questions you have along the way.
#3
Posted 19 September 2011 - 03:54 PM
As for the search, I think I understand what you're saying and I will see if I can get my frontal lobes around it. Not sure how to go about building a custom fieldtype but will look where you suggest and see what I can make of it.
Thanks again.
#4
Posted 11 November 2011 - 03:02 PM
#5
Posted 14 November 2011 - 11:25 AM
I suggest it would be good to hire a programmer to build this for your client. Or, you may be able to find an existing web service or system that can be adapted to your needs. But chances are that it ultimately comes down to putting in the time to code it the way you and your client want it. I would offer to help you more in this regard except that I'm under a non-compete agreement that crosses over with the tools you are wanting to build. However, there may be others here that you could hire to help build this.
#6
Posted 14 November 2011 - 11:42 AM
I doubt a little cottage rental website in Ontario Canada is competition to your clients but I respect your ethical integrity in not wishing to violate your commitment to them Ryan. Thanks for your help on this.
Anyone else who might be interested, please post or PM me and I'll give you details for you to quote. This is a serious offer and time is becoming more of an issue. Thanks in advance.
#7
Posted 14 November 2011 - 08:52 PM
#8
Posted 16 November 2011 - 09:55 AM
I have been thinking of this problem in terms of integrating it into processwire in order to make use of the current templates I built for displaying search results. In order to do that I think I would need a custom fieldtype to store dates, fees and the booked/not booked toggle. It seems, as you and Ryan have both suggested, I need to think instead of a completely separate system that I can include on the availability page. It would solve the problem of user/owner login and editing but would mean I need to rethink the search unless I can get processwire to handle the search with an independent booking system.
I will contact Wayne and reference your name by way of introduction if you don't mind.
#10
Posted 01 December 2011 - 01:01 PM
I decided to go the bootstrap way. I found a booking system that uses the Smarty template system. It's very robust, far more so than I need or want but with the templates, which are html files I can include or exclude what I want.
Now of course I have a new problem. I think it needs a new thread.
Thanks for the help Martin and Ryan.
#11
Posted 22 November 2012 - 02:19 PM
To keep things short, I ended up putting the site up using a 3rd party booking system to track availability for the members and it worked fine-ish and everyone was happy. The big problem was that it wasn't searchable in the way we wanted so I never really let it go. Once Repeater fields were introduced into processwire I came back to the site and built a user interface for members that allowed booking info to be stored in the database, making it searchable...with the right selector. Now my problem is:
The availability search, which I talked about in the first post of this thread mostly works. A user inputs a date range and it finds all pages with availability in that range, almost.
I have this:
$matches = $pages->find("template=property_availability, rental_period.date_from>=$fromvalue, rental_period.date_to<=$tovalue, rental_period.booked=1, include=hidden");But it returns any page with booked=1 even when the date is not in the range searched. I've tried a number of things but so far nothing's worked.
Or am I missing something easy. I feel like I'm close and can finally put this one to bed.
Disregard that. Not working but not for reason stated above.
#12
Posted 24 November 2012 - 09:40 AM
#13
Posted 26 November 2012 - 10:59 AM
Thanks for the feedback. The date input is done using a javascript pop up similar to the one built-in to pw and I made sure the the format matched the format stored in the repeater fields. The selector, at least that part, does work. When searching for dates outside the range, it returns no results found which is expected.
The only problem, which is killing me because it does seem like it should work and is the last part of the project, is that it returns any property with a booked status regardless of the date searched (if it's within the available range). My layman's theory is that it's not seeing each rental_period repeatable item as separate and is treating them as one. In other words "the dates are present and it says booked so it's valid" even though week 1 is booked and the date searched is week 8. Is that possible?
On the other point, I agree, we keep the repeater items contained. There's never more than 10 items per property and at the end of each season they are turned over to the 10 items for next season. What would you say is the upper limit for repeaters? I use them on another site and it's crossed my mind to wonder how many I can add before it becomes a problem.
#14
Posted 27 November 2012 - 12:01 PM
My layman's theory is that it's not seeing each rental_period repeatable item as separate and is treating them as one. In other words "the dates are present and it says booked so it's valid" even though week 1 is booked and the date searched is week 8. Is that possible?
Your theory is correct. When you search fields in a repeater, it is returning the pages that match, not the individual repeater items that match. So your search will be returning pages that have at least one of the repeater items matching your search. Once you've got one of those pages, you'd still need to determine which of the repeater items matched.
What you may want to do is aim to match the individual repeater items instead.
$matches = $pages->find("template=repeater_rental_period, date_from>=$fromvalue, date_to<=$tovalue, booked=1, include=all");Then there's the question of how to determine which 'property' pages have the items you matched above. This is a relatively uncommon scenario, so I don't yet have a pretty solution for this. But you can determine the the property (as in real estate property) from each matching repeater item like this:
foreach($matches as $item) {
$property = $pages->get((int) substr($item->parent->name, 9));
if(!$property->viewable()) continue; // skip if property is unpublished or something
// now you have the $property and the matching repeater $item
}That solution comes via Soma, Diogo and Antti:
http://processwire.c..._200#entry19567
I'll come up with something built-in for this soon, but until then the above is probably the best way to go.
#16
Posted 03 December 2012 - 11:02 AM
The solution above works great...unless someone searches for a date range of more than 1 week. The site does cottage rentals for 1 week at a time but on occasion a renter does a 2 week stay. If searching for e.g. 07/13/2013 to 07/27/2013 the search returns incorrect results again.
So, what would be easier: restricting searches to 1 week at a time which I can do with the popup calendar? or is there a way to adjust the selector or filter results to allow for a extended span of time?
Either would be ok with me but I have a pathological urge to try to be as thorough as possible.
#17
Posted 04 December 2012 - 10:39 AM
$fromvalue ="2013-07-13"; $tovalue = "2013-07-27";
or
$fromvalue = strtotime("2013-07-13");
$tovalue = strtotime("+2 weeks", $fromvalue);
I don't yet have a pretty solution for this.
Also wanted to add, I have a better solution for this now (on the latest commit to the dev branch). You can now do this, where $item is a repeater item:
$property = $item->getForPage();
#18
Posted 04 December 2012 - 01:46 PM
I don't know if I'm making sense. I have restricted the search to only one rental term but that may frustrate anyone who might be looking for a longer stay.
edit: BTW
$property = $item->getForPage();great news!!
#19
Posted 04 December 2012 - 03:43 PM
A1: 2013-01-05 ... 2013-01-12, cottage A, booked: 0 B1: 2013-01-05 ... 2013-01-12, cottage B, booked: 0 A2: 2013-01-12 ... 2013-01-19, cottage A, booked: 1 B2: 2013-01-12 ... 2013-01-19, cottage B, booked: 0
Now if you're targeting the repeater items with a selector like this (left some details out) "date_from>=$fromvalue, date_to<=$tovalue, booked=0" to find out which cottages are available from 2013-01-05 to 2013-01-19, you'd get items A1, B1 and B2. Then, using the method Ryan described in post #14 of this thread, it's easy to find those items correspond to cottages A and B. But this does not mean both of those cottages are available for the whole period, just like you're saying.
So, if the rental period (say 14 days) spans over more than one rental term (7 days), it's necessary to repeat the procedure for each of the terms individually and only then you're able to see which cottages appear in the results for all the terms. Combining all of the above, I'm suggesting something like this (haven't tested so no guarantees):
// rental terms of the desired period in a handy structure
$termsInPeriod = array(
array(
'start' => '2013-01-05',
'end' => '2013-01-12'
),
array(
'start' => '2013-01-12',
'end' => '2013-01-19'
)
);
$cottages = array();
foreach($termsInPeriod as $term) {
// find matches for this term
$matches = $pages->find("template=repeater_rental_period, date_from>={$term['start']}, date_to<={$term['end']}, booked=0, include=all");
// no matches this round --> no matches on the whole, no matter what may have been found before
if(!count($matches)) {
$cottages = array();
break;
}
// array to hold found cottages for this term
$termCottages = array();
foreach($matches as $item) {
$property = $pages->get((int) substr($item->parent->name, 9));
if(!$property->viewable()) continue; // skip if property is unpublished or something
// now you have the $property and the matching repeater $item
$termCottages[] = $item->id;
}
// some results from previous rounds?
// - yes, then find out common matches
// - nope, first round --> use the results as is
if(count($cottages)) $cottages = array_intersect($cottages, $termCottages);
else $cottages = $termCottages;
}
In the end $cottages should hold all the cottages available for the given period. I'm using $item->id because of the array_intersect(). I'll leave it to you to form a structure like $termsInPeriod from your input - and probably this is fuel for your own thinking at most anyway.
My modules: Selector Test | After Save Actions | References Tab ~ Other: Tests for ProcessWire core (work in progress)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













