I have two files:
File get-calendar.php
namespace genesis\\calendar;
class Calendar {
var $calendar;
public function Get_calendar($date,$ministries,$limit) {
global $mysqli;
$query = 'SELECT calendar.event_name, calendar.calendar_id, calendar.ministry_id, calendar.start_date, venue.venue_name, ministry.ministry_name FROM calendar LEFT JOIN venue ON calendar.venue_id = venue.venue_id LEFT JOIN ministry ON calendar.ministry_id = ministry.ministry_id WHERE DATE(start_date) ' . $date . ' ';
if ($ministries !== 'all') {
$query .= 'AND calendar.ministry_id = "' . $ministries . '" ';
}
$query .= 'ORDER BY calendar.start_date ASC';
if ($limit !== 'all') {
$query .= ' LIMIT ' . $limit;
}
$result = $mysqli->query($query);
if ($result) {
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
$this->calendar[] = $row;
}
$result->close();
} else {
$this->calendar = NULL;
}
return $this->calendar;
}
}
File set-calendar.php
use genesis\\calendar as C;
require_once($_SERVER['DOCUMENT_ROOT'] . "/genesis/data/class-get-calendar.php");
class Calendar {
var $date;
var $ministries;
var $limit;
var $calendar;
var $num_results;
function __construct($date,$ministries = 'all',$limit) {
// Validate dates
if (isset($_GET['from']) || isset($_GET['to'])) {
if (isset($_GET['from'])) {
if ($_GET['from'] == 'From') {
$from = NULL;
} else {
$from = strtotime($_GET['from']);
if (checkdate(date('m', $from),date('d', $from),date('Y', $from))) {
$from = mysql_real_escape_string($_GET['from']);
} else {
$from = NULL;
}
}
}
if (isset($_GET['to'])) {
if ($_GET['to'] == 'To') {
$to = NULL;
} else {
$to = strtotime($_GET['to']);
if (checkdate(date('m', $to),date('d', $to),date('Y', $to))) {
$to = mysql_real_escape_string($_GET['to']);
} else {
$to = NULL;
}
}
}
if (!is_null($from) && !is_null($to)) {
$this->date = 'BETWEEN "' . $from . '" AND "' . $to . '"';
} else if (!is_null($from) && is_null($to)) {
$this->date = '>= "' . $from . '"';
} else if (is_null($from) && is_null($to)) {
$this->date = '>= "' . date('Y-m-d') . '"';
}
} else {
if (!is_numeric($date)) {
$this->date = date('Y-m-d');
} else {
if (checkdate(date('m', $date),date('d', $date),date('Y', $date))) {
$this->date = $date;
} else {
$this->date = date('Y-m-d');
}
}
if (!is_null($this->date)) {
$this->date = '>= "' . $this->date . '"';
} else {
$this->date = '>= "' . date('Y-m-d') . '"';
}
}
// Validate ministry ID
if (isset($_GET['ministry']) && is_numeric($_GET['ministry'])) {
$this->ministries = mysql_real_escape_string($_GET['ministry']);
} else if (is_int($ministries) || $ministries == 'all') {
$this->ministries = $ministries;
} else {
$this->ministries = 'all';
}
// Validate limit
if (is_int($limit)) {
$this->limit = $limit;
} else {
$this->limit = 'all';
}
}
public function Set_calendar($location) {
$calendar = new C\\Calendar();
$calendar = $calendar->Get_calendar($this->date,$this->ministries,$this->limit);
if ($calendar == NULL) {
$this->calendar = '';
} else {
if ($location == 'main') {
if (!empty($calendar)) {
$this->calendar = '<table>
<thead>
<tr>
<th>Event</th>
<th>Date</th>
<th>Time</th>
<th>Venue</th>
<th>Ministry</th>
</tr>
</thead>
<tbody class="vcalendar">';
foreach ($calendar as $key => $value) {
$this->calendar .= '<tr class="vevent">';
$this->calendar .= '<td><a class="url uid summary" href="/calendar/event.php?id=' . $calendar[$key]['calendar_id'] . '&ministry=' . $calendar[$key]['ministry_id'] . '">' . $calendar[$key]['event_name'] . '</a></td>';
$date = date('M. j, Y',strtotime(substr($calendar[$key]['start_date'],0,10)));
$time = date('g:ia',strtotime(substr($calendar[$key]['start_date'],11,8)));
$this->calendar .= '<td><span class="dtstart"><abbr class="value" title="' . date('Y-m-d',strtotime(substr($calendar[$key]['start_date'],0,10))) . 'T' . date('H:i:s',strtotime(substr($calendar[$key]['start_date'],11,8))) . '">' . $date . '</abbr></span></td>';
$this->calendar .= '<td>' . $time . '</td>';
$this->calendar .= '<td class="location">' . $calendar[$key]['venue_name'] . '</td>';
$this->calendar .= '<td class="organiser">' . $calendar[$key]['ministry_name'] . '</td>';
$this->calendar .= '</tr>';
}
$this->calendar .= '</tbody>
</table>';
} else {
$this->calendar = '<h2>There are no events at this time</h2><p>Please check back often.</p>';
}
} else if ($location == 'sidebar') {
$this->calendar = '<div id="calendar">';
if (empty($calendar)) {
$this->calendar .= '<p>There are no events at this time.</p>';
} else {
foreach ($calendar as $key => $value) {
$this->calendar .= '<div class="calendar-event">';
$number_date = substr($calendar[$key]['start_date'],8,2);
if ($number_date < 10) {
$number_date = substr($number_date,1,1);
}
$date = date('F j, Y',strtotime(substr($calendar[$key]['start_date'],0,10)));
$time = date('g:i A',strtotime(substr($calendar[$key]['start_date'],11,8)));
$this->calendar .= '<div class="calendar-event-numberdate">' . $number_date . '</div>';
$this->calendar .= '<div class="calendar-event-title"><a href="/calendar/event.php?id=' . $calendar[$key]['calendar_id'] . '&ministry=' . $calendar[$key]['ministry_id'] . '">' . $calendar[$key]['event_name'] . '</a></div>';
$this->calendar .= '<div class="calendar-event-description">';
$this->calendar .= '<div class="calendar-event-description-date">' . $date . '</div>';
$this->calendar .= '<div class="calendar-event-description-time">' . $time . '</div>';
$this->calendar .= '<div class="calendar-event-description-location">' . $calendar[$key]['venue_name'] . '</div>';
$this->calendar .= '</div>
</div>';
}
$this->calendar .= '<p class="small-links"><a href="/calendar/';
if ($this->ministries !== 'all') {
$this->calendar .= 'index.php?ministry=' . $calendar[$key]['ministry_id'];
}
$this->calendar .= '">View More ';
if ($this->ministries !== 'all') {
$this->calendar .= '<br />' . $calendar[$key]['ministry_name'] . ' ';
}
$this->calendar .= 'Events >></a></p>';
}
$this->calendar .= '</div>';
}
}
return $this->calendar;
}
}
I want to make the Get_calendar function in get-calendar.php private, but when I do, it throws me an error. I know it has to do with inheritance, but I am not sure ho to fix the problem.
I tried putting the require_once from set-calendar.php in the construct, but that didn’t work. I am guessing I have to extend Set_calendar in set-calendar.php, but I’m not quite sure the best way to do this.
Any advice would be much appreciated!