-
Notifications
You must be signed in to change notification settings - Fork 0
/
ting_local_bibliography.module
187 lines (162 loc) · 5.72 KB
/
ting_local_bibliography.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
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
<?php
define('TING_LOCAL_BIBLIOGRAPHY_DEFAULT_MAILTEXT',
'!name would like to order !material_title (!material_url).
The item should be delivered to !library.
The user provided the following information:
Name: !name
Address: !address
City: !city
Date of birth: !date_of_birth
Email: !email
Phone: !phone');
/**
* Implementation of hook_menu().
*/
function ting_local_bibliography_menu() {
$items = array();
$items['ting/local_bibliography/order/%'] = array(
'title' => 'Order item',
'page callback' => 'ting_local_bibliography_page_order_item',
'page arguments' => array(3),
'access arguments' => array('access content'),
'file' => 'ting_local_bibliography.pages.inc',
'type' => MENU_CALLBACK,
);
$items['admin/settings/ting/local_bibliography'] = array(
'title' => 'Local bibliography settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('ting_local_bibliography_admin_settings_form'),
'access arguments' => array('administer site configuration'),
'file' => 'ting_local_bibliography.admin.inc',
'type' => MENU_LOCAL_TASK,
);
return $items;
}
/**
* Implementation of hook_ting_object_is().
*/
function ting_local_bibliography_ting_object_is($object, $class) {
// Objects are considered local bibliography if they have the
// 'Lokalbibliografi' source.
if ($class == 'local_bibliography') {
foreach($object->record['ac:source'] as $source) {
if (in_array('Lokalbibliografi', $source)) {
return TRUE;
}
}
}
// Local bibliography objects are never of limited availability,
// cartable or reservable.
if (in_array($class, array('limited_availability', 'cartable', 'reservable')) &&
ting_object_is($object, 'local_bibliography')) {
return FALSE;
}
}
/**
* Implementation of hook_ting_object_buttons()
*/
function ting_local_bibliography_ting_object_buttons($object) {
if (ting_object_is($object, 'local_bibliography')) {
$order_id = FALSE;
if (empty($object->record['dcterms:isPartOf'][''])) {
// Local bibliography objects without host objects can be ordered
$order_id = $object->id;
} else {
// Hosts of local bibliography objects which are not available
// as separate objects can be ordered.
foreach ($object->record['dcterms:isPartOf'][''] as $is_part_of) {
$host_object = FALSE;
// Determine if there is a related object which this object is a part of
if (isset($object->relations)) {
foreach ($object->relations as $related_object) {
if ($related_object->relationType == 'isPartOfManifestation' &&
($related_object->ownerId == $object->ownerId ||
$related_object->ownerId == variable_get('ting_agency', NULL))) {
$host_object = $object;
}
}
}
// If object is a local bibliography object with a host object without
// a matching relation then support ordering the object.
// If the host object has a matching relation then the host object should
// be reachable through linked in the material information.
// See helbib_ting_object_update().
if (!$host_object) {
$order_id = $is_part_of;
break;
}
}
}
if ($order_id) {
// Add required assets
ting_local_bibliography_add_css_js();
// Return the button
return array(
array(
'data' => l(t('Order material'), 'ting/local_bibliography/order/' . $order_id),
'class' => 'local-bibliography-order'
)
);
}
}
}
/**
* Implementation of hook_preprocess_ting_object().
*/
function ting_local_bibliography_preprocess_ting_object(&$vars) {
$object = $vars['object'];
// Add object status to main content
if (ting_object_is($object, 'local_bibliography')) {
$vars['additional_main_content'] = array(
'#type' => 'markup',
'#weight' => 0,
'#value' => theme('ting_local_bibliography_object_status', $object),
);
}
}
/**
* Implementation of hook_preprocess_ting_object().
*/
function ting_local_bibliography_preprocess_ting_list_item(&$vars) {
$object = $vars['object'];
// Add object status to main content
if (ting_object_is($object, 'local_bibliography')) {
$vars['additional_content'] = array(
'#type' => 'markup',
'#weight' => 0,
'#value' => theme('ting_local_bibliography_object_status', $object),
);
}
}
/**
* Implementation of hook_theme().
*/
function ting_local_bibliography_theme() {
return array(
'ting_local_bibliography_object_status' => array(
'arguments' => array('object' => NULL),
),
);
}
function theme_ting_local_bibliography_object_status($object) {
return '<div class="ting-status local-bibliography">' . t('Local bibliography') . '</div>';
}
/**
* Add CSS and Javascript used by the module
*/
function ting_local_bibliography_add_css_js() {
// Add jquery validate library and localized messages
drupal_add_js(drupal_get_path('module', 'ting_local_bibliography') . '/js/jquery-validate/jquery.validate.min.js');
drupal_add_js(drupal_get_path('module', 'ting_local_bibliography') . '/js/jquery-validate/additional-methods.min.js');
drupal_add_js(drupal_get_path('module', 'ting_local_bibliography') . '/js/jquery.validate.messages.drupal.js');
// Add module javascript and css
drupal_add_js(drupal_get_path('module', 'ting_local_bibliography') . '/js/ting_local_bibliography.buttons.js');
drupal_add_css(drupal_get_path('module', 'ting_local_bibliography') . '/css/ting_local_bibliography.css');
}
/**
* Implementation of hook_email().
*/
function ting_local_bibliography_mail($key, &$message, $params) {
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
}