if (is_a($content, 'Horde_iCalendar_vevent')) {
$event = $kronolith_driver->getEvent();
$event->fromiCalendar($content);
- $event->calendar = $calendar;
$uid = $event->uid;
// Remove from uids_remove list so we won't delete in the
// end.
if (is_a($content, 'Horde_iCalendar_vevent')) {
$event = $kronolith_driver->getEvent();
$event->fromiCalendar($content);
- $event->calendar = $calendar;
- // Check if the entry already exists in the data source, first
- // by UID.
+ // Check if the entry already exists in the data source,
+ // first by UID.
$uid = $event->uid;
$existing_event = $kronolith_driver->getByUID($uid, array($calendar));
if (!is_a($existing_event, 'PEAR_Error')) {
class Kronolith_Driver
{
/**
- * A hash containing any parameters for the current driver.
+ * The current calendar.
*
- * @var array
+ * @var string
*/
- protected $_params = array();
+ public $calendar;
/**
- * The current calendar.
+ * The HTML background color to be used for this event.
*
* @var string
*/
- public $calendar;
+ public $backgroundColor = '#ddd';
+
+ /**
+ * The HTML foreground color to be used for this event.
+ *
+ * @var string
+ */
+ public $foregroundColor = '#000';
+
+ /**
+ * A hash containing any parameters for the current driver.
+ *
+ * @var array
+ */
+ protected $_params = array();
/**
* An error message to throw when something is wrong.
$this->_params[$param] = $value;
}
+ /**
+ * Selects a calendar as the currently opened calendar.
+ *
+ * @param string $calendar A calendar identifier.
+ */
public function open($calendar)
{
$this->calendar = $calendar;
}
/**
+ * Returns the background color of the current calendar.
+ *
+ * @return string The calendar color.
+ */
+ public function backgroundColor()
+ {
+ return '#dddddd';
+ }
+
+ /**
+ * Returns the colors of the current calendar.
+ *
+ * @return array The calendar background and foreground color.
+ */
+ public function colors()
+ {
+ $color = $this->backgroundColor();
+ return array($color, Kronolith::foregroundColor($color));
+ }
+
+ /**
* Renames a calendar.
*
* @param string $from The current name of the calendar.
*/
private $_cache = array();
+ /**
+ * Returns the background color of the current calendar.
+ *
+ * @return string The calendar color.
+ */
+ public function backgroundColor()
+ {
+ foreach ($GLOBALS['all_remote_calendars'] as $calendar) {
+ if ($calendar['url'] == $this->calendar) {
+ return empty($calendar['color'])
+ ? '#dddddd'
+ : $calendar['color'];
+ }
+ }
+ return '#dddddd';
+ }
+
public function listAlarms($date, $fullevent = false)
{
return array();
$event = new Kronolith_Event_Ical($this);
$event->status = Kronolith::STATUS_FREE;
$event->fromiCalendar($component);
- $event->calendar = $this->calendar;
// Force string so JSON encoding is consistent across drivers.
$event->id = 'ical' . $i;
$event = new Kronolith_Event_Ical($this);
$event->status = Kronolith::STATUS_FREE;
$event->fromiCalendar($components[$eventId]);
- $event->calendar = $this->calendar;
$event->id = 'ical' . $eventId;
return $event;
}
/**
- * Change current calendar
+ * Selects a calendar as the currently opened calendar.
+ *
+ * @param string $calendar A calendar identifier.
*/
public function open($calendar)
{
- if ($this->calendar != $calendar) {
- $this->calendar = $calendar;
- $this->reset();
+ if ($this->calendar == $calendar) {
+ return;
}
+ $this->calendar = $calendar;
+ $this->reset();
+ }
- return true;
+ /**
+ * Returns the background color of the current calendar.
+ *
+ * @return string The calendar color.
+ */
+ public function backgroundColor()
+ {
+ if (isset($GLOBALS['all_calendars'][$this->calendar])) {
+ $share = $GLOBALS['all_calendars'][$this->calendar];
+ $color = $share->get('color');
+ if (!empty($color)) {
+ return $color;
+ }
+ }
+ return '#dddddd';
}
/**
*/
protected $_eventClass = 'Kronolith_Event_Sql';
+ /**
+ * Returns the background color of the current calendar.
+ *
+ * @return string The calendar color.
+ */
+ public function backgroundColor()
+ {
+ if (isset($GLOBALS['all_calendars'][$this->calendar])) {
+ $share = $GLOBALS['all_calendars'][$this->calendar];
+ $color = $share->get('color');
+ if (!empty($color)) {
+ return $color;
+ }
+ }
+ return '#dddddd';
+ }
+
public function listAlarms($date, $fullevent = false)
{
$allevents = $this->listEvents($date, null, false, true);
*
* @var string
*/
- protected $_foregroundColor = '#000';
+ protected $_foregroundColor = '#000000';
/**
* The VarRenderer class to use for printing select elements.
public function __construct($driver, $eventObject = null)
{
$this->calendar = $driver->calendar;
- // FIXME: Move color definitions anywhere else.
- if (!empty($this->calendar) &&
- isset($GLOBALS['all_calendars'][$this->calendar])) {
- $share = $GLOBALS['all_calendars'][$this->calendar];
- $backgroundColor = $share->get('color');
- if (!empty($backgroundColor)) {
- $this->_backgroundColor = $backgroundColor;
- $this->_foregroundColor = Horde_Image::brightness($this->_backgroundColor) < 128 ? '#fff' : '#000';
- }
- }
+ list($this->_backgroundColor, $this->_foregroundColor) = $driver->colors();
- if ($eventObject !== null) {
+ if (!is_null($eventObject)) {
+ $this->fromDriver($eventObject);
/* Get tags */
- $this->fromDriver($eventObject);
$tagger = Kronolith::getTagger();
$this->tags = $tagger->getTags($this->uid, 'event');
*/
public function __construct($driver, $eventObject = null)
{
- static $alarm;
-
/* Set default alarm value. */
if (!isset($alarm) && isset($GLOBALS['prefs'])) {
- $alarm = $GLOBALS['prefs']->getValue('default_alarm');
+ $this->alarm = $GLOBALS['prefs']->getValue('default_alarm');
}
- $this->alarm = $alarm;
-
parent::__construct($driver, $eventObject);
+
+ if (!empty($this->calendar) &&
+ isset($GLOBALS['all_calendars'][$this->calendar])) {
+ $share = $GLOBALS['all_calendars'][$this->calendar];
+ $backgroundColor = $share->get('color');
+ if (!empty($backgroundColor)) {
+ $this->_backgroundColor = $backgroundColor;
+ $this->_foregroundColor = Horde_Image::brightness($this->_backgroundColor) < 128 ? '#fff' : '#000';
+ }
+ }
}
public function fromDriver($SQLEvent)
// Remote calendars
foreach ($GLOBALS['all_remote_calendars'] as $calendar) {
-
$code['conf']['calendars']['remote'][$calendar['url']] = array_merge(
array('name' => $calendar['name'],
'desc' => isset($calendar['desc']) ? $calendar['desc'] : '',
}
/**
- * Returns the foreground color for a calendar.
+ * Returns the foreground color for a calendar or a background color.
+ *
+ * @param array|Horde_Share_Object|string $calendar A color string, a
+ * calendar share or a
+ * hash from a remote
+ * calender definition.
*
- * @param array|Horde_Share_Object $calendar A calendar share or a hash
- * from a remote calender
- * definition.
* @return string A HTML color code.
*/
public static function foregroundColor($calendar)
{
- return Horde_Image::brightness(self::backgroundColor($calendar)) < 128 ? '#fff' : '#000';
+ return Horde_Image::brightness(is_string($calendar) ? $calendar : self::backgroundColor($calendar)) < 128 ? '#fff' : '#000';
}
/**
} else {
/* Create a new event */
$e = $driver->getEvent();
- $e->calendar = $this->get('calendar');
$e->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
$e->save();
}