modify on-air now php script

I'm looking for a php script that will display an on-air schedule for a radio station I work for. Ray_Paseur did the heavy lifting and wrote the following code that accurately switches my images based on what time it is, but I also need to display:

a) the title of the show (as a hyperlink),
b) the time the show begins and ends,
c) the following show (as a hyperlink).

Plus, this script needs to include the entire week (weekend programs and weekday programs are different).


Here's Ray_Paseur's script, which masterfully rotates my images based on the time of day:
 
<?php // RAY_temp_billypilgrim32.php
error_reporting(E_ALL);


// SET THE CORRECT TIMEZONE
date_default_timezone_set('America/Chicago');


// A FUNCTION TO RETURN THE IMAGE URL BASED ON A GIVEN TIME
function imageUrl($hhmm='now')

{

    // DEFINE A PROGRAM CLASS
    if (!class_exists('Program'))
    {
        Class Program
        {
            public function __construct
            ( $a // START TIME
            , $z // END TIME
            , $i // IMAGE URL
&#9;&#9;&#9;, $t // Show Title
            )
            {
                $this->a = $a;
                $this->z = $z;
                $this->i = $i;
            }
        }
    }

    // MAKE AN ARRAY OF PROGRAM OBJECTS
    $programs = array
    ( new Program('0000', '0200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg')
    , new Program('0200', '0400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/shows/radionews.gif')
    , new Program('0400', '0600', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg')
    , new Program('0600', '0800', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg')
    , new Program('0800', '1000', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host4.jpg')
    , new Program('1000', '1200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host5.jpg')
    , new Program('1200', '1400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host6.jpg')
    , new Program('1400', '1600', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg')
    , new Program('1600', '1800', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host7.jpg')
    , new Program('1800', '2000', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host8.jpg')
    , new Program('2000', '2200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host9.jpg')
    , new Program('2200', '2400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host10.jpg')
    )
    ;

    // NORMALIZE THE DATETIME STRING
    $hhmm = date('hi', strtotime($hhmm));

    // DETERMINE THE IMAGE NEEDED
    foreach ($programs as $timeslot)
    {
        if ($hhmm >= $timeslot->a)
        {
            if ($hhmm <= $timeslot->z)
            {
                $url = $timeslot->i;
            }
        }
    }

    // CREATE THE IMAGE TAG
    $tag = <<<TAG
    <img alt="Host Image" title="$hhmm" src="$url" />
TAG;

    return $tag;
}

// TEST THE FUNCTION
echo '<br clear="all" />' . imageurl();
echo '<br clear="all" />' . imageurl('now+37 minutes');
echo '<br clear="all" />' . imageurl('now+237 minutes');
?>

Open in new window


Thanks!
billypilgrim32Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
In my initial post, the strategy was to create an array of objects.  My thinking worked along the lines of "What else should these objects contain?"  Your line 23 giving a title plays nicely into the design pattern. I think we know the time the show begins and ends from the $a and $z arguments that are passed to the class constructor.  I think the only remaining issue is to find the object in the array that starts after the current start time.  We can either assume that the array is ordered by start time (probably a brittle assumption) or we can use USort() to order the array of objects by start times and end times.  

I am going to bed now, and I will look at it again in the morning.   However there are many wise and clever developers here at EE who may be able to get a quick answer overnight.

Best regards, ~Ray
0
billypilgrim32Author Commented:
Appreciate all your hard work Ray---the challenge for me is to somehow deconstruct this brilliant piece of coding. I'm just an HTML guy, so all of this looks like Mandarin Chinese to me.
0
Ray PaseurCommented:
I'll look at this again.  If it still looks chinese to you, then you really should consider hiring a professional developer to help you with it.  Nothing you want is "hard" but it is time-consuming and a developer should be paid for the time it will take to do all you need to have done.  If this does not have any economic value and you're just using it as a learning tool, then consider getting this excellent little book and give yourself a few weeks to work through the examples.  It will not make you a pro, but it will give you some foundation in how PHP and MySQL work together.
http://www.sitepoint.com/books/phpmysql4/
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Ray PaseurCommented:
This is as far as I can get tonight.  But hopefully it will provide some inspiration for you or your developer.  Best regards, ~Ray
<?php // RAY_temp_billypilgrim32.php
error_reporting(E_ALL);


// SET THE CORRECT TIMEZONE
date_default_timezone_set('America/Chicago');


// DEFINE A PROGRAM CLASS
Class Program
{
    public function __construct
    ( $a // START TIME
    , $z // END TIME
    , $i // IMAGE URL
    , $t // TITLE
    )
    {
        $this->a = $a;
        $this->z = $z;
        $this->i = $i;
        $this->t = $t;
    }
    public function getTitle() { return $this->t; }
    public function getTimes() { return array('a' => $this->a, 'z' => $this->z); }
    public function getImage() { return $this->i; }
}


// MAKE AN ARRAY OF PROGRAM OBJECTS
$programs = array
( new Program('0000', '0200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg', 'Title 0000')
, new Program('0200', '0400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/shows/radionews.gif', 'Title 0200')
, new Program('0400', '0600', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg', 'Title 0400')
, new Program('0600', '0800', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg', 'Title 0600')
, new Program('0800', '1000', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host4.jpg', 'Title 0800')
, new Program('1000', '1200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host5.jpg', 'Title 1000')
, new Program('1200', '1400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host6.jpg', 'Title 1200')
, new Program('1400', '1600', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg', 'Title 1400')
, new Program('1600', '1800', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host7.jpg', 'Title 1600')
, new Program('1800', '2000', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host8.jpg', 'Title 1800')
, new Program('2000', '2200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host9.jpg', 'Title 2000')
, new Program('2200', '2400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host10.jpg', 'Title 2200')
)
;

// A FUNCTION TO RETURN THE IMAGE URL BASED ON A GIVEN TIME
function imageUrl($hhmm='now', $programs=array())
{
    // NORMALIZE THE DATETIME STRING
    $hhmm = date('hi', strtotime($hhmm));

    // DETERMINE THE IMAGE NEEDED
    foreach ($programs as $timeslot)
    {
        if ($hhmm >= $timeslot->a)
        {
            if ($hhmm <= $timeslot->z)
            {
                $url = $timeslot->getimage();
            }
        }
    }

    // CREATE THE IMAGE TAG
    $tag = <<<TAG
    <img alt="Host Image" title="$hhmm" src="$url" />
TAG;

    return $tag;
}

// TEST THE FUNCTION
echo PHP_EOL . '<br clear="all" />' . imageurl('now', $programs);
echo PHP_EOL . '<br clear="all" />' . imageurl('now+37 minutes', $programs);
echo PHP_EOL . '<br clear="all" />' . imageurl('now+237 minutes', $programs);


// SHOW THE PROGRAM NAMES AND THE TIMES
foreach ($programs as $thing)
{
    // CAST THE OBJECT PROPERTY AS STRING VARIABLE
    $t = (string)$thing->getTitle();

    // USE THE OBJECT PROPERTY AS AN ARRAY VARIABLE
    $x = $thing->getTimes();
    echo PHP_EOL . '<br clear="all" />' . "$t STARTS AT {$x['a']} AND ENDS AT {$x['z']}";
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
Ray PaseurCommented:
Recommend accept this.  It has a tested and working code sample that shows exactly how to solve the problem:
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_27634413.html#a37769179
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.