summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Palmer <nick@sluggardy.net>2007-09-30 15:47:40 +0000
committerNick Palmer <nick@sluggardy.net>2007-09-30 15:47:40 +0000
commitd9ea975f5b96d5ac076f958794118294c2fb3136 (patch)
treebed7996ce93c96d3235547b75772266198f37a1d
parentecca99379d729f94b3b7756d586396d04e74d42b (diff)
downloadcalendar-d9ea975f5b96d5ac076f958794118294c2fb3136.tar.gz
calendar-d9ea975f5b96d5ac076f958794118294c2fb3136.tar.bz2
calendar-d9ea975f5b96d5ac076f958794118294c2fb3136.zip
Major revamp of calendar to push functionality from index.php into the
calendar so that other packages can more easily use the calendar. Made the time limit functions in LibertyContent::getContentList more generic.
-rw-r--r--Calendar.php195
-rw-r--r--index.php126
2 files changed, 190 insertions, 131 deletions
diff --git a/Calendar.php b/Calendar.php
index eab9d72..11d409f 100644
--- a/Calendar.php
+++ b/Calendar.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version $Header: /cvsroot/bitweaver/_bit_calendar/Calendar.php,v 1.39 2007/06/29 16:33:57 nickpalmer Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_calendar/Calendar.php,v 1.40 2007/09/30 15:47:40 nickpalmer Exp $
* @package calendar
*
* @copyright Copyright (c) 2004-2006, bitweaver.org
@@ -46,21 +46,17 @@ class Calendar extends LibertyContent {
**/
function getList( $pListHash ) {
$ret = array();
- $pListHash['include_data'] = TRUE;
if( $this->prepGetList( $pListHash ) ) {
- include_once( LIBERTY_PKG_PATH.'LibertyContent.php' );
- $content = new LibertyContent();
- $content->prepGetList( $pListHash );
- $res = $content->getContentList( $pListHash );
+ $res = $this->getContentList( $pListHash );
- foreach( $res['data'] as $item ) {
+ foreach( $res['data'] as $item ) {
// shift all time data by user timezone offset
// and then display as a simple UTC time
- $item['timestamp'] = $item[$pListHash['calendar_sort_mode']] + $this->display_offset;;
+ $item['timestamp'] = $item[$pListHash['time_limit_column']] + $this->display_offset;;
$item['created'] = $item['created'] + $this->display_offset;;
$item['last_modified'] = $item['last_modified'] + $this->display_offset;;
$item['event_time'] = $item['event_time'] + $this->display_offset;;
- $item['parsed'] = $content->parseData($item['data'], $item['format_guid']);
+ $item['parsed'] = $this->parseData($item['data'], $item['format_guid']);
$dstart = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( "m", $item['timestamp'], true ), $this->mDate->date( "d", $item['timestamp'], true ), $this->mDate->date( "Y", $item['timestamp'], true ) );
$ret[$dstart][] = $item;
}
@@ -124,14 +120,30 @@ class Calendar extends LibertyContent {
* prepare ListHash to ensure errorfree usage
**/
function prepGetList( &$pListHash ) {
+ $pListHash['include_data'] = TRUE;
if( !empty( $pListHash['focus_date'] ) ) {
$calDates = $this->doRangeCalculations( $pListHash );
- $pListHash['start'] = $calDates['view_start'] - $this->display_offset;
- $pListHash['stop'] = $calDates['view_end'] - $this->display_offset;
+ $pListHash['time_limit_start'] = $calDates['view_start'] - $this->display_offset;
+ $pListHash['time_limit_stop'] = $calDates['view_end'] - $this->display_offset;
}
- if( !empty( $pListHash['sort_mode'] ) ) {
- $pListHash['calendar_sort_mode'] = preg_replace( "/(_asc$|_desc$)/i", "", $pListHash['sort_mode'] );
+ if ( empty( $pListHash['sort_mode'] ) ) {
+ $pListHash['sort_mode'] = !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : 'event_time_asc';
+ }
+ $pListHash['time_limit_column'] = preg_replace( "/(_asc$|_desc$)/i", "", $pListHash['sort_mode'] );
+
+ if ( empty( $pListHash['user_id'] ) ) {
+ $pListHash['user_id'] = !empty( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : NULL;
}
+ if ( !empty( $_REQUEST['order_table'] ) ) {
+ $pListHash['order_table'] = $_REQUEST['order_table'];
+ }
+
+ // Don't think this is required.
+ $pListHash['offset'] = 0;
+ // There should at least be a preference for this.
+ $pListHash['max_records'] = 500;
+
+ LibertyContent::prepGetList( $pListHash );
return TRUE;
}
@@ -211,7 +223,7 @@ class Calendar extends LibertyContent {
* timezone and daylight saving, but the USERS daylight saving information
* is not available, which will cause some problems!
**/
- function buildCalendar( $pDateHash ) {
+ function buildMonth( $pDateHash ) {
global $gBitSmarty;
$focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true );
@@ -279,5 +291,160 @@ class Calendar extends LibertyContent {
return $calendar;
}
+
+ // Setup the content types for use in the calendar.
+ function setupContentTypes() {
+ global $gLibertySystem, $gBitSmarty, $gBitSystem;
+ foreach( $gLibertySystem->mContentTypes as $cName => $cType ) {
+ if ( $gBitSystem->isPackageActive( $cType['handler_package'] ) ) {
+ $contentTypes[$cType['content_type_guid']] = $cType['content_description'];
+ }
+ }
+ asort($contentTypes);
+ $gBitSmarty->assign( 'calContentTypes', $contentTypes );
+ }
+
+ // Setup the day names for use in the calendar
+ function setupDayNames() {
+ global $gBitSmarty;
+
+ // set up daynames for the calendar
+ $dayNames = array(
+ tra( "Monday" ),
+ tra( "Tuesday" ),
+ tra( "Wednesday" ),
+ tra( "Thursday" ),
+ tra( "Friday" ),
+ tra( "Saturday" ),
+ tra( "Sunday" ),
+ );
+
+ // depending on what day we want to view first, we need to adjust the dayNames array
+ for( $i = 0; $i < WEEK_OFFSET; $i++ ) {
+ $pop = array_pop( $dayNames );
+ array_unshift( $dayNames, $pop );
+ }
+ $gBitSmarty->assign( 'dayNames', $dayNames );
+ }
+
+ function processRequestHash(&$pRequest, &$pStore) {
+ global $gBitUser;
+ if( !empty( $pRequest["content_type_guid"] ) ) {
+ if( $gBitUser->isRegistered() ) {
+ $gBitUser->storePreference( 'calendar_default_guids', serialize( $pRequest['content_type_guid'] ) );
+ }
+ $pStore['content_type_guid'] = $pRequest["content_type_guid"];
+ } elseif( !isset( $pStore['content_type_guid'] ) && $gBitUser->getPreference( 'calendar_default_guids' ) && $gBitUser->isRegistered() ) {
+ $pStore['content_type_guid'] = unserialize( $gBitUser->getPreference( 'calendar_default_guids' ) );
+ } elseif( !isset( $pStore['content_type_guid'] ) ) {
+ $pStore['content_type_guid'] = array();
+ } elseif( isset( $pRequest["refresh"] ) && !isset( $pRequest["content_type_guid"] ) ) {
+ $pStore['content_type_guid'] = array();
+ }
+
+ // set up the todate
+ if( !empty( $pRequest["todate"] ) ) {
+ // clean up todate. who knows where this has come from
+ if ( is_numeric( $pRequest['todate'] ) ) {
+ $pStore['focus_date'] = $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( 'm', $pRequest['todate'], true ), $this->mDate->date( 'd', $pRequest['todate'], true ), $this->mDate->date( 'Y', $pRequest['todate'], true ) );
+ } else {
+ $pStore['focus_date'] = $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date2( 'm', $pRequest['todate'], true ), $this->mDate->date2( 'd', $pRequest['todate'], true ), $this->mDate->date2( 'Y', $pRequest['todate'], true ) );
+ }
+ } elseif( !empty( $pStore['focus_date'] ) ) {
+ $pRequest["todate"] = $pStore['focus_date'];
+ } else {
+ $pStore['focus_date'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( 'm' ), $this->mDate->date( 'd' ), $this->mDate->date( 'Y' ) );
+ $pRequest["todate"] = $pStore['focus_date'];
+ }
+
+ $focus = $pRequest['todate'];
+ if( !empty( $pRequest["view_mode"] ) ) {
+ $pStore['view_mode'] = $pRequest["view_mode"];
+ } elseif( empty( $pStore['view_mode'] ) ) {
+ $pStore['view_mode'] = 'month';
+ }
+ }
+
+ function getEvents(&$pListHash) {
+ global $gBitSystem, $gLibertySystem;
+
+ $bitEvents = array();
+ if ( !empty( $pListHash['content_type_guid'] ) ) {
+ // Verify that the type is still active
+ foreach ( $pListHash['content_type_guid'] as $index => $type ) {
+ if ( !$gBitSystem->isPackageActive( $gLibertySystem->mContentTypes[$type]['handler_package'] ) ) {
+ unset( $pListHash['content_type_guid'][$index] );
+ }
+ if ( !empty( $pListHash['content_type_guid'] ) ) {
+ $bitEvents = $this->getList( $pListHash );
+ }
+ }
+ }
+
+ return $bitEvents;
+ }
+
+ function buildCalendar(&$pListHash, &$pDateHash) {
+ global $gBitSmarty, $gBitSystem;
+
+ $bitEvents = $this->getEvents($pListHash);
+
+ $gBitSmarty->assign( 'navigation', $this->buildCalendarNavigation( $pDateHash ) );
+ $calMonth = $this->buildMonth( $pDateHash );
+ $calDay = $this->buildDay( $pDateHash );
+
+ foreach( $calMonth as $w => $week ) {
+ foreach( $week as $d => $day ) {
+ $dayEvents = array();
+ if( !empty( $bitEvents[$day['day']] ) ) {
+ $i = 0;
+ foreach( $bitEvents[$day['day']] as $bitEvent ) {
+ $bitEvent['parsed_data'] = $this->parseData($bitEvent);
+ $dayEvents[$i] = $bitEvent;
+ if (!$gBitSystem->isFeatureActive('calendar_ajax_popups')) {
+ $gBitSmarty->assign( 'cellHash', $bitEvent );
+ $dayEvents[$i]["over"] = $gBitSmarty->fetch( "bitpackage:calendar/calendar_box.tpl" );
+ }
+
+ // populate $calDay array with events
+ if( !empty ( $bitEvent ) && $pDateHash['view_mode'] == 'day' ) {
+ foreach( $calDay as $key => $t ) {
+ // special case - last item entry in array - check this first
+
+ if( $bitEvent['timestamp'] >= $calDay[$key]['time'] && empty( $calDay[$key + 1]['time'] ) ) {
+ $calDay[$key]['items'][] = $dayEvents[$i];
+ } elseif( $bitEvent['timestamp'] >= $calDay[$key]['time'] && $bitEvent['timestamp'] <= $calDay[$key + 1]['time'] ) {
+ $calDay[$key]['items'][] = $dayEvents[$i];
+ }
+ }
+ }
+
+ $i++;
+ }
+ }
+ if( !empty( $dayEvents ) ) {
+ $calMonth[$w][$d]['items'] = array_values( $dayEvents );
+ }
+ }
+ }
+ $gBitSmarty->assign_by_ref( 'calDay', $calDay );
+ $gBitSmarty->assign_by_ref( 'calMonth', $calMonth );
+ }
+
+ // Display the actual calendar doing any other work required for the template
+ function display($pTitle) {
+ global $gBitThemes, $gBitSmarty, $gBitSystem;
+
+ $this->setupContentTypes();
+ $this->setupDayNames();
+
+ $gBitThemes->loadAjax( 'prototype' );
+
+ // TODO: make this a pref
+ $gBitSmarty->assign( 'trunc', $gBitSystem->getConfig( 'title_truncate', 12 ) );
+
+ $gBitSystem->display( 'bitpackage:calendar/calendar.tpl', tra( 'Calendar' ) );
+
+ }
}
?>
diff --git a/index.php b/index.php
index 8381556..f3b0618 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
<?php
-// $Header: /cvsroot/bitweaver/_bit_calendar/index.php,v 1.54 2007/07/10 18:59:10 squareing Exp $
+// $Header: /cvsroot/bitweaver/_bit_calendar/index.php,v 1.55 2007/09/30 15:47:40 nickpalmer Exp $
// Copyright( c ) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
@@ -13,57 +13,14 @@ $gBitSystem->isPackageActive( 'calendar', TRUE );
$gBitSystem->verifyPermission( 'p_calendar_view' );
-// set up $_SESSION and $_REQUEST to make the usable later on
-// setup list of bit items displayed
-if( !empty( $_REQUEST["content_type_guid"] ) ) {
- if( $gBitUser->isRegistered() ) {
- $gBitUser->storePreference( 'calendar_default_guids', serialize( $_REQUEST['content_type_guid'] ) );
- }
- $_SESSION['calendar']['content_type_guid'] = $_REQUEST["content_type_guid"];
-} elseif( !isset( $_SESSION['calendar']['content_type_guid'] ) && $gBitUser->getPreference( 'calendar_default_guids' ) && $gBitUser->isRegistered() ) {
- $_SESSION['calendar']['content_type_guid'] = unserialize( $gBitUser->getPreference( 'calendar_default_guids' ) );
-} elseif( !isset( $_SESSION['calendar']['content_type_guid'] ) ) {
- $_SESSION['calendar']['content_type_guid'] = array();
-} elseif( isset( $_REQUEST["refresh"] ) && !isset( $_REQUEST["content_type_guid"] ) ) {
- $_SESSION['calendar']['content_type_guid'] = array();
-}
-
-foreach( $gLibertySystem->mContentTypes as $cType ) {
- $contentTypes[$cType['content_type_guid']] = $cType['content_description'];
-}
-asort($contentTypes);
-$gBitSmarty->assign( 'calContentTypes', $contentTypes );
-
// now, lets get the ball rolling!
$gCalendar = new Calendar();
-// set up the todate
-if( !empty( $_REQUEST["todate"] ) ) {
-// clean up todate. who knows where this has come from
- if ( is_numeric( $_REQUEST['todate'] ) ) {
- $_SESSION['calendar']['focus_date'] = $_REQUEST['todate'] = $gCalendar->mDate->gmmktime( 0, 0, 0, $gCalendar->mDate->date( 'm', $_REQUEST['todate'], true ), $gCalendar->mDate->date( 'd', $_REQUEST['todate'], true ), $gCalendar->mDate->date( 'Y', $_REQUEST['todate'], true ) );
- } else {
- $_SESSION['calendar']['focus_date'] = $_REQUEST['todate'] = $gCalendar->mDate->gmmktime( 0, 0, 0, $gCalendar->mDate->date2( 'm', $_REQUEST['todate'], true ), $gCalendar->mDate->date2( 'd', $_REQUEST['todate'], true ), $gCalendar->mDate->date2( 'Y', $_REQUEST['todate'], true ) );
- }
-} elseif( !empty( $_SESSION['calendar']['focus_date'] ) ) {
- $_REQUEST["todate"] = $_SESSION['calendar']['focus_date'];
-} else {
- $_SESSION['calendar']['focus_date'] = $gCalendar->mDate->gmmktime( 0, 0, 0, $gCalendar->mDate->date( 'm' ), $gCalendar->mDate->date( 'd' ), $gCalendar->mDate->date( 'Y' ) );
- $_REQUEST["todate"] = $_SESSION['calendar']['focus_date'];
-}
-
-$focus = $_REQUEST['todate'];
-if( !empty( $_REQUEST["view_mode"] ) ) {
- $_SESSION['calendar']['view_mode'] = $_REQUEST["view_mode"];
-} elseif( empty( $_SESSION['calendar']['view_mode'] ) ) {
- $_SESSION['calendar']['view_mode'] = 'month';
-}
-
-$gBitSmarty->assign( 'navigation', $gCalendar->buildCalendarNavigation( $_SESSION['calendar'] ) );
-$calMonth = $gCalendar->buildCalendar( $_SESSION['calendar'] );
-$calDay = $gCalendar->buildDay( $_SESSION['calendar'] );
+// Handle the request hash storing into the session.
+$gCalendar->processRequestHash($_REQUEST, $_SESSION['calendar']);
-if( $gBitUser->hasPermission("p_calendar_view_changes") && $_SESSION['calendar']['content_type_guid'] ) {
+// Setup which content types we want to view.
+if( $gBitUser->hasPermission("p_calendar_view_changes") && $_SESSION['calendar']['content_type_guid'] ) {
$listHash = $_SESSION['calendar'];
} else {
foreach ($gLibertySystem->mContentTypes as $key => $val) {
@@ -72,74 +29,9 @@ if( $gBitUser->hasPermission("p_calendar_view_changes") && $_SESSION['calendar']
}
}
}
-if (!empty($listHash)) {
- $listHash['user_id'] = !empty( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : NULL;
- $listHash['sort_mode'] = !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : 'event_time_asc';
- $listHash['offset'] = 0;
- $listHash['max_records'] = 500;
- $bitEvents = $gCalendar->getList( $listHash );
-} else {
- $bitEvents = array();
-}
-
-// finally we have all the stuff ready to populate the $calMonth and $calDay arrays
-foreach( $calMonth as $w => $week ) {
- foreach( $week as $d => $day ) {
- $dayEvents = array();
- if( !empty( $bitEvents[$day['day']] ) ) {
- $i = 0;
- foreach( $bitEvents[$day['day']] as $bitEvent ) {
- $dayEvents[$i] = $bitEvent;
- if (!$gBitSystem->isFeatureActive('calendar_ajax_popups')) {
- $gBitSmarty->assign( 'cellHash', $bitEvent );
- $dayEvents[$i]["over"] = $gBitSmarty->fetch( "bitpackage:calendar/calendar_box.tpl" );
- }
-
- // populate $calDay array with events
- if( !empty ( $bitEvent ) && $_SESSION['calendar']['view_mode'] == 'day' ) {
- foreach( $calDay as $key => $t ) {
- // special case - last item entry in array - check this first
-
- if( $bitEvent['timestamp'] >= $calDay[$key]['time'] && empty( $calDay[$key + 1]['time'] ) ) {
- $calDay[$key]['items'][] = $dayEvents[$i];
- } elseif( $bitEvent['timestamp'] >= $calDay[$key]['time'] && $bitEvent['timestamp'] <= $calDay[$key + 1]['time'] ) {
- $calDay[$key]['items'][] = $dayEvents[$i];
- }
- }
- }
-
- $i++;
- }
- }
- if( !empty( $dayEvents ) ) {
- $calMonth[$w][$d]['items'] = array_values( $dayEvents );
- }
- }
-}
-$gBitSmarty->assign_by_ref( 'calDay', $calDay );
-$gBitSmarty->assign_by_ref( 'calMonth', $calMonth );
-
-// set up daynames for the calendar
-$dayNames = array(
- tra( "Monday" ),
- tra( "Tuesday" ),
- tra( "Wednesday" ),
- tra( "Thursday" ),
- tra( "Friday" ),
- tra( "Saturday" ),
- tra( "Sunday" ),
-);
-
-// depending on what day we want to view first, we need to adjust the dayNames array
-for( $i = 0; $i < WEEK_OFFSET; $i++ ) {
- $pop = array_pop( $dayNames );
- array_unshift( $dayNames, $pop );
-}
-$gBitSmarty->assign( 'dayNames', $dayNames );
-$gBitThemes->loadAjax( 'prototype' );
-
-// TODO: make this a pref
-$gBitSmarty->assign( 'trunc', $gBitSystem->getConfig( 'title_truncate', 12 ) );
+// Build the calendar
+$gCalendar->buildCalendar($listHash, $_SESSION['calendar']);
+// And display it with a nice title.
+$gCalendar->display(tra('Calendar'));
-$gBitSystem->display( 'bitpackage:calendar/calendar.tpl', tra( 'Calendar' ) );
?>