$r['categories'] = $this->wpdb->get_results($sql, ARRAY_A);
if ($this->postAddTimes) {
- $sql = "
- SELECT ET.*
- FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET
- WHERE ET.start_time >= now()
- AND ET.active
- AND ET.event = {$r['id']}
- ORDER BY ET.start_time";
- $times = $this->wpdb->get_results($sql, ARRAY_A);
+ include_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataTimes.php';
+ $timeData = new GlmDataEventsTimes( $this->wpdb, $this->config );
+ $where = "
+ T.start_time >= now()
+ AND T.active
+ AND T.event = {$r['id']}
+ ";
+ $order = "T.start_time";
+ $times = $timeData->getList( $where, $order );
$r['times'] = $times;
// get the first element of times array
if ( !empty( $times ) ) {
- $r['starting_date'] = $times[0]['start_time'];
- $r['ending_date'] = $times[count($times) - 1]['end_time'];
+ $r['starting_date'] = $times[key($times)]['start_time']['datetime'];
+ end($times);
+ $r['ending_date'] = $times[key($times)]['end_time']['datetime'];
}
}
public function getModelEventsData($categoryId = null, $limit = null)
{
+ $this->postAddTimes = true;
if ($categoryId) {
- return $this->getEventsByCategory( $categoryId, $limit );
+ $events = $this->getEventsByCategory( $categoryId, $limit );
} else {
- return $this->getList();
+ $events = $this->getList();
}
+ foreach ( $events as &$event ) {
+ // grab the first from times and see if it's ongoing or not
+ if ($event['times']) {
+ reset($event['times']);
+ $firstKey = key($event['times']);
+ $event['ongoing'] = $event['times'][$firstKey]['ongoing'];
+ reset($event['times']);
+ }
+ $event['dates'] = $this->getEventDate(
+ strtotime($event['starting_date']),
+ strtotime($event['ending_date']),
+ 'timestamp'
+ );
+ }
+ $this->postAddTimes = false;
+ return $events;
}
public function getModelEventData($eventId)
{
- return $this->getEntry($eventId);
+ $this->postAddTimes = true;
+ $event = $this->getEntry($eventId);
+ $event['dates'] = $this->getEventDate(
+ strtotime($event['starting_date']),
+ strtotime($event['ending_date']),
+ 'timestamp'
+ );
+ $this->postAddTimes = false;
+ return $event;
}
/**
*/
abstract public function modelAction($actionData = false);
+ /**
+ * get_event_date: make the event date human readable
+ *
+ * @param string $sdate start date
+ * @param string $edate end date
+ * @param string $dateType dateType Postgres,etc
+ * @param boolean $microFormat use microformating on output
+ *
+ * @return string
+ * @access public
+ */
+ function getEventDate(
+ $sdate,
+ $edate,
+ $dateType,
+ $microFormat = false
+ ) {
+ switch($dateType) {
+ case "Postgres":
+ $postgresPattern = "/([0-9]{1,2})[/-]([0-9]{1,2})[/-]([0-9]{4})/";
+ if (preg_match($postgresPattern, $sdate, $spt)) {
+ $mon = $spt[1];
+ $day = $spt[2];
+ $yr = $spt[3];
+ }
+
+ if (preg_match($postgresPattern, $edate, $ept)) {
+ $mon2 = $ept[1];
+ $day2 = $ept[2];
+ $yr2 = $ept[3];
+ }
+ break;
+ case "eventstamp":
+ case "timestamp":
+ $mon = date("m",$sdate);
+ $day = date("d",$sdate);
+ $yr = date("Y",$sdate);
+ $mon2 = date("m",$edate);
+ $day2 = date("d",$edate);
+ $yr2 = date("Y",$edate);
+ break;
+ }
+
+ $start = mktime(0,0,0,$mon,$day,$yr);
+ $end = mktime(0,0,0,$mon2,$day2,$yr2);
+ if ($day == $day2 && $mon == $mon2 && $yr == $yr2) {
+ $dateparam = "M j, Y";
+ $dateBegin = date($dateparam, $start) ;
+ $dateEnd = "";
+ } elseif ($day == $day2 AND $mon == $mon2 AND $yr != $yr2) {
+ $dateparam1 = "M j, Y -";
+ $dateparam2 = "Y";
+ $dateBegin = date($dateparam1, $start);
+ $dateEnd = date($dateparam2, $end);
+ } elseif ($day != $day2 AND $mon == $mon2 AND $yr == $yr2) {
+ $dateparam1 = "M j -";
+ $dateparam2 = "j, Y";
+ $dateBegin = date($dateparam1, $start);
+ $dateEnd = date($dateparam2, $end);
+ } elseif ($day != $day2 AND $mon == $mon2 AND $yr != $yr2) {
+ $dateparam1 = "M j, Y -";
+ $dateparam2 = "M j, Y";
+ $dateBegin = date($dateparam1, $start);
+ $dateEnd = date($dateparam2, $end);
+ } elseif ($yr == $yr2) {
+ $dateparam1 = "M j -";
+ $dateparam2 = "M j, Y";
+ $dateBegin = date($dateparam1, $start);
+ $dateEnd = date($dateparam2, $end);
+ } else {
+ $dateparam1 = "M j, Y -";
+ $dateparam2 = "M j, Y";
+ $dateBegin = date($dateparam1, $start);
+ $dateEnd = date($dateparam2, $end);
+ }
+ if ($microFormat) {
+ $dateBegin = '<span class="dtstart">
+ <span class="value" title="'.date('Y-m-d', $start).'">' .
+ $dateBegin . '</span>
+ </span>';
+ $dateEnd
+ = ($dateEnd)
+ ? '<span class="dtend">
+ <span class="value" title="'.date('Y-m-d', $end).'">' .
+ $dateEnd . '</span>
+ </span>'
+ : '';
+ }
+ return $dateBegin." ".$dateEnd;
+ }
}