-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_header_opening_hours.module
More file actions
158 lines (137 loc) · 4.72 KB
/
ding_header_opening_hours.module
File metadata and controls
158 lines (137 loc) · 4.72 KB
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
<?php
/**
* @file
* Ding Header Opening Hours module functionality.
*/
/**
* Implements hook_ctools_plugin_directory().
*/
function ding_header_opening_hours_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'ctools' && $plugin_type == 'content_types') {
return 'plugins/' . $plugin_type;
}
}
/**
* Implements hook_block_info().
*/
function ding_header_opening_hours_block_info() {
return array(
'ding_header_opened_today' => array(
'info' => t("Today's opening hours for main library"),
'cache' => DRUPAL_NO_CACHE,
),
'ding_header_opened_today_all' => array(
'info' => t("Today's opening hours for all libraries"),
'cache' => DRUPAL_NO_CACHE,
),
);
}
/**
* Implements hook_block_view().
*/
function ding_header_opening_hours_block_view($delta = '') {
$block = array();
if ($delta == 'ding_header_opened_today') {
$block['subject'] = '';
$block['content'] = theme('ding_header_opened_today_view');
}
if ($delta == 'ding_header_opened_today_all') {
$block['subject'] = t('Opened today');
$block['content'] = theme('ding_header_opened_today_view_all');
}
return $block;
}
/**
* Implements hook_theme().
*/
function ding_header_opening_hours_theme($existing, $type, $theme, $path) {
return array(
'ding_header_opened_today_view' => array(
'path' => $path . '/templates',
'template' => 'ding_header_opened_today_view',
'variables' => array('libraries' => NULL),
),
'ding_header_opened_today_view_all' => array(
'path' => $path . '/templates',
'template' => 'ding_header_opened_today_view_all',
'variables' => array('libraries' => NULL),
),
);
}
/**
* Preprocess variables for ding_header_opened_today_view.
*/
function template_preprocess_ding_header_opened_today_view(&$vars) {
$libraries = array();
$today = date('Y-m-d');
// Load all libraries form list, because there are less libraries than dates
// and because of how opening_hours_instance_load_multiple works.
$sql = 'SELECT nq.qid, nq.show_in_tab, nq.show_in_links, nq.show_in_ui, nq.i18n ' .
'FROM {nodequeue_queue} nq ' .
'INNER JOIN {nodequeue_types} nt ON nt.qid = nq.qid ' .
"WHERE nt.type = :type";
$result = db_query($sql, array(':type' => 'ding_library'));
$qids = array();
foreach ($result as $qid) {
$qids[$qid->qid] = $qid;
}
$queue_id = array_keys($qids);
$nodes = nodequeue_load_nodes($queue_id[0], FALSE, 0, 1);
if (!empty($nodes)) {
foreach ($nodes as $library) {
$libraries[$library->nid]['title'] = $library->title;
}
// Get all dates for today.
if (!empty($libraries) > 0) {
$opening_hours = opening_hours_instance_load_multiple(array_keys($libraries), $today, $today);
$i = 0;
foreach ($opening_hours as $hour) {
$libraries[$hour->nid]['opening_hours'][$i]['start_time'] = $hour->start_time;
$libraries[$hour->nid]['opening_hours'][$i]['end_time'] = $hour->end_time;
$libraries[$hour->nid]['opening_hours'][$i]['notice'] = $hour->notice;
$i++;
}
}
}
$vars['libraries'] = $libraries;
}
/**
* Preprocess variables for ding_header_opened_today_view_all.
*/
function template_preprocess_ding_header_opened_today_view_all(&$vars) {
$libraries = array();
$today = date('Y-m-d');
// Load all libraries form list, because there are less libraries than dates
// and because of how opening_hours_instance_load_multiple works.
$sql = 'SELECT nq.qid, nq.show_in_tab, nq.show_in_links, nq.show_in_ui, nq.i18n ' .
'FROM {nodequeue_queue} nq ' .
'INNER JOIN {nodequeue_types} nt ON nt.qid = nq.qid ' .
"WHERE nt.type = :type";
$result = db_query($sql, array(':type' => 'ding_library'));
$qids = array();
foreach ($result as $qid) {
$qids[$qid->qid] = $qid;
}
$queue_id = array_keys($qids);
$nodes = nodequeue_load_nodes($queue_id[0], FALSE, 0, 50);
if (!empty($nodes)) {
foreach ($nodes as $library) {
$libraries[$library->nid]['title'] = l(
$library->title,
'node/' . $library->nid
);
}
// Get all dates for today.
if (!empty($libraries) > 0) {
$opening_hours = opening_hours_instance_load_multiple(array_keys($libraries), $today, $today);
$i = 0;
foreach ($opening_hours as $hour) {
$libraries[$hour->nid]['opening_hours'][$i]['start_time'] = $hour->start_time;
$libraries[$hour->nid]['opening_hours'][$i]['end_time'] = $hour->end_time;
$libraries[$hour->nid]['opening_hours'][$i]['notice'] = $hour->notice;
$i++;
}
}
}
$vars['libraries'] = $libraries;
}