Jump to content

Recommended Posts

Posted

Hello,

I'm new to processwire, I've a small question.

I'm working on a small drama ticket booking website.

I've created Dramas, Cities & Theaters pages.

When I add a drama, I get a pages list select box for the theaters the drama is currently available for show.

Same goes for cities which I've already connected to the theaters page.

Now my drama page shows everything including the theaters it's available but I want to show the cities in which the drama is available.

But I don't know how to do it, can anyone help me?

For your reference,

fields for drama page are as follows:

drama_poster

drama_summary

drama_theatres

fields for theatres page are as follows:

theatre_city

theatre_total_seats

theatre_current_shows

All I want is, theatre_city should be listed as a list on drama page as a single drama can be available on multiple theaters.

Posted

Hi vineonardo

Do you mean this?

// In Template drama

// Get all theatres
foreach ($page->drama_theatres as $theatre) {
  echo $theatre->theatre_city;
}
  • Like 1
Posted

Ok let's find out why :)

The field "drama_theatres" can hold multiple theatres pages, is this correct?

To start debugging, you could output some values and check them.

For example:

$theatresIds = $page->drama_theatres;
echo $theatresIds; //Should outputting some ids like 1343|1345|1234
Posted

For now, I've this in my drama page template:

$theatresIds = $page->drama_theatres;
 
echo $theatresIds;
 
foreach ($theatresIds as $theatre) {
    echo $pages->get($theatre)->title;
}
 

but output is like this:

Cities: 1026|1027HomeHome

Can you please explain why?

Posted

$theatresIds is a string with the Id's of your theatres. You can't use foreach to iterate over a string.

That's why we first need to get the theatre pages with those ids:

$theatresIds = $page->drama_theatres;
// Get the theatre pages
$theatres = $pages->find("template=theatre, id={$theatresIds}");

Next step is to make sure we have found some pages:

if (count($theatres)) {
  foreach ($theatres as $t) {
    echo $t->theatre_city;
  }
} else {
  echo "No theatres found";

Are your theatre pages hidden?

Posted

For following code:

echo "Cities: "; 

$theatresIds = $page->drama_theatres;
// Get the theatre pages
$theatres = $pages->find("template=theatres, id={$theatresIds}");

if (count($theatres)) {
  foreach ($theatres as $t) {
    echo $t->theatre_city."<br/>";
  }
} else {
  echo "No theatres found";
}

 

I get output as:

Cities: 1018
1018

Where, 1018 is a city named "Thane".

Posted

Ah theatre_city is a Page field and not a Text.

Then you can write:

echo $t->theatre_city->title;
Posted

That suggests that you have Multiple selected on the Details tab then.

What happens if you do?

foreach($t->theatre_city as $theatre_city){
    echo $theatre_city->title . '<br />';
}
Posted

Since a theatre can only exist in one city, I don't think you should have multi as an option. You should set it to single and then change asm to a standard select. Then you'll be able to go back to $t->theatre_city->title

Let us know if that works.

Posted

I've understood what I really need. Ryan's example PW blog makes this easy to understand.

I've cities, theatres & shows.

Roughly speaking cities can be pages, theatres can be categories & shows can be articles.

Just as Ryan's example blog creates & connected categories & tags with articles, same system can work for my site as well.

All I need is, if user selects New York city, he/she should be able to see all the currently available shows & all the theatres in NY.

If he/she then clicks a theatre, eg. the Broadway theatre, then he/she should be able to see all the shows according to time of the show.

This is all I need. To save the data entry time, I want that admin should only need to post article(add show) & cities & theatres should display the newly added show.

Right now, I've to manually update cities & theatres which is wrong.

Can you guys please help me with this?

Posted

Guess I am a bit confused as to the page structure that you have set up.

You could do something like:

City 1

   Theatre 1

      Show 1

      Show 2

   Theatre 2

       Show 1

       Show 2

City 2

Then the admin just has to create a new child 'show'under the appropriate theatre.

There may be better ways to organize this depending on your needs on the front end. You could also follow Ryan's skyscrapers setup, and use some of that logic. Have you seen his demo:

http://processwire.com/skyscrapers/admin/

  • Like 1
Posted

@adrian

Thanks for the link.

I think the structure you suggested is something I should be implementing.

Right now I'm studying the skyscrapper right now, looks like I've got my solution.

Thanks a lot both of you, Adrian & Wanze for your time & helping me.

Posted

Glad that helps. Just one thought about the structure I proposed. That will cause you problems if the shows are "on tour" and will play in multiple theaters if different cities - you'd have to enter them several times. It might be better perhaps if you could define most of the details of each show under a "Shows" parent and then somehow specify just the time for each actual performance (perhaps a child under each show labelled as the show date where you define just the datetime and the theatre) - hopefully you get the idea.

The cool thing about PW is all the possibilities, but sometimes that can seem overwhelming too until you get the hang of it :)

Anyway, I am sure some playing around with the skyscrapers demo will give you some ideas!

Posted (edited)

Yes, the shows will be playing in multiple cities. That's exactly what I'm thinking about right now.

But as you said, spending some time with skyscrapers demo will give me some better ideas.

I guess my mistake was to make a wrong structure but now when I think, I want users to look for dramas based on their location, i.e. the city.

They should just select their city & currently nearby available dramas should display.

For this I need to have updatable city & theatre fields for drama.

I think Ryan's blog example will be more suitable.

Edited by vineonardo
Posted

Just wanted to correct a missunderstanding that I've read in the beginning... Haven't ready through all so sorry if you guys already solved it.

If you have a page field multiple or single it will be a PageArray or a Page reference, so you can iterate them with foreach. No need to get the pages through id's or anything like that, they're pages objects already.

foreach($page->drama_theatres as $drama){ 
    echo $drama->title;
}

or if a single page reference field

echo $page->drama_theatre->title;
  • Like 1
Posted

I think within the entry for each show, you should define the theaters where it will play, not the cities at all. Your template code can then get the city from the theatre table/page. Make sense?

Anyway, will leave you to it now :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...