forked from DBCDK/bibdk_favourite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bibdk_favourite.mypage.inc
73 lines (63 loc) · 2.14 KB
/
bibdk_favourite.mypage.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
<?php
/**
* Implements hook_bibdk_mypage_tabs().
*/
function bibdk_favourite_bibdk_mypage_tabs($max_rows=3) {
global $user;
require_once (DRUPAL_ROOT . '/profiles/bibdk/modules/ting_agency/TingAgency.php');
$form['bibdk_favourite'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
'#theme' => 'bibdk_mypage-form',
'#attributes' => array('class' => array('element-wrapper', 'bibdk-mypage-wrapper')),
);
$form['bibdk_favourite']['header'] = array(
'#type' => 'markup',
'#markup' => t('Favourites'),
);
$form['bibdk_favourite']['rows'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
);
$agencies = _bibdk_favourite_get_from_webservice();
usort($agencies, '_favorite_sort');
if ( sizeof($agencies) > 0 ) {
$agencies = array_slice($agencies, 0, $max_rows);
foreach ($agencies as $id => $favourite) {
$branch = $favourite->getBranch();
if (empty($branch)) {
break;
}
$form['bibdk_favourite']['rows'][$id] = array(
'label_row' => array(
'#type' => 'markup',
'#markup' => $branch->branchName,
),
'value_row' => array(
'#type' => 'markup',
'#markup' => ( $favourite->orderAgency ) ? t('(Order agency)') : NULL,
),
);
}
}
else {
$form['bibdk_favourite']['rows'][] = array(
'item_row' => array(
'#type' => 'markup',
'#markup' => t('No favourites selected yet'),
),
);
}
$form['bibdk_favourite']['link_profile2_tab'] = array(
'#type' => 'link',
'#title' => t('Edit favorites'),
'#title_display' => 'invisible',
'#href' => 'user/' . $user->uid . '/edit/bibdk_favourite_list',
'#options' => array('attributes' => array('title' => t('Edit favorites'))),
);
return $form;
}
function _favorite_sort($a,$b) {
if ( $a->orderAgency == $b->orderAgency ) return 0;
return ( $a->orderAgency < $b->orderAgency ) ? 1 : -1;
}