-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_item_list.module
More file actions
139 lines (113 loc) · 3.37 KB
/
ding_item_list.module
File metadata and controls
139 lines (113 loc) · 3.37 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
<?php
/**
* @file
*
* Module core file.
*/
// Item list cache validity period (seconds).
// When changing use default simple cache intervals only.
define('DING_ITEM_LIST_CACHE_TLL', 28800);
// Set style for images.
define('DING_ITEM_LIST_IMAGE_STYLE', 'ding_item_list');
/**
* Implements hook_ctools_plugin_directory().
*/
function ding_item_list_ctools_plugin_directory($module, $plugin) {
// we'll be nice and limit scandir() calls
if ($module == 'ctools' && $plugin == 'content_types') {
return 'plugins/content_types';
}
}
/**
* Implements hook_theme().
*/
function ding_item_list_theme($existing, $type, $theme, $path) {
$hooks = array();
$hooks['ding_item_list_list'] = array(
'variables' => array(),
'template' => 'ding-item-list_item-list',
'path' => $path . '/templates',
);
$hooks['ding_item_list_item'] = array(
'variables' => array(),
'template' => 'ding-item-list_item',
'path' => $path . '/templates',
);
return $hooks;
}
/**
* Get ting objects.
*
* @param $query
* Search query string.
* @param $count
* Number of objects to search.
*/
function ding_item_list_get_objects($query = '', $count = 0, $no_cover = FALSE, $sort = '') {
module_load_include('with_images.inc', 'ting');
$results = ting_get_objects_with_images($query, $count, $sort, array(DING_ITEM_LIST_IMAGE_STYLE));
foreach ($results as $search_item) {
$item = new stdClass();
$item->id = $search_item->getId();
$item->local_id = $search_item->getLocalId();
$item->isbn = $search_item->getIsbn();
$item->ac_source = $search_item->getAcSource();
$item->dc_source = $search_item->getSource();
$item->title = $search_item->getTitle();
$item->object = $search_item;
$item->creator = $search_item->getOneOf('creator', 'creator_aut', 'creator_mus');
$item->subject = $search_item->getOneOf('subject_dk5_text', 'subject_genre', 'subject');
$item->description = $search_item->getOneOf('description', 'abstract', 'haspart_track');
$item->year = $search_item->getDate();
// Default values.
$item->type = 1;
$item->rating = 0;
$item->rating_count = 0;
$item->comment_count = 0;
$item->has_rating = FALSE;
$item->image = $search_item->getImage(DING_ITEM_LIST_IMAGE_STYLE);
$item->entity = $search_item;
$objects[$search_item->getLocalId()] = $item;
}
// TODO: Add VoxB info.
return $objects;
}
/**
* Create missed covers.
*
* @param $items
* Set of ting objects.
*/
function ding_item_list_create_missed_covers(&$items) {
module_load_include('pages.inc', 'ting_covers');
$images = array();
foreach ($items as $search_item) {
// Build input for ting cover.
$images[] = $search_item->local_id . ':' . DING_ITEM_LIST_IMAGE_STYLE;
}
$images = _ting_covers_objects($images);
foreach ($items as $item) {
$index = $item->local_id . ':' . DING_ITEM_LIST_IMAGE_STYLE;
if (!empty($images[$index])) {
$item->image = $images[$index];
}
}
return $images;
}
/**
* Generate a cache id, based on a keyword.
*
* @param $keyword
* A generic keyword.
* @return
* Hash string, meaning a certain cache id.
*/
function ding_item_list_generate_cache_id($keyword) {
return 'ding_item_list-' . md5($keyword);
}
/**
* Implements hook_ding_item_cache().
*/
function ding_item_list_ding_item_cache() {
return array('ding_item_list' => t('Ding item list'));
}