Newer
Older
<?php
/**
* @file
* XC Account module
*
* @copyright (c) 2010-2011 eXtensible Catalog Organization
*/
/**
* Implements hook_permission().
*/
function xc_account_access($account) {
global $user;
return user_access('administer users') ||
user_access('administer xc accounts') ||
($user->uid && ($user->uid == $account->uid));
}
function xc_account_permission() {
return array(
'administer xc accounts' => array(
'title' => t('administer xc accounts'),
'description' => t('administer xc accounts'),
),
'edit own xc account' => array(
'title' => t('edit own xc account'),
'description' => t('edit own xc account'),
),
'edit all xc accounts' => array(
'title' => t('edit all xc accounts'),
'description' => t('edit all xc accounts'),
),
);
}
/**
* @param $node
* Either a node object or the machine name of the content type on which to perform the access check.
* @param $op
* The operation to be performed. Possible values: create, delete, update, view
* The user object to perform the access check operation on.
function xc_account_node_access($node, $op, $account) {
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
return user_access('administer users') ||
user_access('administer xc accounts') ||
($user->uid && ($user->uid == $account->uid));
}
/**
* Implements hook_form_alter().
*/
function xc_account_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_profile_form') {
if (!(($user->uid && ($user->uid == $account->uid) &&
user_access('edit own xc account')) ||
user_access('edit all xc accounts'))) {
unset($form['account']);
}
// Solves problem of Drupal forcing the validation of emails (Part 1)
$fake_email = 'not-a-real-email@c4LSh9V5FztmvkZZZ3eb';
if (empty($form['account']['mail']['#default_value']) || ((is_array($form_state['values']) &&
empty($form_state['values']['mail'])))) {
$form['account']['mail'] = array(
'#type' => 'hidden',
'#value' => $fake_email,
);
}
}
}
/**
* Implements hook_user_presave().
*/
function xc_account_user_presave(&$edit, $account, $category) {
// Solves problem of Drupal forcing the validation of emails (Part 2)
$fake_email = 'not-a-real-email@c4LSh9V5FztmvkZZZ3eb';
if ($edit['mail'] == $fake_email) {
$edit['mail'] = '';
}
}
/**
* Implements hook_user_view().
*/
function xc_account_user_view($account, $view_mode, $langcode) {
if (xc_account_access($account)) {
$personal_info = xc_account_get_personal_information($account);
$xc_account_pi = variable_get('xc_account_pi', array());
$xc_account_pi[$account->uid] = array(
'num_loaned_items' => isset($personal_info['num_loaned_items'])?$personal_info['num_loaned_items']: '',
'num_requested_items' => isset($personal_info['num_requested_items'])?$personal_info['num_requested_items']: '',
variable_set('xc_account_pi', $xc_account_pi);
if (isset($personal_info['name'])
|| (isset($personal_info['address']) && is_array($personal_info['address']))
|| (isset($personal_info['email']) && is_array($personal_info['email']))) {
$account->content['xc_account_personal_info'] = array(
'#type' => 'user_profile_category',
'#title' => t('Personal information'),
'#weight' => -10,
);
$account->content['xc_account_personal_info']['name'] = array(
'#type' => 'user_profile_item',
'#title' => t('Full name'),
'#markup' => is_array($personal_info['name']) ? current($personal_info['name']) : $personal_info['name'],
'#weight' => -10,
);
}
if (isset($personal_info['address']) && is_array($personal_info['address'])) {
foreach ($personal_info['address'] as $address) {
$account->content['xc_account_personal_info']['address'][] = array(
'#type' => 'user_profile_item',
'#title' => t($address['type']),
'#weight' => -6,
);
}
}
if (is_array($personal_info['email'])) {
foreach ($personal_info['email'] as $email) {
$account->content['xc_account_personal_info']['email'][] = array(
'#type' => 'user_profile_item',
'#title' => t($email['type']),
'#weight' => -8,
);
}
}
}
if (!empty($personal_info['num_loaned_items'])
|| !empty($personal_info['num_requested_items'])
|| !empty($personal_info['account_balance'])) {
$account->content['xc_account_status'] = array(
'#type' => 'user_profile_category',
'#title' => t('Library account status'),
'#weight' => -8,
);
if (!empty($personal_info['num_loaned_items'])) {
$link = l(t('(see all)'), 'user/' . $account->uid . '/loaned-items');
$account->content['xc_account_status']['num_loaned_items'] = array(
'#type' => 'user_profile_item',
'#title' => t('Loaned items'),
'#markup' => $personal_info['num_loaned_items'] . ' ' . $link,
'#weight' => -10,
);
}
if (!empty($personal_info['num_requested_items'])) {
$link = l(t('(see all)'), 'user/' . $account->uid . '/requested-items');
$account->content['xc_account_status']['num_requested_items'] = array(
'#type' => 'user_profile_item',
'#title' => t('Requested items'),
'#markup' => $personal_info['num_requested_items'] . ' ' . $link,
'#weight' => -8,
);
}
if (!empty($personal_info['account_balance'])) {
$account->content['xc_account_status']['account_balance'] = array(
'#type' => 'user_profile_item',
'#title' => t('Account balance'),
'#markup' => $personal_info['account_balance'],
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
'#weight' => -6,
);
}
}
}
return;
}
/**
* Implements hook_user().
*/
function xc_account_user_OLD($op, &$edit, &$account, $category = NULL) {
// TODO Remaining code in this function needs to be moved to the appropriate new hook function.
global $user;
}
/**
* Implements hook_menu().
*/
function xc_account_menu() {
// A NOTE: user/%/view weight is 10, we should add lesser weight to position the tabs before view
$items['user/%user/loaned-items'] = array(
'title' => 'Check-out',
'title callback' => 'xc_account_loaned_items_title',
'title arguments' => array(1),
'description' => 'List of checked out items',
'page callback' => 'xc_account_loaned_items',
'page arguments' => array(1),
'access callback' => 'xc_account_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => -20,
);
$items['user/%user/requested-items'] = array(
'title' => 'Requested',
'title callback' => 'xc_account_requested_items_title',
'title arguments' => array(1),
'description' => 'List of requested items',
'page callback' => 'xc_account_requested_items',
'page arguments' => array(1),
'access callback' => 'xc_account_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => -19,
);
$items['user/%user/bookmarked-items'] = array(
'title' => 'Bookmarked',
'title callback' => 'xc_account_bookmarked_items_title',
'title arguments' => array(1),
'description' => 'List of bookmarked items',
'page callback' => 'drupal_get_form',
'page arguments' => array('xc_account_bookmarked_items_form', 1),
'access callback' => 'xc_account_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => -18,
);
/*
$items['user/%user/bookmarked-items/%/request'] = array(
'title' => 'Request item',
'description' => 'Request item',
'page callback' => 'drupal_get_form',
'page arguments' => array('xc_account_bookmarked_item_request_form', 1, 3),
'access callback' => 'xc_account_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
*/
$items['user/%user/bookmarked-items/%/remove'] = array(
'title' => 'Remove item',
'description' => 'Remove item from bookmarks',
'page callback' => 'drupal_get_form',
'page arguments' => array('xc_account_bookmarked_item_remove_form', 1, 3),
'access callback' => 'xc_account_access',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
'weight' => 5,
);
$items['xc/account/email-form'] = array(
'title' => 'Email',
'description' => 'Email results',
'page callback' => 'xc_account_email_form3', //drupal_get_form',
// 'page arguments' => array('xc_account_email_form3'),
'access arguments' => array(TRUE),
// 'access callback' => 'xc_account_access',
// 'access arguments' => array(1),
'type' => MENU_CALLBACK,
'weight' => 5,
);
$items['xc/account/email-form2'] = array(
'title' => 'Email',
'description' => 'Email results',
'page callback' => 'xc_account_email_form2',
'access arguments' => array(TRUE),
// 'access callback' => 'xc_account_access',
// 'access arguments' => array(1),
'type' => MENU_CALLBACK,
'weight' => 5,
);
return $items;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_email_form2() {
return drupal_get_form('xc_account_email_form');
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_email_form3() {
$output = l(t('email'), 'xc/account/email-form2', array('attributes' => array('rel' => 'lightframe')));
return $output;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_email_form($form) {
global $user;
$form['to'] = array(
'#type' => 'textfield',
'#title' => t('To'),
);
$form['from'] = array(
'#type' => 'textfield',
'#title' => t('From'),
'#default_value' => $user->email,
);
$form['comments'] = array(
'#type' => 'textarea',
'#title' => t('Comments'),
);
// TODO: captcha
$form['comments'] = array(
'#type' => 'textarea',
'#title' => t('Comments'),
);
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
);
$form['send'] = array(
'#type' => 'submit',
'#value' => t('Send'),
);
return $form;
}
/**
* Gets checked out items page
*
* @params $account (Object)
* User account object
*
* @return (String)
* Themed list of Checked out items
*/
function xc_account_loaned_items($account, $values = array()) {
$loaned_items = xc_account_get_loaned_items($account, $values);
$xc_account_pi = variable_get('xc_account_pi', array());
$xc_account_pi[$account->uid]['num_loaned_items'] = count($loaned_items);
variable_set('xc_account_pi', $xc_account_pi);
$rows = array();
$i = 0;
$has_bibid = FALSE;
foreach ($loaned_items as $item) {
$schema_field = xc_ils_field_by_provider($item['ncip_provider_id']);
$solr_field = xc_solr_schema2solr($schema_field, TRUE, 'phrase');
$params = array('paths' => $item['renew']['path']);
$form = drupal_get_form('xc_account_renew_form', $params);
++$i;
$row = array(
'data' => array(
array(
'data' => $i . '.',
),
array(
'data' => @date('m/d/Y', $item['date_due']),
'class' => ($item['date_due'] < time() ? array('control overdue') : array('control')),
),
array(
'data' => $form,
);
if (isset($item['bib_id']) && !is_null($item['bib_id'])) {
$has_bibid = TRUE;
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'title', 'check-out'),
);
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'authors'),
);
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'type'),
);
}
else {
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'title', 'check-out'),
'colspan' => 3,
);
}
$rows[] = $row;
}
if ($has_bibid) {
'data' => t('Due Date'),
'colspan' => 3,
'id' => 'xc-check-out-due-date',
),
t('Item'),
t('Author'),
t('Type')
);
'data' => t('Due Date'),
'colspan' => 3,
'id' => 'xc-check-out-due-date',
'data' => t('Item'),
'colspan' => 3,
return theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => array('xc-check-out-items'))
));
} // xc_account_loaned_items
/**
* Renew item form definition
*
* @param $form_state (array)
* FAPI form state
* @param $params (Array)
* Parameters
*
* @return (array)
* FAPI Form definition
*/
function xc_account_renew_form($form, $form_state, $params) {
$form['paths'] = array(
'#type' => 'hidden',
'#value' => $params['paths'],
);
$form['renew'] = array(
'#type' => 'submit',
'#value' => t('Renew'),
'#disabled' => TRUE,
'#attributes' => array('class' => array('renew action-disabled')),
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
);
return $form;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_renew_form_submit($form, &$form_state) {
$form_state['redirect'] = $form_state['values']['paths'];
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_loaned_items_title($account, $values = array()) {
$xc_account_pi = variable_get('xc_account_pi', array());
if (isset($xc_account_pi[$account->uid]['num_loaned_items'])) {
$count = $xc_account_pi[$account->uid]['num_loaned_items'];
}
else {
$count = count(xc_account_get_loaned_items($account, $values));
}
return t('Checked out (@count)', array('@count' => $count));
}
/**
* Requested items page
*/
function xc_account_requested_items($account, $values = array()) {
$requested_items = xc_account_get_requested_items($account, $values);
$xc_account_pi = variable_get('xc_account_pi', array());
$xc_account_pi[$account->uid]['num_requested_items'] = count($requested_items);
variable_set('xc_account_pi', $xc_account_pi);
$header = array('', t('Requested'), t('Due'), t('Item'), t('Author'), t('Type'));
$rows = array();
$i = 0;
$has_bibid = FALSE;
foreach ($requested_items as $item) {
$schema_field = xc_ils_field_by_provider($item['ncip_provider_id']);
$solr_field = xc_solr_schema2solr($schema_field, TRUE, 'phrase');
$row = array(
'data' => array(
array(
'data' => ++$i . '.',
),
array(
'data' => @date('m/d/Y', $item['date_placed']),
),
array(
'data' => @date('m/d/Y', $item['date_due']),
'class' => ($item['date_due'] < time() ? array('control overdue') : array('control')),
);
if (isset($item['bib_id']) && !is_null($item['bib_id'])) {
$has_bibid = TRUE;
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'title', 'requested'),
);
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'authors'),
);
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'type'),
);
}
else {
$row['data'][] = array(
'data' => xc_account_item_get_field($item, $solr_field, 'title', 'check-out'),
'colspan' => 3,
);
}
$rows[] = $row;
}
if ($has_bibid) {
$header = array('', t('Requested'), t('Due'), t('Title'), t('Author'), t('Type'));
}
else {
$header = array('', t('Requested'), t('Due'), array(
'data' => t('Title'),
'colspan' => 3,
));
}
return theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => array('xc-requested-items'))
));
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
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_requested_items_title($account, $values = array()) {
$xc_account_pi = variable_get('xc_account_pi', array());
if (isset($xc_account_pi[$account->uid]['num_requested_items'])) {
$count = $xc_account_pi[$account->uid]['num_requested_items'];
}
else {
$count = count(xc_account_get_requested_items($account, $values));
}
return t('Requested (@count)', array('@count' => $count));
}
/**
* Get a themed title information of the document represented by an NCIP item
*
* @param $item (Array)
* An item description
* @param $solr_field (String)
* A Solr field to search for
*
* @return (String)
* A themed title information
*/
function xc_account_item_to_title($item, $solr_field) {
$bib_id = $item['bib_id'];
$result = xc_search_do_solr_search($solr_field . ':"' . $bib_id . '"');
if (count($result['docs']) > 0) {
$title = theme('xc_account_item_title', array('0' => $result['docs'][0]));
}
elseif (isset($item['bib_desc'])) {
$bib_desc = $item['bib_desc'];
$title = theme('xc_account_bib_desc', array('0' => $bib_desc));
}
else {
$title = $bib_id;
}
return $title;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_item_get_field($item, $solr_field, $target = 'title', $caller = 'check-out') {
static $cache;
if (isset($item['bib_id']) && !is_null($item['bib_id'])) {
$bib_id = $item['bib_id'];
if (!isset($cache['bib'][$bib_id])) {
$result = xc_search_do_solr_search('bibid_s:"' . $bib_id . '"');
if (count($result['docs']) > 0) {
$xc_record = _xc_solr_to_array($result['docs'][0]);
$element = xc_search_get_display_template_elements($xc_record['type'], $xc_record);
$title = l(
xc_util_conditional_join(' — ', $element['title']),
'node/' . $xc_record['node_id'],
array('query' => array('caller' => $caller))
);
$authors = xc_util_conditional_join(' — ', $element['creator']);
$type = xc_search_get_manifestation_formats($xc_record['format']);
}
elseif (isset($item['bib_desc'])) {
$title = $item['bib_desc']['Title'];
$authors = $item['bib_desc']['Author'];
$type = '';
}
else {
$title = $item['title'];
$type = $authors = '';
}
$cache['bib'][$bib_id] = array(
'title' => $title,
'authors' => $authors,
'type' => $type,
);
}
return $cache['bib'][$bib_id][$target];
}
else {
if ($target == 'title') {
return $item['title'];
}
return NULL;
}
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function theme_xc_account_bib_desc($variables) {
$bib_desc = $variables['0'];
$output = '';
$output = $bib_desc['Title'];
if (!preg_match('/ \/ /', $bib_desc['Title'])) {
$output .= ' / ' . $bib_desc['Author'];
}
$output .= ' (' . $bib_desc['Publisher'] . ')';
return $output;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_bookmarked_items_form($form, $form_state, $account) {
$form = array(
'#tree' => TRUE,
);
$bookmarked_items = xc_account_get_bookmarked_items($account);
foreach ($bookmarked_items as $item) {
$i++;
$result = xc_search_do_solr_search('id:"' . $item->sid . '"', TRUE, 0, XC_SEARCH_LIMIT, array('XCNAME' => 'xc_account_bookmarked'));
$doc = $result['docs'][0];
$xc_record = _xc_solr_to_array($doc);
$xc_record['full_display_url'] = xc_search_get_full_display_url($xc_record, $i);
$element = xc_search_get_display_template_elements($xc_record['type'], $xc_record);
$title = l(
xc_util_conditional_join(' — ', $element['title']),
'node/' . $item->nid,
array('query' => array('caller' => 'bookmark', 'hit' => $i), 'html' => TRUE)
);
if (!empty($element['creator'])) {
$authors = t('by !authors', array('!authors' => xc_util_conditional_join(' — ', $element['creator'])));
}
else {
$authors = '';
}
$formats = xc_search_get_manifestation_formats($xc_record['format']);
$form['items'][$i] = array(
'checkmark' => array(
'#type' => 'checkbox',
'#default_value' => 0,
),
'id' => array(
'#type' => 'hidden',
'#value' => $item->id,
),
'uid' => array(
'#type' => 'hidden',
'#value' => $item->uid,
),
'sid' => array(
'#type' => 'hidden',
'#value' => $item->sid,
),
'nid' => array(
'#type' => 'hidden',
'#value' => $item->nid,
),
'htmlid' => array(
'#type' => 'value',
'#value' => 'xc-bookmark-' . $item->id,
),
'title' => array(
'#type' => 'item',
'#value' => $title,
),
'authors' => array(
'#type' => 'item',
'#value' => $authors,
),
'formats' => array(
'#type' => 'item',
'#value' => $formats,
$form['submit'] = array(
'#type' => 'submit',
'#id' => 'dummy-remove-bookmark',
'#value' => t('Remove'),
return $form;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function theme_xc_account_bookmarked_items_form($form) {
$form = xc_account_bookmarked_items_form($form=null,$form_state=null,$account=null);
drupal_add_css(drupal_get_path('module', 'xc_account') . '/bookmarks.css');
drupal_add_js(drupal_get_path('module', 'xc_account') . '/xc_account.js');
$destination = drupal_get_destination();
// TODO The second parameter to this function call should be an array.
drupal_add_js(array('xc_search' => array(
'page' => 'bookmark',
'remove_bookmark_item_url' => url('xc_search/ajax/remove_bookmark_item', array('absolute' => TRUE)),
'print_url' => url('print/', array('absolute' => TRUE)),
'mail_url' => url('printmail/', array('absolute' => TRUE)),
'destination' => $destination,
)), array('type' => 'setting', 'scope' => JS_DEFAULT));
$output = theme('xc_search_bookmark_notification', array());
// draw the table
// $print_exists = module_exists('print');
// $addthis_exists = module_exists('addthis');
foreach (element_children($form['items']) as $item_id) {
drupal_render($form['items'][$item_id]['checkmark']),
'title' => '<span class="title">' . $form['items'][$item_id]['title']['#value'] . '</span>',
'authors'=> '<span class="authors">' . $form['items'][$item_id]['authors']['#value'] . '</span>',
'format' => '<div class="format">' . $form['items'][$item_id]['formats']['#value'] .'</div>',
$header = array('',
array('data' => t('Item'), 'class' => array('item')),
array('data' => t('Author'), 'class' => array('author')),
array('data' => t('Type'), 'class' => array('type')));
$output .= theme('table', array('header' => $header, 'rows' => $rows));
$output .= '<div id="hidden"><div id="dialog-confirm">' // title="Remove selected bookmarks?"
. '<p>'
. t('Are you sure you would like to remove <span id="xc-remove-bookmark-number"></span>?')
. '</p></div></div>';
$output .= drupal_render_children($form);
}
else {
$output = '<p>' . t('There is no bookmarked item yet.') . '</p>';
}
return $output;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_bookmarked_items_form_submit($form, &$form_state) {
foreach ($form_state['values']['items'] as $item) {
if ($item['checkmark'] == 1) {
xc_account_remove_bookmark_item($item['uid'], $item['nid'], $item['sid']);
}
}
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_bookmarked_items_title($account) {
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
$saved_items = xc_account_get_bookmarked_items($account);
return t('Bookmarked (@count)', array('@count' => count($saved_items)));
}
// TODO....
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_bookmarked_item_request_form(&$form_state, $account, $item_id) {
return confirm_form(
array(
'id' => array(
'#type' => 'hidden',
'#default_value' => $item_id,
),
'user_id' => array(
'#type' => 'hidden',
'#default_value' => $account->uid,
),
'type' => array(
'#type' => 'hidden',
'#default_value' => 'bib',
),
),
t('Are you sure, that you would like to request this item?'),
'user/' . $account->uid . '/bookmarked-items', // path to go if user click on 'cancel'
t('This action cannot be undone.'),
t('Request item'),
t('Cancel')
);
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_bookmarked_item_request_form_submit($form, &$form_state) {
/*
$values = $form_state['values'];
$ncip_provider = $values['ncip_provider'];
$user_id = $values['user_id'];
$item_id = $values['item_id'];
$type = 'bib'; //$values['type'];
$request_type = 'Hold'; // $values['request_type'];
$pickup_expiry_date = $values['pickup_expiry_date'];
$shipping_information_address = NULL; // $values['shipping_information_address'];
$response = xc_ncip_provider_request_item($ncip_provider->ncip_provider_id,
$user_id, $item_id, $type, $request_type, $pickup_expiry_date,
$shipping_information_address, 'xml');
*/
$form_state['redirect'] = 'user/' . $uid . '/bookmarked-items';
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function xc_account_bookmarked_item_remove_form($form, &$form_state, $account, $item_id) {
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
return confirm_form(
array(
'id' => array(
'#type' => 'hidden',
'#default_value' => $item_id,
),
'uid' => array(
'#type' => 'hidden',
'#default_value' => $account->uid,
),
),
t('Are you sure, that you would like to remove this item?'),
'user/' . $account->uid . '/bookmarked-items', // path to go if user click on 'cancel'
t('This action cannot be undone.'),
t('Remove item'),
t('Cancel')
);
}
/**
* Creates a new bookmark
*
* @param $uid (int)
* User identifier
* @param $nid (int)
* Node identifier
* @param $sid (String)
* The Solr identifier
*
* @return (int)
* The integer signaling the result of the operation:
* - -1: the bookmark does already exist
* - 0: the operation failed
* - 1: new bookmark were created
*/
function xc_account_bookmark_item($uid, $nid, $sid) {
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
$exists = xc_account_bookmark_item_exists($uid, $nid, $sid);
if (!$exists) {
$record = new stdClass();
$record->uid = $uid;
$record->nid = $nid;
$record->sid = $sid;
$success = drupal_write_record('xc_account_bookmarked_items', $record);
return (int) $success; // FALSE, SAVED_NEW = 1, SAVED_UPDATED = 2
}
else {
return -1;
}
}
/**
* Removes an existing bookmark
*
* @param $uid (int)
* User identifier
* @param $nid (int)
* Node identifier
* @param $sid (String)
* The Solr identifier
*
* @return (int)
* The integer signaling the result of the operation:
* - -1: the bookmark does not exist
* - 0: the operation failed
* - 1: bookmark were deleted
function xc_account_remove_bookmark_item($uid, $nid, $sid) {
$exists = xc_account_bookmark_item_exists($uid, $nid, $sid);
$sql = "DELETE FROM {xc_account_bookmarked_items} WHERE uid = :uid AND nid = :nid";
$result_code = db_query($sql,array('uid'=>$uid,'nid'=> $nid,'sid'=> $sid));
return -1;
}
}
/**
* The submit handler for the remove bookmark form
*
* @param $form (Array)
* The FAPI form definition
* @param $form_state
* The FAPI form state
*/
function xc_account_bookmarked_item_remove_form_submit($form, &$form_state) {
$id = $form_state['values']['id'];
$uid = $form_state['values']['uid'];
$sql = 'DELETE FROM {xc_account_bookmarked_items} WHERE id = :id AND uid = :uid';
$result_code = db_query($sql,array('id'=>$id,'uid'=> $uid));