forked from emaV/atrium_event_repeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatrium_event_repeat.module
101 lines (86 loc) · 3.48 KB
/
atrium_event_repeat.module
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
<?php
include_once('atrium_event_repeat.features.inc');
/**
* Implementation of hook_enable().
*/
function atrium_event_repeat_enable() {
// Make sure this module loads after atrium.module.
db_query("UPDATE {system} SET weight = 1 WHERE name = 'atrium_event_repeat'");
}
/**
* Implementation of hook_views_pre_build().
*/
function atrium_event_repeat_views_pre_build(&$view) {
// https://community.openatrium.com/issues/node/1788#comment-8149
// When OG public nodes are in play it is (very) possible to get
// duplicate rows because of the node_access() JOIN and WHERE
// combination. In atrium.module the hook is implemented with
// a rather brute force method of making sure this doesn't
// affect our Views without going through every
// default view and setting the distinct flag.
//
// Here we override the hook for calendar_listing and calendar_upcoming
// views.
if ($view->name=='calendar_listing' || $view->name=='calendar_upcoming') {
$view->display_handler->set_option('distinct', 0);
}
}
/**
* Implementation of hook_theme_registry_alter().
* - override litecal_timeslot theming ONLY if not already overridden by theme.
*/
function atrium_event_repeat_theme_registry_alter(&$theme_registry) {
if ($theme_registry['litecal_timeslot']['function'] == 'theme_litecal_timeslot') {
$theme_registry['litecal_timeslot']['function'] = 'atrium_event_repeat_litecal_timeslot';
}
}
/**
* Theme a single timeslot.
* - solve the Quick add issue
* https://community.openatrium.com/issues/node/1788#comment-9254
*/
function atrium_event_repeat_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']}][value][date]=". date_format_date($date, 'custom', 'm/d/Y') .
"&edit[{$quickadd['field']}][value][time]=" . date_format_date($date, 'custom', 'g:iA') ."&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>";
}