02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

?><br />

CHAPTER 5 ■ ADD CONTROLS TO CREATE, EDIT, AND DELETE EVENTS<br />

Modifying the Full Event Display Method to Show Admin Controls<br />

Before the Edit button will be displayed, the _adminEntryOptions() method needs to be called from<br />

within the displayEvent() method. This is as simple as storing the return value of _adminEntryOptions()<br />

in a variable, $admin, <strong>and</strong> outputting that variable along with the rest of the entry markup.<br />

Add the following bold modifications to displayEvent() in the Calendar class:<br />

/**<br />

* Displays a given event's information<br />

*<br />

* @param int $id the event ID<br />

* @return string basic markup to display the event info<br />

*/<br />

public function displayEvent($id)<br />

{<br />

/*<br />

* Make sure an ID was passed<br />

*/<br />

if ( empty($id) ) { return NULL; }<br />

/*<br />

* Make sure the ID is an integer<br />

*/<br />

$id = preg_replace('/[^0-9]/', '', $id);<br />

/*<br />

* Load the event data from the DB<br />

*/<br />

$event = $this->_loadEventById($id); /*<br />

* Generate strings for the date, start, <strong>and</strong> end time<br />

*/<br />

$ts = strtotime($event->start);<br />

$date = date('F d, Y', $ts);<br />

$start = date('g:ia', $ts);<br />

$end = date('g:ia', strtotime($event->end));<br />

/*<br />

* Load admin options if the user is logged in<br />

*/<br />

$admin = $this->_adminEntryOptions($id);<br />

/*<br />

* Generate <strong>and</strong> return the markup<br />

*/<br />

return "$event->title"<br />

. "\n\t$date, $start&mdash;$end"<br />

187

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!