diff options
author | emkael <emkael@tlen.pl> | 2016-03-15 23:59:33 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-03-15 23:59:33 +0100 |
commit | e509fc24d904831759071134361bef1503d4ff87 (patch) | |
tree | fe56ad530be0f4270a43f8c5715a326b67bdd249 | |
parent | 0c5ca745975b1929787ea55a2d936b8fbef4a38f (diff) |
* facade for event list fetch
-rw-r--r-- | app/php/facades/EventFacade.php | 35 | ||||
-rw-r--r-- | app/php/sqlmap/config.xml | 1 | ||||
-rw-r--r-- | app/php/sqlmap/events.xml | 11 |
3 files changed, 47 insertions, 0 deletions
diff --git a/app/php/facades/EventFacade.php b/app/php/facades/EventFacade.php new file mode 100644 index 0000000..6ed739f --- /dev/null +++ b/app/php/facades/EventFacade.php @@ -0,0 +1,35 @@ +<?php + +Prado::using('Application.facades.Facade'); + +class EventFacade extends Facade { + + public function getEventList($dateFrom=NULL, $dateTo=NULL, $calendars=NULL) { + $calendarClause = '1=1'; + if ($calendars) { + $calendarClause = sprintf( + '_calendar IN (%s)', + implode( + ',', + array_map( + function($calendar) { + return $this->quoteString($calendar->UID); + }, + $calendars + ) + ) + ); + } + return $this->fetchList( + 'getEvents', + array( + 'date_from' => $dateFrom ?: '0000-00-00 00:00:00', + 'date_to' => $dateTo ?: '9999-99-99', + 'calendar_clause' => $calendarClause + ) + ); + } + +} + +?> diff --git a/app/php/sqlmap/config.xml b/app/php/sqlmap/config.xml index 7c213a3..101e1b7 100644 --- a/app/php/sqlmap/config.xml +++ b/app/php/sqlmap/config.xml @@ -4,5 +4,6 @@ <datasource ConnectionID="db" /> </provider> <sqlMaps> + <sqlMap name="events" resource="events.xml" /> </sqlMaps> </sqlMapConfig> diff --git a/app/php/sqlmap/events.xml b/app/php/sqlmap/events.xml new file mode 100644 index 0000000..5980b27 --- /dev/null +++ b/app/php/sqlmap/events.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<sqlMapConfig> + <select id="getEvents" resultClass="Entry"> + <![CDATA[ + SELECT * FROM entries + WHERE end_date >= #date_from# AND begin_date <= #date_to# + AND $calendar_clause$ + ORDER BY begin_date ASC; + ]]> + </select> +</sqlMapConfig> |