Jump to content

Movie website - session times by day


Marty Walker
 Share

Recommended Posts

Well it's been a while since I've been stuck on something and when I am it consistently appears to be with dates.

I'm working on site for a cinema. Each movie has it's own page with a start and end-of-run date and a repeater field for session times.

Screen-Shot-2015-03-27-10-14-50.png

--

Screen-Shot-2015-03-27-10-09-17.png

So that's all fine and well for the individual movie pages.

BUT I'm struggling with request of theirs to group all the movie sessions under days. eg:

Friday 27th:

Birdman: 2pm 5pm 7pm

Theory of Everything: 3pm 4pm 8pm

etc

If I try to output all the start dates I get multiple days (of course, because there are multiple movies on each day).

So I'm trying to work out how to limit the output of the days to one instance and then list all the movies and session start times underneath that.

No point showing any code because mine is ass-about.

Thanks for any help

Link to comment
Share on other sites

shouldn't be that hard; i've done some similar things with complex displays really similar to that.

this is untested and assumes a lot, not knowing the names of fields etc..

<?
function listMovies() {
    // get all of the movies
    $movies = wire("pages")->find("template=repeater_movie_times")
    $dates = array();
    
    $out ="";
    // find the array of dates for all movies
    foreach ($movies as $movie) {
        $dates[]= date("U", $movie->getUnformatted("date"));
    }

    $dates = array_unique($dates);
    asort($dates);

	// for testing
	// print_r($dates);
	// print_r($movies);

    foreach($dates as $key => $date) {

        $dateDisplay = date("l, F jS", $date); 
        // l = A full textual representation of the day of the week
        // F = A full textual representation of a month, such as January or March
        // j = Day of the month without leading zeros
        // S = st, nd, rd, th

        // Output the date
        $out .="<h2>{$dateDisplay}</h2>";

        // find the array of movies this day and put into new array $date_movies
        $date_movies = $movies->find("date=$date");
        	// print_r($date_movies);

        // loop through the movies for this day and add the times to the array
        $times = array();
        foreach ($date_movies as $date_movie) {
            $times[]= $date_movie->start_time;
        }
        $times = array_unique($times);
        asort($times);
        	// print_r($times);

        // loop through the times and find movies for the time
        foreach($times as $key => $time) {
            
            // Output the time
            $out .="<h3>{$time}</h3>";

            // filter only the movies for this time, from the $date_movies array.
            $time_movies = $date_movies->find("start_time=$time");
            	// print_r($time_movies);
                echo '<ul>';
                foreach($time_movies as $m) {
                    $movie = $m->getForPage();
                        $out .="<li>{$movie->title}</li>";
                } // end foreach movies
                echo '</ul>';

        } // end foreach times
    
    } // end foreach dates

return $out;
}
?>
  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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