11 May 2012 18:16
[Tikiwiki-cvs/svn] SF.net SVN: tikiwiki:[41432] trunk
Revision: 41432
http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=41432&view=rev
Author: citadelrock
Date: 2012-05-11 16:16:02 +0000 (Fri, 11 May 2012)
Log Message:
-----------
[ENH] Add pagination when events exceed max specified and allow for listing of past or all events, not just upcoming
Modified Paths:
--------------
trunk/lib/calendar/calendarlib.php
trunk/lib/wiki-plugins/wikiplugin_events.php
trunk/templates/wiki-plugins/wikiplugin_events.tpl
Modified: trunk/lib/calendar/calendarlib.php
===================================================================
--- trunk/lib/calendar/calendarlib.php 2012-05-11 13:29:00 UTC (rev 41431)
+++ trunk/lib/calendar/calendarlib.php 2012-05-11 16:16:02 UTC (rev 41432)
<at> <at> -665,13 +665,15 <at> <at>
// Returns an array of a maximum of $maxrows upcoming (but possibly past) events in the given $order. If
$calendarId is set, events not in the specified calendars are filtered. $calendarId can be a calendar
identifier or an array of calendar identifiers. If $maxDaysEnd is a natural, events ending after
$maxDaysEnd days are filtered. If $maxDaysStart is a natural, events starting after $maxDaysStart days
are filtered. Events ending more than $priorDays in the past are filtered.
// Each event is represented by a string-indexed array with indices start, end, name, description,
calitemId, calendarId, user, lastModif, url, allday in the same format as tiki_calendar_items fields,
as well as location for the event's locations, parsed for the parsed description and category for the
event's calendar category.
- function upcoming_events($maxrows = -1, $calendarId = null, $maxDaysEnd = -1, $order = 'start_asc',
$priorDays = 0, $maxDaysStart = -1)
- {
+
+//Pagination
+ function upcoming_events($maxrows = -1, $calendarId = null, $maxDaysEnd = -1, $order = 'start_asc',
$priorDays = 0, $maxDaysStart = -1, $start = 0) {
+
global $prefs;
$cond = '';
$bindvars = array();
if (isset($calendarId)) {
- if (is_array($calendarId)) {
+ if(is_array($calendarId)) {
$cond = $cond."and (0=1";
foreach ($calendarId as $id) {
$cond = $cond." or i.`calendarId` = ? ";
<at> <at> -686,6 +688,54 <at> <at>
$cond .= " and `end` >= (unix_timestamp(now()) - ?*3600*34)";
$bindvars[] = $priorDays;
+
+ if ($maxDaysEnd > 0)
+ {
+ $maxSeconds = ($maxDaysEnd * 24 * 60 * 60);
+ $cond .= " and `end` <= (unix_timestamp(now())) +".$maxSeconds;
+ }
+ if ($maxDaysStart > 0) {
+ $maxSeconds = ($maxDaysStart * 24 * 60 * 60);
+ $cond .= " and `start` <= (unix_timestamp(now())) +".$maxSeconds;
+ }
+ $ljoin = "left join `tiki_calendar_locations` as l on i.`locationId`=l.`callocId` left join
`tiki_calendar_categories` as c on i.`categoryId`=c.`calcatId`";
+ $query = "select i.`start`, i.`end`, i.`name`, i.`description`, i.`status`, i.`calitemId`,
i.`calendarId`, i.`user`, i.`lastModif`, i.`url`, l.`name` as location, i.`allday`, c.`name` as
category from `tiki_calendar_items` i $ljoin where 1=1 ".$cond." order by ".$this->convertSortMode($order);
+
+ $ret = $this->fetchAll($query,$bindvars,$maxrows,$start);
+
+ $query_cant = "select count(*) from `tiki_calendar_items` i $ljoin where 1=1 ".$cond." order by ".$this->convertSortMode($order);
+ $cant = $this->getOne($query_cant, $bindvars);
+
+ foreach ( $ret as &$res ) {
+ $res['parsed'] = $this->parse_data($res['description'], array('is_html' =>
$prefs['calendar_description_is_html'] === 'y'));
+ }
+ $retval = array();
+ $retval['data'] = $ret;
+ $retval['cant'] = $cant;
+ return $retval;
+ }
+
+ function all_events($maxrows = -1, $calendarId = null, $maxDaysEnd = -1, $order = 'start_asc',
$priorDays = 0, $maxDaysStart = -1, $start = 0) {
+ global $prefs;
+ $cond = '';
+ $bindvars = array();
+ if (isset($calendarId)) {
+ if (is_array($calendarId)) {
+ $cond = $cond."and (0=1";
+ foreach($calendarId as $id) {
+ $cond = $cond." or i.`calendarId` = ? ";
+ }
+ $cond = $cond.")";
+ $bindvars = array_merge( $bindvars, $calendarId );
+ } else {
+ $cond = $cond." and i.`calendarId` = ? ";
+ $bindvars[] = $calendarId;
+ }
+ }
+ $condition = "";
+ $cond .= " and $condition (unix_timestamp(now()) - ?*3600*34)";
+ $bindvars[] = $priorDays;
+
if ($maxDaysEnd > 0) {
$maxSeconds = ($maxDaysEnd * 24 * 60 * 60);
$cond .= " and `end` <= (unix_timestamp(now())) +".$maxSeconds;
<at> <at> -696,16 +746,70 <at> <at>
}
$ljoin = "left join `tiki_calendar_locations` as l on i.`locationId`=l.`callocId` left join
`tiki_calendar_categories` as c on i.`categoryId`=c.`calcatId`";
$query = "select i.`start`, i.`end`, i.`name`, i.`description`, i.`status`, i.`calitemId`,
i.`calendarId`, i.`user`, i.`lastModif`, i.`url`, l.`name` as location, i.`allday`, c.`name` as
category from `tiki_calendar_items` i $ljoin where 1=1 ".$cond." order by ".$this->convertSortMode($order);
- $ret = $this->fetchAll($query, $bindvars, $maxrows, 0);
+
+ $ret = $this->fetchAll($query,$bindvars,$maxrows,$start);
+
+ $query_cant = "select count(*) from `tiki_calendar_items` i $ljoin where 1=1 ".$cond." order by ".$this->convertSortMode($order);
+ $cant = $this->getOne($query_cant, $bindvars);
foreach ( $ret as &$res ) {
$res['parsed'] = $this->parse_data($res['description'], array('is_html' =>
$prefs['calendar_description_is_html'] === 'y'));
}
-
- return $ret;
+
+ $retval = array();
+ $retval['data'] = $ret;
+ $retval['cant'] = $cant;
+ return $retval;
}
- function cleanEvents($calendarId, $days)
- {
+
+ function past_events($maxrows = -1, $calendarId = null, $maxDaysEnd = -1, $order = 'start_asc',
$priorDays = 0, $maxDaysStart = -1, $start = 0) {
+ global $prefs;
+ $cond = '';
+ $bindvars = array();
+ if (isset($calendarId)) {
+ if(is_array($calendarId))
+ {
+ $cond = $cond."and (0=1";
+ foreach ($calendarId as $id) {
+ $cond = $cond." or i.`calendarId` = ? ";
+ }
+ $cond = $cond.")";
+ $bindvars = array_merge( $bindvars, $calendarId );
+ } else {
+ $cond = $cond." and i.`calendarId` = ? ";
+ $bindvars[] = $calendarId;
+ }
+ }
+ $cond .= " and `end` <= (unix_timestamp(now()) - ?*3600*34)";
+ $bindvars[] = $priorDays;
+
+ if ($maxDaysEnd > 0) {
+ $maxSeconds = ($maxDaysEnd * 24 * 60 * 60);
+ $cond .= " and `end` <= (unix_timestamp(now())) +".$maxSeconds;
+ }
+ if ($maxDaysStart > 0) {
+ $maxSeconds = ($maxDaysStart * 24 * 60 * 60);
+ $cond .= " and `start` <= (unix_timestamp(now())) +".$maxSeconds;
+ }
+
+ $ljoin = "left join `tiki_calendar_locations` as l on i.`locationId`=l.`callocId` left join
`tiki_calendar_categories` as c on i.`categoryId`=c.`calcatId`";
+ $query = "select i.`start`, i.`end`, i.`name`, i.`description`, i.`calitemId`, i.`calendarId`,
i.`user`, i.`lastModif`, i.`url`, l.`name` as location, i.`allday`, c.`name` as category from
`tiki_calendar_items` i $ljoin where 1=1 ".$cond." order by ".$this->convertSortMode($order);
+ $ret = $this->fetchAll($query,$bindvars,$maxrows,$start);
+
+ $query_cant = "select count(*) from `tiki_calendar_items` i $ljoin where 1=1 ".$cond." order by ".$this->convertSortMode($order);
+ $cant = $this->getOne($query_cant, $bindvars);
+
+ foreach ( $ret as &$res ) {
+ $res['parsed'] = $this->parse_data($res['description'], array('is_html' =>
$prefs['calendar_description_is_html'] === 'y'));
+ }
+
+ $retval = array();
+ $retval['data'] = $ret;
+ $retval['cant'] = $cant;
+ return $retval;
+ }
+
+ function cleanEvents($calendarId, $days) {
global $tikilib;
$mid[] = " `end` < ? ";
$bindvars[] = $tikilib->now - $days*24*60*60;
Modified: trunk/lib/wiki-plugins/wikiplugin_events.php
===================================================================
--- trunk/lib/wiki-plugins/wikiplugin_events.php 2012-05-11 13:29:00 UTC (rev 41431)
+++ trunk/lib/wiki-plugins/wikiplugin_events.php 2012-05-11 16:16:02 UTC (rev 41432)
<at> <at> -57,6 +57,24 <at> <at>
array('text' => tra('No'), 'value' => 0)
),
),
+ // Pagination
+ 'timespan' => array(
+ 'required' => false,
+ 'name' => tra('Timespan'),
+ 'description' => tra('all, past, future (default)'),
+ ),
+ 'usePagination' => array(
+ 'required' => false,
+ 'name' => tra('Use Pagination'),
+ 'description' => tra('Activate pagination when Events listing are long. Default is n'),
+ 'filter' => 'alpha',
+ 'default' => 'n',
+ 'options' => array(
+ array('text' => '', 'value' => ''),
+ array('text' => tra('Yes'), 'value' => 'y'),
+ array('text' => tra('No'), 'value' => 'n')
+ ),
+ ),
),
);
}
<at> <at> -88,6 +106,19 <at> <at>
$desc=1;
}
+ // Pagination
+ if (!isset($timespan)) { $timespan = "future"; }
+
+ if ($usePagination == 'y')
+ {
+ if (!isset($_REQUEST["offset"])) {
+ $start = 0;
+ } else {
+ $start = $_REQUEST["offset"];
+ }
+ }
+
+
$rawcals = $calendarlib->list_calendars();
$calIds = array();
<at> <at> -121,7 +152,27 <at> <at>
$viewable[] = $cal_id;
}
}
+
+ // Pagination
+ if($timespan == "future") {
+ $events = $calendarlib->upcoming_events($max,
+ array_intersect($calIds, $viewable),
+ $maxdays,'start_asc', 1, 0, $start);
+ }
+
+ if($timespan == "all") {
+ $events = $calendarlib->all_events($max,
+ array_intersect($calIds, $viewable),
+ $maxdays,'start_asc', 1, 0, $start);
+ }
+
+ if($timespan == "past"){
+ $events = $calendarlib->past_events($max,
+ array_intersect($calIds, $viewable),
+ $maxdays, 'start_desc', 0, -1, $start);
+ }
+
if (isset($calendarid)) {
$calIds=explode("|", $calendarid);
}
<at> <at> -130,6 +181,21 <at> <at>
$smarty->assign_by_ref('datetime', $datetime);
$smarty->assign_by_ref('desc', $desc);
$smarty->assign_by_ref('events', $events);
+
+ // Pagination
+ if ($usePagination == 'y'){
+
+ $smarty->assign('maxEvents', $max);
+ $smarty->assign_by_ref('offset', $start);
+ $smarty->assign_by_ref('cant', $events['cant']);
+
+ }
+
+ $smarty->assign('usePagination', $usePagination);
+ $smarty->assign_by_ref('events', $events['data']);
+ $smarty->assign_by_ref('actions', $actions);
+
+
return '~np~'.$smarty->fetch('wiki-plugins/wikiplugin_events.tpl').'~/np~';
$repl="";
Modified: trunk/templates/wiki-plugins/wikiplugin_events.tpl
===================================================================
--- trunk/templates/wiki-plugins/wikiplugin_events.tpl 2012-05-11 13:29:00 UTC (rev 41431)
+++ trunk/templates/wiki-plugins/wikiplugin_events.tpl 2012-05-11 16:16:02 UTC (rev 41432)
<at> <at> -21,4 +21,9 <at> <at>
</td>
</tr><!-- {cycle} -->
{/foreach}
-</table>
\ No newline at end of file
+</table>
+{*Pagination *}
+{if !empty($events) && $usePagination ne 'n'}
+ {pagination_links cant=$cant step=$maxEvents offset=$offset}{/pagination_links}
+{/if}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open
Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
RSS Feed