calendar: added posted/created chronology

calendar: added a where are we bar (like: created/2005/august)

calendar: possibility to hide the All/Any buttons ($conf['calendar_show_any'])

calendar: possibility to display a single navigation bar instead of 
several navigation bars ($conf['calendar_multi_bar'])

calendar: tried to simplify code and improve readability 
(still requires a review)

git-svn-id: http://piwigo.org/svn/trunk@1057 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2006-02-24 05:58:48 +00:00
parent 3aff4f0bfe
commit d4646f39d2
9 changed files with 394 additions and 261 deletions

View file

@ -301,7 +301,7 @@ $template->assign_block_vars(
$template->assign_block_vars( $template->assign_block_vars(
'special_cat', 'special_cat',
array( array(
'URL' => PHPWG_ROOT_PATH.'category.php?calendar=m-c', 'URL' => PHPWG_ROOT_PATH.'category.php?calendar=monthly-c',
'TITLE' => $lang['calendar_hint'], 'TITLE' => $lang['calendar_hint'],
'NAME' => $lang['calendar'] 'NAME' => $lang['calendar']
)); ));

View file

@ -35,25 +35,41 @@ class CalendarBase
var $inner_sql; var $inner_sql;
// base url used when generating html links // base url used when generating html links
var $url_base; var $url_base;
// array of date components e.g. (2005,10,12) ...
var $date_components;
function get_date_where()
{
die("get_date_where not extended");
}
/** /**
* Initialize the calendar * Initialize the calendar
* @param string date_field db column on which this calendar works * @param string date_field db column on which this calendar works
* @param string inner_sql used for queries (INNER JOIN or normal) * @param string inner_sql used for queries (INNER JOIN or normal)
* @param array date_components
*/ */
function initialize($date_field, $inner_sql) function initialize($date_field, $inner_sql, $date_components)
{ {
$this->date_field = $date_field; $this->date_field = $date_field;
$this->inner_sql = $inner_sql; $this->inner_sql = $inner_sql;
$this->date_components = $date_components;
} }
//--------------------------------------------------------- private members --- //--------------------------------------------------------- private members ---
/**
* Returns a display name for a date component optionally using labels
*/
function get_date_component_label($date_component, $labels=null)
{
$label = $date_component;
if (isset($labels[$date_component]))
{
$label = $labels[$date_component];
}
elseif ($date_component == 'any' )
{
$label = l10n('calendar_any');
}
return $label;
}
/** /**
* Creates a calendar navigation bar. * Creates a calendar navigation bar.
* *
@ -96,8 +112,8 @@ class CalendarBase
} }
$nav_bar.= '</span>'; $nav_bar.= '</span>';
} }
global $conf;
if ($allow_any and count($items) > 1) if ($conf['calendar_show_any'] and $allow_any and count($items) > 1)
{ {
$label = l10n('calendar_any'); $label = l10n('calendar_any');
if (isset($selected_item) and 'any' == $selected_item) if (isset($selected_item) and 'any' == $selected_item)
@ -121,14 +137,12 @@ class CalendarBase
/** /**
* Creates a calendar navigation bar for a given level. * Creates a calendar navigation bar for a given level.
* *
* @param string view_type - list or calendar (e.g. 'l' or 'c')
* @param array requested - array of current selected elements (e.g. 2005,10)
* @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ... * @param string sql_func - YEAR/MONTH/DAY/WEEK/DAYOFWEEK ...
* @param string sql_offset - (e.g. +1 for WEEK - first in year is 1) * @param string sql_offset - (e.g. +1 for WEEK - first in year is 1)
* @param array labels - optional labels to show in the navigation bar * @param array labels - optional labels to show in the navigation bar
* @return void * @return void
*/ */
function build_nav_bar($view_type, $requested, $level, $sql_func, function build_nav_bar($level, $sql_func,
$sql_offset='', $labels=null) $sql_offset='', $labels=null)
{ {
global $template; global $template;
@ -137,7 +151,7 @@ class CalendarBase
SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset
.') as period'; .') as period';
$query.= $this->inner_sql; $query.= $this->inner_sql;
$query.= $this->get_date_where($requested, $level); $query.= $this->get_date_where($level);
$query.= ' $query.= '
GROUP BY period GROUP BY period
;'; ;';
@ -150,19 +164,22 @@ SELECT DISTINCT('.$sql_func.'('.$this->date_field.')'.$sql_offset
} }
$url_base = $this->url_base; $url_base = $this->url_base;
$url_base .= $view_type.'-';
for ($i=0; $i<$level; $i++) for ($i=0; $i<$level; $i++)
{ {
if (isset($requested[$i])) if (isset($this->date_components[$i]))
{ {
$url_base .= $requested[$i].'-'; $url_base .= $this->date_components[$i].'-';
} }
} }
$selected = null;
if ( isset($this->date_components[$level]) )
{
$selected = $this->date_components[$level];
}
$nav_bar = $this->get_nav_bar_from_items( $nav_bar = $this->get_nav_bar_from_items(
$url_base, $url_base,
$level_items, $level_items,
isset($requested[$level]) ? $requested[$level] : null, $selected,
'cal', 'cal',
true, true,
$labels $labels

View file

@ -26,6 +26,10 @@
include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
define ('CYEAR', 0);
define ('CMONTH', 1);
define ('CDAY', 2);
/** /**
* Monthly calendar style (composed of years/months and days) * Monthly calendar style (composed of years/months and days)
*/ */
@ -37,43 +41,62 @@ class Calendar extends CalendarBase
* @return boolean false to indicate that thumbnails * @return boolean false to indicate that thumbnails
* where not included here, true otherwise * where not included here, true otherwise
*/ */
function generate_category_content($url_base, $view_type, &$requested) function generate_category_content($url_base, $view_type)
{ {
global $lang; global $lang, $conf;
$this->url_base = $url_base; $this->url_base = $url_base;
if ($view_type==CAL_VIEW_CALENDAR and count($requested)==0) if ($view_type==CAL_VIEW_CALENDAR)
{//case A: no year given - display all years+months {
if ($this->build_global_calendar($requested)) if ( count($this->date_components)==0 )
return true; {//case A: no year given - display all years+months
} if ($this->build_global_calendar())
return true;
}
if ($view_type==CAL_VIEW_CALENDAR and count($requested)==1) if ( count($this->date_components)==1 )
{//case B: year given - display all days in given year {//case B: year given - display all days in given year
if ($this->build_year_calendar($requested)) if ($this->build_year_calendar())
{ {
$this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years if ( $conf['calendar_multi_bar'] )
$this->build_nav_bar2(CYEAR, 'YEAR'); // years
return true;
}
}
if ( count($this->date_components)==2 )
{//case C: year+month given - display a nice month calendar
$this->build_month_calendar();
if ( $conf['calendar_multi_bar'] )
{
$this->build_nav_bar2(CYEAR, 'YEAR'); // years
}
if (count($this->date_components)>=1 and
( $conf['calendar_multi_bar'] or count($this->date_components)==1 ) )
{
$this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
}
return true; return true;
} }
} }
if ($view_type==CAL_VIEW_CALENDAR and count($requested)==2) if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
{//case C: year+month given - display a nice month calendar
$this->build_month_calendar($requested);
$this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 0, 'YEAR'); // years
if (count($requested)>0)
$this->build_nav_bar2(CAL_VIEW_CALENDAR, $requested, 1, 'MONTH', $lang['month']); // month
return true;
}
if ($view_type==CAL_VIEW_LIST or count($requested)==3)
{ {
$this->build_nav_bar2($view_type, $requested, 0, 'YEAR'); // years if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
if (count($requested)>0) {
$this->build_nav_bar2($view_type, $requested, 1, 'MONTH', $lang['month']); // month $this->build_nav_bar2(CYEAR, 'YEAR'); // years
if (count($requested)>1) }
$this->build_nav_bar2($view_type, $requested, 2, 'DAYOFMONTH' ); // days if ( count($this->date_components)>=1 and
( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
)
{
$this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
}
if ( count($this->date_components)>=2 )
{
$this->build_nav_bar2(CDAY, 'DAYOFMONTH' ); // days
}
} }
return false; return false;
} }
@ -81,31 +104,30 @@ function generate_category_content($url_base, $view_type, &$requested)
/** /**
* Returns a sql where subquery for the date field * Returns a sql where subquery for the date field
* @param array requested selected levels for this calendar
* (e.g. 2005,11,5 for 5th of November 2005)
* @param int max_levels return the where up to this level * @param int max_levels return the where up to this level
* (e.g. 2=only year and month) * (e.g. 2=only year and month)
* @return string * @return string
*/ */
function get_date_where($requested, $max_levels=3) function get_date_where($max_levels=3)
{ {
while (count($requested)>$max_levels) $date = $this->date_components;
while (count($date)>$max_levels)
{ {
array_pop($requested); array_pop($date);
} }
$res = ''; $res = '';
if (isset($requested[0]) and $requested[0]!='any') if (isset($date[CYEAR]) and $date[CYEAR]!='any')
{ {
$b = $requested[0] . '-'; $b = $date[CYEAR] . '-';
$e = $requested[0] . '-'; $e = $date[CYEAR] . '-';
if (isset($requested[1]) and $requested[1]!='any') if (isset($date[CMONTH]) and $date[CMONTH]!='any')
{ {
$b .= $requested[1] . '-'; $b .= $date[CMONTH] . '-';
$e .= $requested[1] . '-'; $e .= $date[CMONTH] . '-';
if (isset($requested[2]) and $requested[2]!='any') if (isset($date[CDAY]) and $date[CDAY]!='any')
{ {
$b .= $requested[2]; $b .= $date[CDAY];
$e .= $requested[2]; $e .= $date[CDAY];
} }
else else
{ {
@ -117,13 +139,13 @@ function get_date_where($requested, $max_levels=3)
{ {
$b .= '01-01'; $b .= '01-01';
$e .= '12-31'; $e .= '12-31';
if (isset($requested[1]) and $requested[1]!='any') if (isset($date[CMONTH]) and $date[CMONTH]!='any')
{ {
$res .= ' AND MONTH('.$this->date_field.')='.$requested[1]; $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
} }
if (isset($requested[2]) and $requested[2]!='any') if (isset($date[2]) and $date[2]!='any')
{ {
$res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
} }
} }
$res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res; $res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res;
@ -131,31 +153,72 @@ function get_date_where($requested, $max_levels=3)
else else
{ {
$res = ' AND '.$this->date_field.' IS NOT NULL'; $res = ' AND '.$this->date_field.' IS NOT NULL';
if (isset($requested[1]) and $requested[1]!='any') if (isset($date[CMONTH]) and $date[CMONTH]!='any')
{ {
$res .= ' AND MONTH('.$this->date_field.')='.$requested[1]; $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
} }
if (isset($requested[2]) and $requested[2]!='any') if (isset($date[CDAY]) and $date[CDAY]!='any')
{ {
$res .= ' AND DAYOFMONTH('.$this->date_field.')='.$requested[2]; $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
} }
} }
return $res; return $res;
} }
//--------------------------------------------------------- private members ---
function build_nav_bar2($view_type, $requested, $level, $sql_func, $labels=null) function get_display_name()
{ {
parent::build_nav_bar($view_type, $requested, $level, $sql_func, '', $labels); global $conf, $lang;
$res = '';
$url = $this->url_base;
if ( isset($this->date_components[CYEAR]) )
{
$res .= $conf['level_separator'];
$url .= $this->date_components[CYEAR].'-';
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label($this->date_components[CYEAR])
.'</a>';
}
if ( isset($this->date_components[CMONTH]) )
{
$res .= $conf['level_separator'];
$url .= $this->date_components[CMONTH].'-';
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label(
$this->date_components[CMONTH],
$lang['month']
)
.'</a>';
}
if ( isset($this->date_components[CDAY]) )
{
$res .= $conf['level_separator'];
$url .= $this->date_components[CDAY].'-';
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label($this->date_components[CDAY])
.'</a>';
}
return $res;
} }
function build_global_calendar(&$requested)
//--------------------------------------------------------- private members ---
function build_nav_bar2($level, $sql_func, $labels=null)
{ {
assert( count($requested) == 0 ); parent::build_nav_bar($level, $sql_func, '', $labels);
}
function build_global_calendar()
{
assert( count($this->date_components) == 0 );
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period, $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period,
COUNT(id) as count'; COUNT(id) as count';
$query.= $this->inner_sql; $query.= $this->inner_sql;
$query.= $this->get_date_where($requested); $query.= $this->get_date_where();
$query.= ' $query.= '
GROUP BY period'; GROUP BY period';
@ -175,14 +238,14 @@ function build_global_calendar(&$requested)
if (count($items)==1) if (count($items)==1)
{// only one year exists so bail out to year view {// only one year exists so bail out to year view
list($y) = array_keys($items); list($y) = array_keys($items);
array_push($requested, $y ); $this->date_components[CYEAR] = $y;
return false; return false;
} }
global $lang, $template; global $lang, $template;
foreach ( $items as $year=>$year_data) foreach ( $items as $year=>$year_data)
{ {
$url_base = $this->url_base .'c-'.$year; $url_base = $this->url_base.$year;
$nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'.$year.'</a>'; $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'.$year.'</a>';
$nav_bar .= ' ('.$year_data['nb_images'].')'; $nav_bar .= ' ('.$year_data['nb_images'].')';
@ -199,13 +262,13 @@ function build_global_calendar(&$requested)
return true; return true;
} }
function build_year_calendar(&$requested) function build_year_calendar()
{ {
assert( count($requested) == 1 ); assert( count($this->date_components) == 1 );
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period, $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period,
COUNT(id) as count'; COUNT(id) as count';
$query.= $this->inner_sql; $query.= $this->inner_sql;
$query.= $this->get_date_where($requested); $query.= $this->get_date_where();
$query.= ' $query.= '
GROUP BY period'; GROUP BY period';
@ -225,18 +288,18 @@ function build_year_calendar(&$requested)
if (count($items)==1) if (count($items)==1)
{ // only one month exists so bail out to month view { // only one month exists so bail out to month view
list($m) = array_keys($items); list($m) = array_keys($items);
array_push($requested, $m ); $this->date_components[CMONTH] = $m;
if (count($items[$m]['children'])==1) if (count($items[$m]['children'])==1)
{ // or even to day view if everything occured in one day { // or even to day view if everything occured in one day
list($d) = array_keys($items[$m]['children']); list($d) = array_keys($items[$m]['children']);
array_push($requested, $d); $this->date_components[CDAY] = $d;
} }
return false; return false;
} }
global $lang, $template; global $lang, $template;
foreach ( $items as $month=>$month_data) foreach ( $items as $month=>$month_data)
{ {
$url_base = $this->url_base.'c-'.$requested[0].'-'.$month; $url_base = $this->url_base.$this->date_components[CYEAR].'-'.$month;
$nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">'; $nav_bar = '<span class="calCalHead"><a href="'.$url_base.'">';
$nav_bar .= $lang['month'][$month].'</a>'; $nav_bar .= $lang['month'][$month].'</a>';
@ -255,12 +318,12 @@ function build_year_calendar(&$requested)
} }
function build_month_calendar($requested) function build_month_calendar()
{ {
$query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%d")) as period, $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%d")) as period,
COUNT(id) as count'; COUNT(id) as count';
$query.= $this->inner_sql; $query.= $this->inner_sql;
$query.= $this->get_date_where($requested, 2); $query.= $this->get_date_where($this->date_components);
$query.= ' $query.= '
GROUP BY period'; GROUP BY period';
@ -277,15 +340,18 @@ function build_month_calendar($requested)
$template->assign_block_vars('thumbnails.line', array()); $template->assign_block_vars('thumbnails.line', array());
foreach ( $items as $day=>$nb_images) foreach ( $items as $day=>$nb_images)
{ {
$url_base = $this->url_base.'c-'.$requested[0].'-'.$requested[1].'-'.$day; $url_base = $this->url_base.
$requested[2]=$day; $this->date_components[CYEAR].'-'.
$this->date_components[CMONTH].'-'.$day;
$this->date_components[CDAY]=$day;
$query = ' $query = '
SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw'; SELECT file,tn_ext,path, DAYOFWEEK('.$this->date_field.')-1 as dw';
$query.= $this->inner_sql; $query.= $this->inner_sql;
$query.= $this->get_date_where($requested); $query.= $this->get_date_where();
$query.= ' $query.= '
ORDER BY RAND() ORDER BY RAND()
LIMIT 0,1'; LIMIT 0,1';
unset ( $this->date_components[CDAY] );
$row = mysql_fetch_array(pwg_query($query)); $row = mysql_fetch_array(pwg_query($query));

View file

@ -26,6 +26,10 @@
include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php');
define ('CYEAR', 0);
define ('CWEEK', 1);
define ('CDAY', 2);
/** /**
* Weekly calendar style (composed of years/week in years and days in week) * Weekly calendar style (composed of years/week in years and days in week)
*/ */
@ -36,52 +40,61 @@ class Calendar extends CalendarBase
* Generate navigation bars for category page * Generate navigation bars for category page
* @return boolean false to indicate that thumbnails where not included here * @return boolean false to indicate that thumbnails where not included here
*/ */
function generate_category_content($url_base, $view_type, &$requested) function generate_category_content($url_base, $view_type)
{ {
global $lang; global $lang, $conf;
$this->url_base = $url_base; $this->url_base = $url_base;
assert($view_type==CAL_VIEW_LIST); assert($view_type==CAL_VIEW_LIST);
$this->build_nav_bar($view_type, $requested, 0, 'YEAR'); // years if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
if (count($requested)>0) {
$this->build_nav_bar($view_type, $requested, 1, 'WEEK', '+1' ); // month $this->build_nav_bar(CYEAR, 'YEAR'); // years
if (count($requested)>1) }
$this->build_nav_bar($view_type, $requested, 2, 'DAYOFWEEK', '-1', if ( count($this->date_components)>=1 and
( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
)
{
$this->build_nav_bar(CWEEK, 'WEEK', '+1' ); // month
}
if ( count($this->date_components)>=2 )
{
$this->build_nav_bar(CDAY, 'DAYOFWEEK', '-1',
$lang['day'] ); // days $lang['day'] ); // days
}
return false; return false;
} }
/** /**
* Returns a sql where subquery for the date field * Returns a sql where subquery for the date field
* @param array requested selected levels for this calendar
* (e.g. 2005,42,1 for 41st week of 2005, Monday)
* @param int max_levels return the where up to this level * @param int max_levels return the where up to this level
* (e.g. 2=only year and week in year) * (e.g. 2=only year and week in year)
* @return string * @return string
*/ */
function get_date_where($requested, $max_levels=3) function get_date_where($max_levels=3)
{ {
while (count($requested)>$max_levels) $date_components = $this->date_components;
while (count($date_components)>$max_levels)
{ {
array_pop($requested); array_pop($date_components);
} }
$res = ''; $res = '';
if (isset($requested[0]) and $requested[0]!='any') if (isset($date_components[CYEAR]) and $date_components[CYEAR]!='any')
{ {
$y = $requested[0]; $y = $date_components[CYEAR];
$res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'"; $res = " AND $this->date_field BETWEEN '$y-01-01' AND '$y-12-31 23:59:59'";
} }
if (isset($requested[1]) and $requested[1]!='any') if (isset($date_components[CWEEK]) and $date_components[CWEEK]!='any')
{ {
$res .= ' AND WEEK('.$this->date_field.')+1='.$requested[1]; $res .= ' AND WEEK('.$this->date_field.')+1='.$date_components[CWEEK];
} }
if (isset($requested[2]) and $requested[2]!='any') if (isset($date_components[CDAY]) and $date_components[CDAY]!='any')
{ {
$res .= ' AND DAYOFWEEK('.$this->date_field.')-1='.$requested[2]; $res .= ' AND DAYOFWEEK('.$this->date_field.')-1='
.$date_components[CDAY];
} }
if (empty($res)) if (empty($res))
{ {
@ -90,6 +103,44 @@ function get_date_where($requested, $max_levels=3)
return $res; return $res;
} }
function get_display_name()
{
global $conf,$lang;
$res = '';
$url = $this->url_base;
if ( isset($this->date_components[CYEAR]) )
{
$res .= $conf['level_separator'];
$url .= $this->date_components[CYEAR].'-';
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label($this->date_components[CYEAR])
.'</a>';
}
if ( isset($this->date_components[CWEEK]) )
{
$res .= $conf['level_separator'];
$url .= $this->date_components[CWEEK].'-';
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label($this->date_components[CWEEK])
.'</a>';
}
if ( isset($this->date_components[CDAY]) )
{
$res .= $conf['level_separator'];
$url .= $this->date_components[CDAY].'-';
$res .=
'<a href="'.$url.'">'
.$this->get_date_component_label(
$this->date_components[CDAY],
$lang['day']
)
.'</a>';
}
return $res;
}
} }
?> ?>

View file

@ -90,6 +90,14 @@ $conf['anti-flood_time'] = 60;
// catgory // catgory
$conf['calendar_datefield'] = 'date_creation'; $conf['calendar_datefield'] = 'date_creation';
// calendar_multi_bar : the calendar shows a maximum number of
// year/month/week/day navigation bars
$conf['calendar_multi_bar'] = true;
// calendar_show_any : the calendar shows an aditional 'any' button in the
// year/month/week/day navigation bars
$conf['calendar_show_any'] = true;
// newcat_default_commentable : at creation, must a category be commentable // newcat_default_commentable : at creation, must a category be commentable
// or not ? // or not ?
$conf['newcat_default_commentable'] = 'true'; $conf['newcat_default_commentable'] = 'true';

View file

@ -27,6 +27,25 @@
define('CAL_VIEW_LIST', 'l'); define('CAL_VIEW_LIST', 'l');
define('CAL_VIEW_CALENDAR', 'c'); define('CAL_VIEW_CALENDAR', 'c');
function get_calendar_parameter($options, &$parameters )
{
if ( count($parameters) and isset($options[$parameters[0]]) )
{
return array_shift($parameters);
}
else
{
foreach ($options as $option => $data)
{
if ( empty( $data['default_link'] ) )
{
break;
}
}
return $option;
}
}
function initialize_calendar() function initialize_calendar()
{ {
global $page, $conf, $user, $template; global $page, $conf, $user, $template;
@ -73,65 +92,76 @@ WHERE id IN (' . implode(',',$page['items']) .')';
//-------------------------------------- initialize the calendar parameters --- //-------------------------------------- initialize the calendar parameters ---
pwg_debug('start initialize_calendar'); pwg_debug('start initialize_calendar');
// the parameters look like (FIELD)?(STYLE)?(VIEW)?(DATE COMPONENTS)?
$cal_styles = array( // FIELD = (created-|posted-)
// STYLE = (m-|w-)
// VIEW = (l-|c-)
// DATE COMPONENTS= YEAR(-MONTH/WEEK)?(-DAY)?
$fields = array(
// Created
'created' => array(
// TODO change next line when calendar_datefield disapears
'default_link' => ( $conf['calendar_datefield']=='date_creation' ? '' : 'created-' ),
'label' => l10n('Creation date'),
'db_field' => 'date_creation',
),
// Posted
'posted' => array(
// TODO change next line when calendar_datefield disapears
'default_link' => ( $conf['calendar_datefield']=='date_available' ? '' : 'posted-' ),
'label' => l10n('Availability date'),
'db_field' => 'date_available',
),
);
$styles = array(
// Monthly style // Monthly style
array( 'monthly' => array(
'link' => 'm',
'default_link' => '', 'default_link' => '',
'name' => l10n('Monthly'), 'label' => l10n('Monthly'),
'include' => 'calendar_monthly.class.php', 'include' => 'calendar_monthly.class.php',
'view_calendar' => true, 'view_calendar' => true,
), ),
// Weekly style // Weekly style
array( 'weekly' => array(
'link' => 'w', 'default_link' => 'weekly-',
'default_link' => 'w-', 'label' => l10n('Weekly'),
'name' => l10n('Weekly'),
'include' => 'calendar_weekly.class.php', 'include' => 'calendar_weekly.class.php',
'view_calendar' => false, 'view_calendar' => false,
), ),
); );
$views = array(
// list view
CAL_VIEW_LIST => array(
'default_link' => '',
'label' => l10n('List')
),
// calendar view
CAL_VIEW_CALENDAR => array(
'default_link' => CAL_VIEW_CALENDAR.'-',
'label' => l10n('calendar')
),
);
$requested = explode('-', $_GET['calendar']); $requested = explode('-', $_GET['calendar']);
$calendar = null;
foreach ($cal_styles as $cal_style)
{
if ($requested[0] == $cal_style['link'])
{
include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
$calendar = new Calendar();
array_shift($requested);
break;
}
}
if (!isset($calendar)) // Retrieve calendar field
$cal_field = get_calendar_parameter($fields, $requested);
// Retrieve style
$cal_style = get_calendar_parameter($styles, $requested);
include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
$calendar = new Calendar();
// Retrieve view
$cal_view = get_calendar_parameter($views, $requested);
if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] )
{ {
foreach($cal_styles as $cal_style) $cal_view=CAL_VIEW_LIST;
{
if ('' == $cal_style['default_link'])
{
break;
}
}
include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
$calendar = new Calendar();
} }
$view_type = CAL_VIEW_LIST;
if ($requested[0] == CAL_VIEW_LIST)
{
array_shift($requested);
}
elseif ($requested[0] == CAL_VIEW_CALENDAR)
{
if ($cal_style['view_calendar'])
{
$view_type = CAL_VIEW_CALENDAR;
}
array_shift($requested);
}
// perform a sanity check on $requested // perform a sanity check on $requested
while (count($requested) > 3) while (count($requested) > 3)
{ {
@ -143,7 +173,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
{ {
if ($requested[$i] == 'any') if ($requested[$i] == 'any')
{ {
if ($view_type == CAL_VIEW_CALENDAR) if ($cal_view == CAL_VIEW_CALENDAR)
{// we dont allow any in calendar view {// we dont allow any in calendar view
while ($i < count($requested)) while ($i < count($requested))
{ {
@ -165,29 +195,26 @@ WHERE id IN (' . implode(',',$page['items']) .')';
{ {
array_pop($requested); array_pop($requested);
} }
$calendar->initialize($conf['calendar_datefield'], $inner_sql);
//echo ('<pre>'. var_export($requested, true) . '</pre>');
//echo ('<pre>'. var_export($calendar, true) . '</pre>');
// TODO: what makes the list view required?
$must_show_list = true;
$calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested);
//echo ('<pre>'. var_export($fields, true) . '</pre>');
$url_base =
PHPWG_ROOT_PATH.'category.php'
.get_query_string_diff(array('start', 'calendar'))
.(empty($url_base) ? '?' : '&')
.'calendar='.$cal_field.'-'
;
$must_show_list = true; // true until calendar generates its own display
if (basename($_SERVER["PHP_SELF"]) == 'category.php') if (basename($_SERVER["PHP_SELF"]) == 'category.php')
{ {
$template->assign_block_vars('calendar', array()); $template->assign_block_vars('calendar', array());
$url_base =
PHPWG_ROOT_PATH.'category.php'
.get_query_string_diff(array('start', 'calendar'))
.(empty($url_base) ? '?' : '&')
.'calendar='
;
if ($calendar->generate_category_content( if ($calendar->generate_category_content(
$url_base.$cal_style['default_link'], $url_base.$cal_style.'-'.$cal_view.'-',
$view_type, $cal_view
$requested
) )
) )
{ {
@ -199,82 +226,60 @@ WHERE id IN (' . implode(',',$page['items']) .')';
$must_show_list = false; $must_show_list = false;
} }
if ($cal_style['view_calendar']) $template->assign_block_vars( 'calendar.views', array() );
{ // Build bar for views (List/Calendar) foreach ($styles as $style => $style_data)
$views = array(
// list view
array(
'type' => CAL_VIEW_LIST,
'label' => l10n('List')
),
// calendar view
array(
'type' => CAL_VIEW_CALENDAR,
'label' => l10n('calendar')
),
);
$views_bar = '';
foreach ($views as $view)
{
if ($view_type != $view['type'])
{
$views_bar.=
'<a href="'
.$url_base.$cal_style['default_link'].$view['type'].'-'
.implode('-', $requested)
.'">'.$view['label'].'</a> ';
}
else
{
$views_bar.= $view['label'].' ';
}
$views_bar.= ' ';
}
$template->assign_block_vars(
'calendar.views',
array(
'BAR' => $views_bar,
)
);
}
// Build bar for calendar styles (Monthly, Weekly)
$styles_bar = '';
foreach ($cal_styles as $style)
{ {
if ($cal_style['link'] != $style['link']) foreach ($views as $view => $view_data)
{ {
$url = $url_base.$style['default_link']; if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
$url .= $view_type;
if (isset($requested[0]))
{ {
$url .= '-' . $requested[0]; $selected = '';
$url = $url_base.$style.'-'.$view;
if ($style==$cal_style)
{
$url .= '-'.implode('-', $calendar->date_components);
if ( $view==$cal_view )
{
$selected = 'SELECTED';
}
}
else
{
if (isset($calendar->date_components[0]))
{
$url .= '-' . $calendar->date_components[0];
}
}
$template->assign_block_vars(
'calendar.views.view',
array(
'VALUE' => $url,
'CONTENT' => $style_data['label'].' ('.$view_data['label'].')',
'SELECTED' => $selected,
)
);
} }
$styles_bar .= '<a href="'. $url . '">'.$style['name'].'</a> ';
}
else
{
$styles_bar .= $style['name'].' ';
} }
} }
$template->assign_block_vars(
'calendar.styles',
array(
'BAR' => $styles_bar,
)
);
} // end category calling } // end category calling
$calendar_title =
'<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
.$fields[$cal_field]['label'].'</a>';
$calendar_title.= $calendar->get_display_name();
$template->assign_block_vars(
'calendar',
array(
'TITLE' => $calendar_title,
)
);
if ($must_show_list) if ($must_show_list)
{ {
$query = 'SELECT DISTINCT(id)'; $query = 'SELECT DISTINCT(id)';
$query .= $calendar->inner_sql; $query .= $calendar->inner_sql;
$query .= $calendar->get_date_where($requested); $query .= $calendar->get_date_where();
if ( isset($page['super_order_by']) ) if ( isset($page['super_order_by']) )
{ {
$query .= ' $query .= '

View file

@ -793,16 +793,9 @@ else
if (!empty($picture['current']['date_creation'])) if (!empty($picture['current']['date_creation']))
{ {
$val = format_date($picture['current']['date_creation']); $val = format_date($picture['current']['date_creation']);
if ( $conf['calendar_datefield'] == 'date_creation' ) $infos['INFO_CREATION_DATE'] = '<a href="'.
{ PHPWG_ROOT_PATH.'category.php?calendar=created-c-'.
$infos['INFO_CREATION_DATE'] = '<a href="'.
PHPWG_ROOT_PATH.'category.php?calendar=c-'.
$picture['current']['date_creation'].'">'.$val.'</a>'; $picture['current']['date_creation'].'">'.$val.'</a>';
}
else
{
$infos['INFO_CREATION_DATE'] = $val;
}
} }
else else
{ {
@ -811,16 +804,9 @@ else
// date of availability // date of availability
$val = format_date($picture['current']['date_available'], 'mysql_datetime'); $val = format_date($picture['current']['date_available'], 'mysql_datetime');
if ( $conf['calendar_datefield'] == 'date_available' ) $infos['INFO_AVAILABILITY_DATE'] = '<a href="'.
{ PHPWG_ROOT_PATH.'category.php?calendar=posted-c-'.
$infos['INFO_AVAILABILITY_DATE'] = '<a href="'. substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
PHPWG_ROOT_PATH.'category.php?calendar=c-'.
substr($picture['current']['date_available'],0,10).'">'.$val.'</a>';
}
else
{
$infos['INFO_AVAILABILITY_DATE'] = $val;
}
// size in pixels // size in pixels
if ($picture['current']['is_picture']) if ($picture['current']['is_picture'])

View file

@ -138,19 +138,23 @@
<!-- END normal_view --> <!-- END normal_view -->
</ul> </ul>
<h2>{TITLE}</h2> <h2>{TITLE}
<!-- BEGIN calendar -->
<br/>{calendar.TITLE}
<!-- END calendar --></h2>
</div> <!-- content --> </div> <!-- content -->
<!-- BEGIN calendar --> <!-- BEGIN calendar -->
<!-- BEGIN styles -->
<div class="calendarStyles">Style: {calendar.styles.BAR}</div>
<!-- END styles -->
<!-- BEGIN views --> <!-- BEGIN views -->
<div class="calendarViews">{calendar.views.BAR}</div> <div class="calendarViews">
<select onchange="document.location = this.options[this.selectedIndex].value;">
<!-- BEGIN view -->
<option value="{calendar.views.view.VALUE}" {calendar.views.view.SELECTED}>{calendar.views.view.CONTENT}</option>
<!-- END view -->
</select>
</div><br/>
<!-- END views --> <!-- END views -->
<br/>
<!-- BEGIN navbar --> <!-- BEGIN navbar -->
<div class="navigationBar">{calendar.navbar.BAR}</div> <div class="navigationBar">{calendar.navbar.BAR}</div>
<!-- END navbar --> <!-- END navbar -->

View file

@ -179,12 +179,8 @@ SPAN.filename:after {
} }
#content DIV.calendarStyles {
float: left;
}
#content DIV.calendarViews { #content DIV.calendarViews {
float: right; float: left;
} }
SPAN.cal { SPAN.cal {