forked from DBCDK/bibdk_favourite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bibdk_favourite.module
705 lines (618 loc) · 21.4 KB
/
bibdk_favourite.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
<?php
require_once('bibdk_favourite.mypage.inc');
require_once (DRUPAL_ROOT . '/profiles/bibdk/modules/ting_agency/TingAgency.php');
require_once('FavouriteAgency.php');
/**
* Implements hook_add_to_vejviser (@see bibdk_vejviser.module)
* */
function bibdk_favourite_add_to_vejviser($branchId) {
$ret = drupal_get_form('bibdk_favourite_select_form', $branchId);
return drupal_render($ret);
}
/** \brief button to add a library to favourites
* @param type $form
* @param type $form_state
* @return string
*/
function bibdk_favourite_select_form($form, $form_state) {
$form['favourite_button'] = array(
'#type' => 'submit',
'#value' => t('Add to favorite libraries'),
'#ajax' => array(
'callback' => 'bibdk_favourite_ajax_add_favourite',
),
'#attributes' => array(
'class' => array('btn-add-library'),
),
);
//dpm(func_get_args());
return $form;
}
/**
* Ajax callback function
* add favourite to session
* set a message
* */
function bibdk_favourite_ajax_add_favourite($form, $form_state) {
$branchId = $form_state['build_info']['args'][0];
$commands = array();
$response = _bibdk_favourite_save_on_webservice($branchId);
if ($response['status'] != 'error') {
module_load_include('inc', 'bibdk_favourite', 'bibdk_favourite.agencies');
$new_agency = bibdk_favourite_parse_agencies($response['response']);
$check = bibdk_favourite_check_agencies($new_agency, TRUE);
if ($check) {
bibdk_favourite_add_favourite_to_session($check[$branchId]);
$bibname = $check[$branchId]->getBranch()->branchName;
$text = t('@bibname has been added to your favourite libraries', array('@bibname' => $bibname));
}
}
else {
$text = t($response['response']);
////_bibdk_favourite_set_error_text($branchId);
// $commands[] = ajax_command_alert(var_dump($branch));
}
$selector = '.messages_' . $branchId;
drupal_set_message($text);
$commands[] = ajax_command_replace($selector, theme('status_messages'));
return array('#type' => 'ajax', '#commands' => $commands);
}
/**
* Add favourite library to sesssion
* */
function bibdk_favourite_add_favourite_to_session($favourite) {
if (!isset($_SESSION)) {
drupal_session_initialize();
}
// special case. user logs in and selects a favourite BEFORE
// going to favourite_list
if( !isset($_SESSION['bibdk_favourites']) ) {
$_SESSION['bibdk_favourites'] = array();
_bibdk_favourite_set_agencies();
}
if (!isset($_SESSION['bibdk_favourites'][$favourite->getAgencyId()])) {
$_SESSION['bibdk_favourites'][$favourite->getAgencyId()] = serialize($favourite);
}
}
/** \brief delete user on webservice
*
* @global $user
* @param $branchId
* @return FALSE if user is not logged in or is not ding_provider_user
* or something goes wrong. TRUE if all went well
*/
function _bibdk_favourite_delete_on_webservice($branchId) {
global $user;
try {
$creds = ding_user_get_creds($user);
} catch (Exception $e) {
return FALSE;
}
$response = ding_provider_invoke('user', 'delete_favourite', $creds['name'], $branchId);
return $response;
}
/** \brief save user on webservice
*
* @global $user
* @param $branch
* @return array['status','response']; status: error or success, response: string (on error) or xml (on success)
*/
function _bibdk_favourite_save_on_webservice($agencyId) {
// check if user is logged in and if so if user is provider user
global $user;
try {
$creds = ding_user_get_creds($user);
} catch (Exception $e) {
return FALSE;
}
$response = ding_provider_invoke('user', 'add_favourite', $creds['name'], $agencyId);
return $response;
}
/** \ Delete favourite from SESSION and on webservice
*
* @param type $branchId
* @return boolean
*/
function bibdk_favourite_delete_favourite_from_session($branchId) {
unset($_SESSION['bibdk_favourites']);
$ret = TRUE;
$ret = _bibdk_favourite_delete_on_webservice($branchId);
if ($ret && isset($_SESSION['bibdk_favourites'][$branchId])) {
unset($_SESSION['bibdk_favourites'][$branchId]);
}
return $ret;
}
/**
* Implememts hook_user_profile_tabs (@see ding_user.module)
* */
function bibdk_favourite_user_profile2_tabs() {
$ret = new stdClass();
$ret->label = t('favourites');
//$ret->form = 'bibdk_favourite_form_view_items_from_session';
$ret->form = bibdk_favourite_get_forms();
//'bibdk_favourite_get_forms';
$ret->type = 'bibdk_favourite_list';
return $ret;
}
/** \brief get favourites from webservice and add them to session
*
*/
function _bibdk_favourite_set_agencies() {
// try to get from webservice
$agencies = _bibdk_favourite_get_from_webservice();
if (!empty($agencies)) {
// add agencies to session
foreach ($agencies as $favourite) {
bibdk_favourite_add_favourite_to_session($favourite);
}
}
}
function bibdk_favourite_get_forms() {
$agencies = isset($_SESSION['bibdk_favourites']) ? $_SESSION['bibdk_favourites'] : NULL;
if (empty($agencies)) {
_bibdk_favourite_set_agencies();
}
$agencies = isset($_SESSION['bibdk_favourites']) ? $_SESSION['bibdk_favourites'] : NULL;
if (!empty($agencies)) {
foreach ($agencies as $id => $branch) {
$form_ids[] = 'bibdk_favourite_' . $id;
}
return $form_ids;
}
return 'bibdk_favourite_empty_favourite_form';
}
function bibdk_favourite_empty_favourite_form($form, &$form_state){
$form['container'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('element-section'),
),
);
$form['container']['no_agencies'] = array(
'#markup' => t('no_favourites_saved'),
);
return $form;
}
/**
* the form to be displayed on profile tab
* */
function bibdk_favourite_form_view_items_from_session($form, &$form_state, $favourite, $weight) {
require_once('FavouriteAgency.php');
require_once (DRUPAL_ROOT . '/profiles/bibdk/modules/ting_agency/TingAgency.php');
//print_r($favourite);
$fav = unserialize($favourite);
//$favourite = (TingAgency)$favourite;
$branch = $fav->getBranch();
if (empty($branch)) {
return;
}
// check if given branch is set as order-agency
$order_class = ( $fav->getOrderAgency() ) ? 'order-agency' : '';
$form['#title'] = $branch->branchName;
$actions = bibdk_favourite_get_action_links($fav);
$moreinfo = theme('ting_agency_more_info', array('branch' => $branch,
'openingHours' => theme('ting_agency_opening_hours', array('branch' => $branch,)),
'tools' => theme('ting_agency_tools', array('branch' => $branch)),
'address' => theme('ting_agency_address', array('branch' => $branch)),
'contact' => theme('ting_agency_contact', array('branch' => $branch)),
)
);
$classes = array();
$classes[] = 'favourite_' . $fav->getAgencyId();
$classes[] = ( $fav->getOrderAgency() ) ? 'order-agency' : NULL;
$form[$fav->getAgencyId()]['library']['#markup'] =
theme('ting_agency_library', array('branchName' => $branch->branchName, 'agencyName' => $branch->agencyName, 'actions' => $actions, 'add_classes' => $classes, 'moreinfo' => $moreinfo, 'branchid' => $branch->branchId));
// place branch on top if set as order-agency
$form[$fav->getAgencyId()]['#weight'] = ($fav->getOrderAgency()) ? -1 : $weight;
return $form;
}
/*
* Implements hook_forms.
* drupal_get_form uses this hook if given formid is not found
*
* add a form for each of a users favourite agencies.
*/
function bibdk_favourite_forms($form_id) {
// is this a bibdk_favourite form ?
if (strpos($form_id, 'bibdk_favourite_') === 0) {
$agencies = isset($_SESSION['bibdk_favourites']) ? $_SESSION['bibdk_favourites'] : NULL;
if (empty($agencies)) {
_bibdk_favourite_set_agencies();
}
$agencies = isset($_SESSION['bibdk_favourites']) ? $_SESSION['bibdk_favourites'] : array();
$count = 0;
foreach ($agencies as $id => $favourite) {
$forms['bibdk_favourite_' . $id] = array(
'callback' => 'bibdk_favourite_form_view_items_from_session',
'callback arguments' => array(
'favourite' => $favourite,
'weight' => $count++,
),
);
}
return $forms;
}
}
function _bibdk_favourite_set_user_data_page_title($branchid) {
$branchName = '';
if (isset($_SESSION['bibdk_favourites'][$branchid])) {
$favourite = unserialize($_SESSION['bibdk_favourites'][$branchid]);
$branch = $favourite->getBranch();
$branchName = isset($branch->branchName) ? $branch->branchName : '';
}
return t('Edit data for @library', array('@library' => $branchName));
}
/**
* Render user fields;
*/
function bibdk_favourite_user_form_fields($form, &$form_state, $branchid) {
bibdk_favourite_add_js();
if (!isset($_SESSION['bibdk_favourites'])) {
// get agencies
_bibdk_favourite_set_agencies();
}
// set title of page
$page_title = _bibdk_favourite_set_user_data_page_title($branchid);
drupal_set_title($page_title);
$form['wrapper'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('form-section')),
);
$form['#branchid'] = array(
'#type' => 'hidden',
'#value' => $branchid,
);
if (!isset($_SESSION['bibdk_favourites'])) {
$agencies = _bibdk_favourite_get_from_webservice();
foreach ($agencies as $key => $value) {
$_SESSION['bibdk_favourites'][$key] = serialize($value);
}
}
if (isset($_SESSION['bibdk_favourites'][$branchid])) {
$fields = bibdk_favourite_get_agency_fields($branchid);
$agency = unserialize($_SESSION['bibdk_favourites'][$branchid]);
}
else {
// user has no favourites
return array();
}
if (empty($fields) || !is_object($agency)) {
// do something
$form['wrapper']['error'] = array('#markup' => _bibdk_favourite_error_no_agency_user_data());
return $form;
}
$params = $fields->getUserParameters();
if (empty($params)) {
$form['wrapper']['error'] = array('#markup' => _bibdk_favourite_error_no_agency_user_data());
return $form;
}
// checkbox to unmask password fields
$form['wrapper']['uncheck'] = array(
'#title' => t('Show_masked_input'),
'#type' => 'checkbox',
'#attributes' => array('class' => array(drupal_html_class('bibdk_unmask_password_field'))),
);
$userData = $agency->getUserData();
foreach ($fields->getUserParameters() as $userParameter) {
$value = isset($userData[$userParameter['type']]) ? $userData[$userParameter['type']] : NULL;
$type = $userParameter['type'];
$form['wrapper'][$type] = array(
// '#type' => isset($userParameter['field_type']) ? $userParameter['field_type'] : 'textfield',
'#attributes' => array('class' => array((isset($userParameter['field_type']) && $userParameter['field_type'] == 'password') ? drupal_html_class('bibdk_password_field') : '')),
'#type' => 'textfield',
'#title' => isset($userParameter['field_name']) ? $userParameter['field_name'] : "",
'#description' => isset($userParameter['field_description']) ? $userParameter['field_description'] : NULL,
'#required' => $userParameter['required'],
'#default_value' => isset($value) ? $value : "",
);
}
$form['#submit'][] = 'bibdk_favourite_set_userdata';
$form['wrapper']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function bibdk_favourite_set_userdata($form, $form_state) {
$userdata = array();
$valid_fields = array('cpr', 'userId', 'cardno', 'customId', 'pincode', 'userName', 'userAddress', 'userMail', 'userTelephone', 'barcode');
foreach ($form_state['values'] as $key => $value) {
if (in_array($key, $valid_fields)) {
if (!empty($value)) {
$userdata[$key] = $value;
}
}
}
$agencyid = $form['#branchid']['#value'];
bibdk_favourite_save_userdata($agencyid, $userdata);
// clear session
if (isset($_SESSION['bibdk_favourites'])) {
unset($_SESSION['bibdk_favourites']);
}
}
function _bibdk_favourite_error_no_agency_user_data() {
return t('no_agency_data_from_agency');
}
function bibdk_favourite_save_userdata($agencyid, array $userdata) {
global $user;
if (!ding_user_is_provider_user($user)) {
return;
}
try {
$creds = ding_user_get_creds($user);
} catch (Exception $e) {
// do nothing
}
$data = serialize($userdata);
$response = bibdk_provider_user_save_favourite_data($creds['name'], $agencyid, $data);
if ($response !== FALSE) {
drupal_set_message(t('user_changes_saved', array(), array('context' => 'bibdk_favourite')));
}
else {
// @TODO ... do something
}
}
/**
* Get fields required by Agency
* @return \bibdkReservationUserInput
*/
function bibdk_favourite_get_agency_fields($agencyId) {
$agency = new TingAgency($agencyId);
$fields = $agency->getAgencyFields();
return $fields;
}
/**
* \brief Get favourite agencies for the user
*
* @global type $user
* @return TingClientAgencyBranch
*/
function _bibdk_favourite_get_from_webservice() {
global $user;
if (ding_user_is_provider_user($user)) {
try {
$creds = ding_user_get_creds($user);
} catch (Exception $e) {
// do nothing
}
if (empty($creds)) {
return array();
}
// call openuserinfo webservice
$xml = ding_provider_invoke('user', 'get_favourites', $creds['name']);
module_load_include('inc', 'bibdk_favourite', 'bibdk_favourite.agencies');
$saved_agencies = bibdk_favourite_parse_agencies($xml);
if (!$saved_agencies) {
//drupal_set_message(t('bibdk_favourite_something_went_wrong', array(), array('context' => 'bibdk_favourite')), 'error');
return array();
}
// get the real agency(branch)
$client = new ting_client_class();
$agencies = array();
foreach ($saved_agencies as $key => $agency) {
$params = array('action' => 'findLibraryRequest', 'agencyId' => $agency['oui:agencyId']);
// call openagency webservice to get full agencies
// @TODO cache
$result = $client->do_agency($params);
if (isset($result->findLibraryResponse->pickupAgency)) {
// there should be one and only one agency in result
$obj = new TingClientAgencyBranch($result->findLibraryResponse->pickupAgency[0]);
$obj->userdata = unserialize($saved_agencies[$key]['oui:userData']);
$obj->orderLibrary = $saved_agencies[$key]['oui:orderAgency'];
$agencies[$agency['oui:agencyId']] = $obj;
$saved_agencies[$key]['agencyBranch'] = $obj;
}
}
return bibdk_favourite_check_agencies($saved_agencies);
}
// user is not ding_provider_user
return array();
}
function bibdk_favourite_check_agencies($saved_agencies, $add = FALSE) {
if (!$saved_agencies) {
$message = _bibdk_favourite_set_error_text(0);
drupal_set_message($message, 'error');
return array();
}
// get the real agency(branch)
// $client = new ting_client_class();
$agencies = array();
$order_agency = FALSE;
foreach ($saved_agencies as $key => $agency) {
if ($agency['oui:orderAgency'] == 'TRUE') {
$order_agency = TRUE;
}
$agencies[$agency['oui:agencyId']] = new FavouriteAgency($agency);
if (isset($agency['agencyBranch']))
$agencies[$agency['oui:agencyId']]->setBranch($agency['agencyBranch']);
}
if (!$order_agency && !empty($agencies) && !$add) {
// no orderagency is set pick a new favourite as orderagency
$fav = current($agencies);
if (bibdk_favourite_set_favourite($fav->getAgencyId())) {
$fav->orderAgency = 'TRUE';
}
}
return $agencies;
}
/**
* Helper function to add required javascript and CSS to the page.
*/
function bibdk_favourite_add_js() {
// Initialize a flag; we only need to do this one per page request.
static $done = FALSE;
if ($done) {
return;
}
// Add the requisite libraries and our custom js file.
$js_path = drupal_get_path('module', 'bibdk_favourite') . '/js/';
drupal_add_js($js_path . 'setFavourite.js');
// Set flag to true.
$done = TRUE;
}
/** \brief invoke bibdk_providers user_set_favourite method
*
* @global $user $user
* @param mixed $branchId
* @return boolean
*/
function bibdk_favourite_set_favourite($branchId) {
global $user;
if (ding_user_is_provider_user($user)) {
try {
$creds = ding_user_get_creds($user);
} catch (Exception $e) {
// do nothing
}
if (empty($creds)) {
return FALSE;
}
$response = ding_provider_invoke('user', 'set_favourite', $creds['name'], $branchId);
return $response;
}
}
/** \brief get links for editing favourite agency (delete, set as order-agency, edit user data)
*
* @param type $branch
* @return html (unordered list)
*
* NOTICE text and classes are also set in javascript. @see js/setFavourite.js
*/
function bibdk_favourite_get_action_links($favourite) {
bibdk_favourite_add_js();
// add ajax library to intrepret the use-ajax class
drupal_add_library('system', 'drupal.ajax');
$order_agency = ( $favourite->getOrderAgency() ) ? TRUE : FALSE;
if ($order_agency) {
$order_txt = t('Order agency');
$link_class = 'selected-agency';
}
else {
$order_txt = t('set_as_favourite');
$link_class = 'not-selected-agency';
}
$edit_text = ( $favourite->getUserData() ) ? t('edit_user_data', array(), array('context' => 'bibdk_favorite')) : t('add_user_data', array(), array('context' => 'bibdk_favorite'));
$links = array();
$links[] = l($order_txt, 'favourite_set/ajax/' . $favourite->getAgencyId(), array('attributes' => array('class' => array('use-ajax', 'set-default-order-agency', $link_class))));
$links[] = l($edit_text, 'overlay/favourite/userdata/' . $favourite->getAgencyId(), array('attributes' => array('rel' => array('bibdkFavorite'), 'class' => array('edit-personal-info', ' bibdk-popup-link'))));
$links[] = l(t('delete_favourite'), 'favourite_delete/ajax/' . $favourite->getAgencyId(), array('attributes' => array('class' => array('use-ajax', 'delete-favourite'))));
foreach ($links as $link) {
$item['data'] = $link;
$items[] = $item;
}
return theme('item_list', array('items' => $items));
}
/**
* Implements hook_menu
* BIG @TODO access check
*/
function bibdk_favourite_menu() {
global $user;
// form to edit favourite data
$items['overlay/favourite/userdata/%'] = array(
'title' => 'Edit data',
'description' => 'Library helpdesk form.',
'page callback' => 'drupal_get_form',
'page arguments' => array('bibdk_favourite_user_form_fields', 3),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// ajax call for deleting a favourite
$items['favourite_delete/ajax/%'] = array(
'title' => 'ajax_delete_favourite',
'page callback' => 'bibdk_favourite_ajax_link_delete_favourite',
'page arguments' => array(2),
// @TODO set access
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
// ajax call for setting a favourite
$items['favourite_set/ajax/%'] = array(
'title' => 'ajax_set_favourite',
'page callback' => 'bibdk_favourite_ajax_link_set_favourite',
'page arguments' => array(2),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function bibdk_favourite_ajax_command($branchId) {
return array(
'command' => 'favourite_set',
'selector' => 'favourite_' . $branchId,
);
}
/**
* ajax callback for setting order agency
*/
function bibdk_favourite_ajax_link_set_favourite($branchId) {
// add javascript for handling favourite_set
bibdk_favourite_add_js();
unset($_SESSION['bibdk_favourites']);
$response = bibdk_favourite_set_favourite($branchId);
if (!$response) {
$text = _bibdk_favourite_set_error_text($branchId);
$type = 'error';
}
else {
$text = _bibdk_favourite_set_favourite_text($branchId);
$type = 'status';
}
$commands = array();
//clear message stack
drupal_get_messages();
$commands[] = bibdk_favourite_ajax_command($branchId);
// if $response is not set something went wrong
if (!$response) {
drupal_set_message($text, $type);
$commands[] = ajax_command_append($selector, theme('status_messages'));
}
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}
/**
* ajax callback for deleting a favourite library
* */
function bibdk_favourite_ajax_link_delete_favourite($branchId) {
$deleted_agency = unserialize($_SESSION['bibdk_favourites'][$branchId]);
$response = bibdk_favourite_delete_favourite_from_session($branchId);
if (!$response) {
$text = _bibdk_favourite_set_error_text($branchId);
$type = 'error';
}
else {
$text = _bibdk_favourite_set_delete_text($branchId);
$type = 'status';
}
$commands = array();
if($deleted_agency && $deleted_agency->getOrderAgency()){
_bibdk_favourite_set_agencies();
$agencies = isset($_SESSION['bibdk_favourites']) ? $_SESSION['bibdk_favourites'] : NULL;
if ($agencies){
$agency = unserialize(current($agencies));
$commands[] = bibdk_favourite_ajax_command($agency->getAgencyId());
}
}
$selector = '.favourite_' . $branchId;
// clear message stack
drupal_get_messages();
// set message
drupal_set_message($text, $type);
if ($response) {
$commands[] = ajax_command_replace($selector, theme('status_messages'));
}
else {
$commands[] = ajax_command_append($selector, theme('status_messages'));
}
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}
function _bibdk_favourite_set_error_text($branchId) {
return t('bibdk_favourite_something_went_wrong', array(), array('context' => 'bibdk_favourite'));
}
function _bibdk_favourite_set_favourite_text($branchId) {
return t('Favourite library has been set', array(), array('context' => 'bibdk_favourite'));
}
function _bibdk_favourite_set_delete_text($branchId) {
return t('Favourite library has been deleted', array(), array('context' => 'bibdk_favourite'));
}