forked from developmentseed/litecal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
litecal.theme.inc
121 lines (101 loc) · 3.67 KB
/
litecal.theme.inc
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
<?php
/**
* Theme a timespan item.
*/
function theme_litecal_timeitem($item, $granularity) {
$left = number_format($item->start / $granularity * 100, 2);
$width = number_format($item->size / $granularity * 100, 2);
$attr = array('style' => "left:{$left}%; width:{$width}%;");
$attr['class'] = 'litecal-item';
$attr['class'] .= $item->starts ? ' starts' : '';
$attr['class'] .= $item->ends ? ' ends' : '';
if (module_exists('crayon')) {
$attr['class'] .= ' crayon-anchor crayon-'. crayon_generate_index($item->id);
$popup = theme('crayon_popup', $item->data, $item->id);
}
else {
$attr['class'] .= ' color';
$popup = '';
}
if (!empty($item->url)) {
return l("$popup<span class='litecal-data'>{$item->data}</span>", $item->url, array('attributes' => $attr, 'html' => TRUE));
}
else {
$attr = drupal_attributes($attr);
return "<div {$attr}>$popup<span class='litecal-data'>{$item->data}</span></div>";
}
}
/**
* Theme all timeslots for a given timespan.
*/
function theme_litecal_timeslots($timespan, $quickadd = array()) {
switch ($timespan->unit) {
case 'days':
$format = 'j';
break;
}
$slots = array();
$date = drupal_clone($timespan->from);
for ($i = 0; $i < $timespan->granularity; $i++) {
$slots[] = theme('litecal_timeslot', $timespan, $i, $date, $format, $quickadd);
date_modify($date, "+1 {$timespan->unit}");
}
return $slots;
}
/**
* Theme a single timeslot.
*/
function theme_litecal_timeslot($timespan, $start, $date, $format, $quickadd = array()) {
$add = '';
$attr = array('style' => '');
$link_attr = array('class' => 'label');
// Position
if ($start < $timespan->granularity - 1) {
$attr['style'] .= ' left:'. number_format($start / $timespan->granularity * 100, 2) .'%;';
}
// We position last items differently since slots often use borders and need tight alignment.
else {
$attr['style'] .= ' right:0%;';
}
// Width
$attr['style'] .= ' width:'. number_format(1 / $timespan->granularity * 100, 2) .'%';
// Classes
$attr['class'] = 'litecal-slot rows-'. count($timespan->built);
// Add class for today's slot.
static $today;
$today = !isset($today) ? date_format_date(date_now(), 'custom', 'Y-m-d') : $today;
if ($today == date_format_date($date, 'custom', 'Y-m-d')) {
$attr['class'] .= ' litecal-slot-today';
}
// If this timeslot is outside of the timespan's real time range,
// add a class so it can be displayed accordingly.
if (!litecal_date_between($date, $timespan->real_from, $timespan->real_to)) {
$attr['class'] .= ' litecal-slot-gutter';
}
$attr = drupal_attributes($attr);
// Quickadd
if (!empty($quickadd['type'])) {
$type = str_replace('_', '-', $quickadd['type']);
$item = menu_get_item("node/add/{$type}");
if ($item && $item['access']) {
$options = array('query' => "edit[{$quickadd['field']}][0][value]=". date_convert($date, DATE_OBJECT, DATE_ISO) ."&destination=" . $_GET['q']);
$link_attr['href'] = url("node/add/{$type}", $options);
$add = "<span class='add'>". t('+ Add') ."</span>";
}
}
$link_attr = drupal_attributes($link_attr);
$formatted = date_format_date($date, 'custom', $format);
return "<div {$attr}>
<a $link_attr>{$add}<span class='num'>{$formatted}</span></a>
</div>";
}
/**
* Theme a header, like days of the week for a month.
*/
function theme_litecal_header($label, $start, $granularity) {
$left = number_format($start / $granularity * 100, 2);
$width = number_format(1 / $granularity * 100, 2);
$attr = array('style' => "left:{$left}%; width:{$width}%;");
$attr = drupal_attributes($attr);
return "<div class='litecal-label' {$attr}>{$label}</div>";
}