1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
<?php
require_once 'Horde/Template.php';
/**
* This class represent a view of multiple free busy information sets.
*
* Copyright 2003-2008 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information.
*
* $Horde: kronolith/lib/FBView.php,v 1.10.10.14 2008/03/15 17:30:59 jan Exp $
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @author Jan Schneider <jan@horde.org>
* @package Kronolith
*/
class Kronolith_FreeBusy_View {
var $_requiredMembers = array();
var $_optionalMembers = array();
var $_startHour;
var $_endHour;
var $_startStamp;
var $_endStamp;
function addRequiredMember($vFreebusy)
{
$this->_requiredMembers[] = Util::cloneObject($vFreebusy);
}
function addOptionalMember($vFreebusy)
{
$this->_optionalMembers[] = Util::cloneObject($vFreebusy);
}
function render($day = null)
{
global $prefs;
$this->_startHour = floor($prefs->getValue('day_hour_start') / 2);
$this->_endHour = floor(($prefs->getValue('day_hour_end') + 1) / 2);
$this->_render($day);
require_once 'Horde/iCalendar.php';
$vCal = new Horde_iCalendar();
$required = &Horde_iCalendar::newComponent('vfreebusy', $vCal);
foreach ($this->_requiredMembers as $member) {
$required->merge($member, false);
}
$required->simplify();
$optional = &Horde_iCalendar::newComponent('vfreebusy', $vCal);
foreach ($this->_optionalMembers as $member) {
$optional->merge($member, false);
}
$optional->simplify();
$optimal = &Horde_iCalendar::newComponent('vfreebusy', $vCal);
$optimal->merge($required, false);
$optimal->merge($optional);
$base_url = Horde::selfUrl();
$base_url = Util::removeParameter($base_url, 'date');
$base_url = Util::removeParameter($base_url, 'fbview');
$base_url = Util::addParameter($base_url, 'fbview', $this->view);
$template = &new Horde_Template();
$template->set('title', $this->_title());
$html = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/header.html') .
'<div class="fbgrid">';
$hours_html = $this->_hours();
// set C locale to avoid localized decimal separators during CSS width
// calculation.
$lc = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'C');
// Required to attend.
if (count($this->_requiredMembers) > 0) {
$template = new Horde_Template();
$rows = '';
foreach ($this->_requiredMembers as $member) {
$member->simplify();
$blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy"));
$template = new Horde_Template();
$template->set('blocks', $blocks);
$template->set('name', $member->getName());
$rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
}
$template = new Horde_Template();
$template->set('title', _("Required Attendees"));
$template->set('rows', $rows);
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
$template->set('legend', '');
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
}
// Optional to attend.
if (count($this->_optionalMembers) > 0) {
$template = new Horde_Template();
$rows = '';
foreach ($this->_optionalMembers as $member) {
$member->simplify();
$blocks = $this->_getBlocks($member, $member->getBusyPeriods(), 'busyblock.html', _("Busy"));
$template = new Horde_Template();
$template->set('blocks', $blocks);
$template->set('name', $member->getName());
$rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
}
$template = new Horde_Template();
$template->set('title', _("Optional Attendees"));
$template->set('rows', $rows);
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
$template->set('legend', '');
$html .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html');
}
// Possible meeting times.
$optimal->setAttribute('ORGANIZER', _("All Attendees"));
$blocks = $this->_getBlocks($optimal,
$optimal->getFreePeriods($this->_startStamp, $this->_endStamp),
'meetingblock.html', _("All Attendees"));
$template = new Horde_Template();
$template->set('name', _("All Attendees"));
$template->set('blocks', $blocks);
$rows = $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
// Possible meeting times.
$required->setAttribute('ORGANIZER', _("Required Attendees"));
$blocks = $this->_getBlocks($required,
$required->getFreePeriods($this->_startStamp, $this->_endStamp),
'meetingblock.html', _("Required Attendees"));
$template = new Horde_Template();
$template->set('name', _("Required Attendees"));
$template->set('blocks', $blocks);
$rows .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/row.html');
// Reset locale.
setlocale(LC_NUMERIC, $lc);
$template = new Horde_Template();
$template->set('rows', $rows);
$template->set('title', _("Overview"));
$template->set('span', count($this->_timeBlocks));
$template->set('hours', $hours_html);
if ($prefs->getValue('show_fb_legend')) {
$template->setOption('gettext', true);
$template->set('legend', $template->fetch(KRONOLITH_TEMPLATES . '/fbview/legend.html'));
} else {
$template->set('legend', '');
}
return $html . $template->fetch(KRONOLITH_TEMPLATES . '/fbview/section.html') . '</div>';
}
/**
* Attempts to return a concrete Kronolith_FreeBusy_View instance based on
* $view.
*
* @param string $view The type of concrete Kronolith_FreeBusy_View
* subclass to return.
*
* @return mixed The newly created concrete Kronolith_FreeBusy_View
* instance, or false on an error.
*/
function &factory($view)
{
$driver = basename($view);
require_once dirname(__FILE__) . '/FBView/' . $driver . '.php';
$class = 'Kronolith_FreeBusy_View_' . $driver;
if (class_exists($class)) {
$fbview = new $class($user, $params);
} else {
$fbview = false;
}
return $fbview;
}
/**
* Attempts to return a reference to a concrete Kronolith_FreeBusy_View
* instance based on $view. It will only create a new instance if no
* Kronolith_FreeBusy_View instance with the same parameters currently
* exists.
*
* This method must be invoked as:
* $var = &Kronolith_FreeBusy_View::singleton()
*
* @param string $view The type of concrete Kronolith_FreeBusy_View
* subclass to return.
*
* @return mixed The created concrete Kronolith_FreeBusy_View instance, or
* false on an error.
*/
function &singleton($view)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
if (!isset($instances[$view])) {
$instances[$view] = &Kronolith_FreeBusy_View::factory($view);
}
return $instances[$view];
}
function _getBlocks($member, $periods, $blockfile, $label)
{
$template = new Horde_Template();
$template->set('label', $label);
reset($periods);
list($periodStart, $periodEnd) = each($periods);
$blocks = '';
foreach ($this->_timeBlocks as $start => $end) {
if ($member->getStart() > $start ||
$member->getEnd() < $end) {
$blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/unknownblock.html');
continue;
}
while ($start > $periodEnd &&
list($periodStart, $periodEnd) = each($periods));
if (($periodStart <= $start && $periodEnd >= $start) ||
($periodStart <= $end && $periodEnd >= $end) ||
($periodStart <= $start && $periodEnd >= $end) ||
($periodStart >= $start && $periodEnd <= $end)) {
$l_start = ($periodStart < $start) ? $start : $periodStart;
$l_end = ($periodEnd > $end) ? $end : $periodEnd;
$plen = ($end - $start) / 100.0;
$left = ($l_start - $start) / $plen;
$width = ($l_end - $l_start) / $plen;
$template->set('left', $left . '%');
$template->set('width', $width . '%');
$blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/' . $blockfile);
} else {
$blocks .= $template->fetch(KRONOLITH_TEMPLATES . '/fbview/emptyblock.html');
}
}
return $blocks;
}
}
|