-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCoins.inc
785 lines (729 loc) · 27.6 KB
/
Coins.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
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
<?php
/**
* @file
* Coins.inc
*/
/**
* Class to parse relevant data from MODS, initially used to
* construct the COINS url but has found use elsewhere.
*/
class Coins {
public $pid = NULL;
public $mods = NULL;
public $issn = NULL;
public $volume = NULL;
public $issue = NULL;
public $date = NULL;
public $start_page = NULL;
public $title = NULL;
public $sub_title = NULL;
public $journal_title = NULL;
public $abstract = NULL;
public $names = NULL;
public $authors = NULL;
public $contributors = NULL;
public $reverse_names = NULL;
public $topic = NULL;
public $note = NULL;
public $embargo_date = NULL;
public $sup_embargo_date = NULL;
public $genre = NULL;
public $family_names = NULL;
public $full_names = NULL;
public $username = NULL;
public $department = NULL;
public $type = NULL;
public $status = NULL;
public $isbn = NULL;
public $publishers = NULL;
public $edition = NULL;
public $object = NULL;
/**
* Create the object properties from the MODS datastream
*
* @param type $pid
* The PID of the object that you want to extract the MODS data from
*
* @return type
*/
function __construct($pid) {
$this->pid = $pid;
module_load_include('inc', 'Fedora_Repository', 'api/fedora_item');
$object = new Fedora_Item($pid);
$this->object = $object;
$xmlstr = $object->get_datastream_dissemination('MODS');
if ($xmlstr == NULL || strlen($xmlstr) < 5) {
drupal_set_message(t('No MODS datastream found!', 'warning'));
return " ";
}
$xml = new SimpleXMLElement($xmlstr);
$xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
$this->mods = $xml;
$full_names = array();
$names = array();
$authors = array();
$contributors = array();
$family_names = array();
$i = 0;
foreach ($xml->name as $name) {
foreach ($name->namePart as $name_part) {
if ((string) $name_part != '') {
if ($name_part['type'] == 'given') {
//$names[$i] .= (string) substr(rtrim($name_part, '.'), 0, 1) . '. ';
$names[$i] .= (string) $name_part . ' ';
$full_names[$i] .= (string) $name_part;
}
else {
if ($name_part['type'] == 'family') {
$names[$i] .= (string) rtrim($name_part, '.');
$family_names[$i] = (string) rtrim($name_part, '.');
$full_names[$i] .= ' ' . (string) rtrim($name_part, '.');
}
else {
$names[$i] = trim($name_part);
}
}
}
}
$role = (string) $name->role->roleTerm;
if ($role == 'aut' || $role == 'Author' || $role == 'Creator') {
$role = 'author';
}
if ($role == 'author') {
$authors[] = $names[$i];
}
else {
$contributors[] = $names[$i];
}
$names[$i] .= ' (' . $role . ')';
$i++;
}
$this->names = $names;
$this->full_names = $full_names;
$this->authors = $authors;
$this->contributors = $contributors;
$this->family_names = $family_names;
$form = $xml->physicalDescription->form;
if (!empty($form)) {
foreach ($xml->physicalDescription->form as $form) {
if ($form['authority'] == 'local' && (string) $form != 'NO_OBJ') {
$this->status = 'FULL_TEXT_AVAILABLE';
$this->type = (string) $form;
}
}
}
$reverse = array();
$i = 0;
foreach ($xml->name as $name) {
foreach ($name->namePart as $name_part) {
if ($name_part['type'] == 'family') {
$reverse_family[$i] .= (string) rtrim($name_part, '.');
}
if ($name_part['type'] == 'given') {
$reverse_given[$i] .= (string) rtrim($name_part, '.');
}
$reverse[$i] = $reverse_family[$i] . ', ' . $reverse_given[$i] . '.';
}
$i++;
}
$this->reverse_names = $reverse;
$publishers = $xml->xpath('/mods:mods/mods:originInfo/mods:publisher');
$this->publishers = implode(', ', $publishers);
$edition = $xml->xpath('//mods:originInfo/mods:edition');
$this->edition = $edition[0];
$issn = $xml->xpath('//mods:identifier[@type="issn"]');
$this->issn = $this->check_issn($issn);
$isbn = $xml->xpath('//mods:identifier[@type="isbn"]');
$this->isbn = str_replace(array(
"&",
"=",
",",
";"
), array(
'',
'',
'',
''
), (string) $isbn[0]);
//$this->date = $xml->part->date;
$date = $xml->xpath('//mods:originInfo/mods:dateIssued');
if (isset($date[0])) {
$this->date = $date[0];
}
$date = $xml->xpath('//mods:originInfo/mods:dateCreated');
if ($this->date == NULL) {
$this->date = $date[0];
}
if ($this->date == NULL) {
$this->date = $xml->originInfo->dateCreated;
}
$volume = $xml->xpath('//mods:part/mods:detail[@type="volume"]');
$this->volume = $volume[0]->number;
$issue = $xml->xpath('//mods:part/mods:detail[@type="issue"]');
$this->issue = $issue[0]->number;
$start_page = $xml->xpath('//mods:extent[@unit="page"]/mods:start');
$this->start_page = $start_page[0];
$title = $xml->xpath('/mods:mods/mods:titleInfo/mods:title');
$this->title = $title[0];
$sub_title = $xml->xpath('/mods:mods/mods:titleInfo/mods:subTitle');
$this->sub_title = $sub_title[0];
$journal_title = $xml->xpath('//mods:relatedItem[@type="host"]//mods:title');
$this->journal_title = $journal_title[0];
$abstract = $xml->xpath('//mods:abstract');
$this->abstract = $abstract[0];
$topic = array();
foreach ($xml->subject as $subject) {
$topic[] = $subject->topic;
}
$this->topic = $topic;
$notes = array();
foreach ($xml->note as $note) {
$notes[] = $note;
}
$this->note = $note;
$embargo_date = $xml->xpath('//mods:dateOther[@type="embargo"]');
$this->embargo_date = $embargo_date[0];
$sup_embargo_date = $xml->xpath('//mods:dateOther[@type="supp_embargo"]');
$this->sup_embargo_date = $sup_embargo_date[0];
$genre = $xml->xpath('//mods:genre');
$this->genre = $genre;
$username = $xml->xpath('//mods:identifier[@type="u1"]');
$this->username = $username;
$department = $xml->xpath('//mods:identifier[@type="u2"]');
$this->department = $department;
}
/**
* validates an issn. If the issn does not have a - (dash) this funciton inserts
* one
* @param mixed $issn
* @return mixed
* returns FALSE if issn is not valid otherwise returns the parsed issn.
*/
function check_issn($issn) {
if (is_array($issn)) {
$issns = $issn[0];
}
else {
$issns = $issn;
}
$tmp = explode(',', $issns);
$tmp = $tmp[0];
//RETURNING here as the validation below failed in some cases and needs investigation
return $tmp;
$tmp = preg_replace('{[^0-9X]}', '', $tmp);
// get length
$length = strlen($tmp);
// get checksum
$checksum = ($tmp[($length - 1)] === 'X') ? 10 : intval($tmp[($length - 1)]);
// calculate checksum
if ($length === 8) {
$sum = NULL;
for ($i = 1; $i < $length; $i++) {
$sum += (8 - ($i - 1)) * $tmp[($i - 1)];
}
$sum = 11 - $sum % 11;
//$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
$tmp = (substr($tmp, 0, 4) . '-' . substr($tmp, 4, 7)); //put the dash back
return $sum === $checksum ? $tmp : FALSE;
}
return FALSE;
}
/**
* Function to return citation details in a table-ready form
*
* @param string $type
* Type of reference that is being used. Default value is citation but
* thesis and book are also valid. This parameter will change the values
* that are returned when the render_view function is called
*
* @return type
* An array containing the headers and rows ready to put into a table describing
* the reference
*/
function render_view($type = 'citation') {
$modsxml = $this->mods;
global $base_url;
$fedora_url = variable_get('fedora_base_url', 'http://localhost:8080/fedora');
$headers = array('', '');
$rows = array();
$genre = (string) $this->genre[0];
if (!empty($genre)) {
switch ((string) $genre) {
case 'Journal Article':
//journal stuff
$this->get_title($rows, 'Title');
$authors = implode(', ', $this->authors);
if (!empty($authors) && strlen(trim($authors)) > 1) {
$rows[] = array('Author(s)', $authors);
}
$journal = $modsxml->xpath('/mods:mods/mods:relatedItem/mods:titleInfo[not(@type="abbreviated")]/mods:title');
$journal = implode(', ', $journal);
if (!empty($journal) && strlen(trim($journal)) > 1) {
$rows[] = array('Journal', $journal);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
if (isset($this->volume)) {
$rows[] = array('Volume', $this->volume);
}
if (isset($this->issue)) {
$rows[] = array('Issue', $this->issue);
}
if (!empty($this->start_page)) {
$rows[] = array('Start page', $this->start_page);
}
$endp = $modsxml->xpath('//mods:extent[@unit="page"]/mods:end');
$endp = implode(',', $endp);
if (!empty($endp) && strlen(trim($endp)) > 1) {
$rows[] = array('End page', $endp);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$doi = $modsxml->xpath('//mods:identifier[@type="doi"]');
$doi = implode(',', $doi);
if (!empty($doi) && strlen(trim($doi)) > 1) {
$rows[] = array('DOI', l($doi, 'http://dx.doi.org/' . $doi));
}
// arXiv identifier
$arxiv = $modsxml->xpath('//mods:identifier[@type="arxiv"]');
$arxiv = implode(',', $arxiv);
if (!empty($arxiv) && strlen(trim($arxiv)) > 1) {
$rows[] = array(
'arXiv',
l($arxiv, 'http://arxiv.org/abs/' . $arxiv)
);
}
// PubMed Identifier
$pmid = $modsxml->xpath('//mods:identifier[@type="pmid"]');
$pmid = implode(',', $pmid);
if (!empty($pmid) && strlen(trim($pmid)) > 1) {
$rows[] = array(
'PubMed ID',
l($pmid, 'http://www.ncbi.nlm.nih.gov/pubmed/' . $pmid)
);
}
// PubMed Central Identifier
$pmcid = $modsxml->xpath('//mods:identifier[@type="pmcid"]');
$pmcid = implode(',', $pmcid);
if (!empty($pmcid) && strlen(trim($pmcid)) > 1) {
$rows[] = array(
'PubMed Central ID',
l($pmcid, 'http://www.ncbi.nlm.nih.gov/pmc/articles/' . $pmcid)
);
}
$issn = $this->issn;
$this->get_availability($rows);
$this->get_use($rows);
break;
case 'Book, Whole':
$this->get_title($rows, 'Title');
$authors = implode(', ', $this->authors);
if (!empty($authors) && strlen(trim($authors)) > 1) {
$rows[] = array('Author(s)', $authors);
}
if (!empty($this->edition)) {
$rows[] = array('Edition', $this->edition);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
$this->populate_publishers_row($rows);
$this->populate_place_row($rows, "Place published");
$pages = $modsxml->xpath('/mods:mods/mods:physicalDescription/mods:extent');
$pages = implode(', ', $pages);
if (!empty($pages) && strlen(trim($pages)) > 1) {
$rows[] = array('Pages', $pages);
}
$isbn = $modsxml->xpath('/mods:identifier[@type="isbn"]');
$isbn = implode(', ', $isbn);
if (!empty($isbn) && strlen(trim($isbn)) > 1) {
$rows[] = array('ISBN', $isbn);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$this->get_availability($rows);
$this->get_use($rows);
break;
case 'Book, Section':
$this->get_title($rows, 'Section title');
$authors = implode(', ', $this->authors);
if (!empty($authors)) {
$rows[] = array('Section author(s)', $authors);
}
$btitle = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:title');
$btitle = (string) $btitle[0];
$bsub_title = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:subTitle');
$bsub_title = (string) $bsub_title[0];
if (!empty($bsub_title)) {
$btitle = $btitle . ': ' . $bsub_title;
}
if (!empty($btitle)) {
$rows[] = array('Book title', $btitle);
}
$beditors = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:name');
$beditors_arr = array();
foreach ($beditors as $beditor) {
$value = trim((string) $beditor->namePart[0] . ' ' . (string) $beditor->namePart[1]);
if (!empty($value)) {
$beditors_arr[] = $value;
}
}
$editor_name = implode(', ', $beditors_arr);
if (!empty($editor_name)) {
$rows[] = array('Book editor(s)', $editor_name);
}
if (!empty($this->edition)) {
$rows[] = array('Edition', $this->edition);
}
if (!empty($this->start_page)) {
$rows[] = array('Start page', $this->start_page);
}
$endp = $modsxml->xpath('//mods:extent[@unit="page"]/mods:end');
$endp = implode(',', $endp);
if (!empty($endp) && strlen(trim($endp)) > 1) {
$rows[] = array('End page', $endp);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
$this->populate_publishers_row($rows);
$this->populate_place_row($rows, "Place published");
$isbn = $modsxml->xpath('/mods:identifier[@type="isbn"]');
$isbn = implode(', ', $isbn);
if (!empty($isbn) && strlen(trim($isbn)) > 1) {
$rows[] = array('ISBN', $isbn);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$this->get_availability($rows);
$this->get_use($rows);
break;
case 'thesis':
case 'Signature Project':
case 'MEd Project':
case 'MN Project':
case 'Thesis':
$this->get_title($rows, 'Title');
$authors = implode(', ', $this->authors);
if (!empty($authors) && strlen(trim($authors)) > 1) {
$rows[] = array('Author(s)', $authors);
}
$btitle = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:title');
$btitle = (string) $btitle[0];
$bsub_title = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:subTitle');
$bsub_title = (string) $bsub_title[0];
if (!empty($bsub_title)) {
$btitle = $btitle . ': ' . $bsub_title;
}
if (!empty($btitle)) {
$rows[] = array('Related item', $btitle);
}
if (!empty($this->start_page)) {
$rows[] = array('Start page', $this->start_page);
}
$endp = $modsxml->xpath('//mods:extent[@unit="page"]/mods:end');
$endp = implode(',', $endp);
if (!empty($endp) && strlen(trim($endp)) > 1) {
$rows[] = array('End page', $endp);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
$this->populate_publishers_row($rows, 'Institution');
//advisor
$advisors = $modsxml->xpath('/mods:mods/mods:name[@type="personal"]');
$this->get_advisors_by_type($rows, 'Supervisor(s)', array(
"Signature Project Advisor",
"Thesis advisor",
"MEd Project Advisor",
"MN Project Advisor"
), $advisors);
$this->get_advisors_by_type($rows, 'Committee member(s)', array("Committee member"), $advisors);
$this->get_advisors_by_type($rows, 'Supervisory Committee Member(s)', array("Supervisory Committee Member"), $advisors);
$this->get_advisors_by_type($rows, 'Examination Committee Member(s)', array("Examination Committee Member"), $advisors);
$modsxml->registerXPathNamespace('etd', 'http://www.ndltd.org/standards/metadata/etdms/1.0');
$degree_name = $modsxml->xpath('//etd:name');
$degree_name = (string) $degree_name[0];
$degree_level = $modsxml->xpath('//etd:level');
$degree_level = (string) $degree_level[0];
if (!empty($degree_name) && !empty($degree_level)) {
$rows[] = array('Degree earned', $degree_name);
}
$this->populate_place_row($rows, "Place published");
$isbn = $modsxml->xpath('/mods:identifier[@type="isbn"]');
$isbn = implode(', ', $isbn);
if (!empty($isbn) && strlen(trim($isbn)) > 1) {
$rows[] = array('ISBN', $isbn);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$this->get_availability($rows);
$this->get_use($rows);
break;
case 'Conference Proceedings':
$this->get_title($rows, 'Paper title');
$authors = implode(', ', $this->authors);
if (!empty($authors) && strlen(trim($authors)) > 1) {
$rows[] = array('Paper author(s)', $authors);
}
$pro_title = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:title');
$pro_sub_title = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:subTitle');
$pro_title = (string) $pro_title[0]; //implode(', ', $pro_title);
$pro_sub_title = (string) $pro_sub_title[0]; //implode(',', $pro_sub_title);
if (!empty($pro_sub_title[0])) {
$pro_title = $pro_title . ': ' . $pro_sub_title;
}
if (!empty($pro_title)) {
$rows[] = array('Proceedings title', $pro_title);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
$beditors = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:name/mods:namePart');
$beditors = implode(', ', $beditors);
if (!empty($beditors) && strlen(trim($beditors)) > 1) {
$rows[] = array('Conference', $beditors);
}
$this->populate_publishers_row($rows);
$this->populate_place_row($rows, "Place published");
$pages = $modsxml->xpath('/mods:mods/mods:physicalDescription/mods:extent');
$pages = implode(', ', $pages);
if (!empty($pages) && strlen(trim($pages)) > 1) {
$rows[] = array('Pages', $pages);
}
$isbn = $modsxml->xpath('/mods:identifier[@type="isbn"]');
$isbn = implode(', ', $isbn);
if (!empty($isbn) && strlen(trim($isbn)) > 1) {
$rows[] = array('ISBN', $isbn);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$this->get_availability($rows);
$this->get_use($rows);
break;
case 'Book, Edited':
$this->get_title($rows, 'Title');
$authors = implode(', ', $this->authors);
if (!empty($authors) && strlen(trim($authors)) > 1) {
$rows[] = array('Editor(s)', $authors);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
$this->populate_publishers_row($rows);
$this->populate_place_row($rows, "Place published");
$pages = $modsxml->xpath('/mods:mods/mods:physicalDescription/mods:extent');
$pages = implode(', ', $pages);
if (!empty($pages) && strlen(trim($pages)) > 1) {
$rows[] = array('Pages', $pages);
}
$isbn = $modsxml->xpath('/mods:identifier[@type="isbn"]');
$isbn = implode(', ', $isbn);
if (!empty($isbn) && strlen(trim($isbn)) > 1) {
$rows[] = array('ISBN', $isbn);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$this->get_availability($rows);
$this->get_use($rows);
break;
default:
$this->get_title($rows, 'Title');
$authors = implode(', ', $this->authors);
if (!empty($authors) && strlen(trim($authors)) > 1) {
$rows[] = array('Author(s)', $authors);
}
$btitle = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:title');
$btitle = (string) $btitle[0];
$bsub_title = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:subTitle');
$bsub_title = (string) $bsub_title[0];
if (!empty($bsub_title)) {
$btitle = $btitle . ': ' . $bsub_title;
}
if (!empty($btitle)) {
$rows[] = array('Related item', $btitle);
}
$beditors = $modsxml->xpath('/mods:mods/mods:relatedItem[@type="host"]/mods:name/mods:namePart');
$beditors = implode(', ', $beditors);
if (!empty($beditors) && strlen(trim($beditors)) > 1) {
$rows[] = array('Editors', $beditors);
}
if (!empty($this->start_page)) {
$rows[] = array('Start page', $this->start_page);
}
$endp = $modsxml->xpath('//mods:extent[@unit="page"]/mods:end');
$endp = implode(',', $endp);
if (!empty($endp) && strlen(trim($endp)) > 1) {
$rows[] = array('End page', $endp);
}
if ((string) $this->date != NULL) {
$rows[] = array('Date', $this->date);
}
$this->populate_publishers_row($rows);
$this->populate_place_row($rows, "Place published");
$isbn = $modsxml->xpath('/mods:identifier[@type="isbn"]');
$isbn = implode(', ', $isbn);
if (!empty($isbn) && strlen(trim($isbn)) > 1) {
$rows[] = array('ISBN', $isbn);
}
if (!empty($this->abstract)) {
$rows[] = array('Abstract', $this->abstract);
}
$this->get_availability($rows);
$this->get_use($rows);
break;
}
}
$ds_array = $this->object->get_datastreams_list_as_array();
$download_url = $this->get_download_url($ds_array);
if (!empty($download_url)) {
$rows[] = array(
'Text',
l($download_url, $download_url)
);
}
return array(
'headers' => $headers,
'rows' => $rows,
);
}
function populate_publishers_row(&$rows, $label = "Publisher") {
if (!empty($this->publishers) && strlen(trim($this->publishers)) > 1) {
$rows[] = array($label, $this->publishers);
}
}
function get_download_url($ds_array, $absolute = TRUE) {
$check = NULL;
if (array_key_exists('OBJ', $ds_array) &&
strstr($ds_array['OBJ']['MIMEType'],'pdf') ) { //check status in case ds exists but is embargoed
$check = 'OBJ';
}
if (array_key_exists('PDF', $ds_array)) {
$check = 'PDF';
}
$embargoed = $this->is_embargoed($this->embargo_date);
$url_path = 'fedora/repository/';
if ($check && !$embargoed) {
if (module_exists('scholar_tracking')) {
$url_path = 'download_ds/';
}
$url = $url_path . $this->pid . '/' . $check . '/'. str_replace(':', '_', $this->pid) . '.pdf';
if($absolute){
return url($url, array('absolute' => $absolute));
} else {
return $url;
}
}
return NULL;
}
function get_advisors_by_type(&$rows, $label, $roles, $advisors) {
$i = 0;
$advisor_name = '';
foreach ($advisors as $advisor) {
if (in_array($advisor->role->roleTerm, $roles)) {
//if ($advisor->role->roleTerm == "Signature Project Advisor" || $advisor->role->roleTerm == "Thesis advisor") {
if ($i > 0) {
$advisor_name .= ', ';
}
$advisor_name .= (string) $advisor->namePart[0] . ' ' . (string) $advisor->namePart[1] . ' ' . (string) $advisor->namePart[2];
$advisor_name = trim($advisor_name);
if (!empty($advisor_name)) {
$i++;
}
}
}
if (!empty($advisor_name)) {
$advisor_name = trim($advisor_name);
$rows[] = array($label, $advisor_name);
}
}
function get_altmetrics_text($doi) {
if (empty($doi)) {
return '';
}
$text = '<span class="altmetrics">
<span class="altmetric-embed" data-badge-popover="right" data-doi="' .
$doi . '">
</span>
</span>';
return $text;
}
function get_title(&$rows, $label) {
$title = $this->mods->xpath('/mods:mods/mods:titleInfo/mods:title');
$title = (string) $title[0];
$sub_title = $this->mods->xpath('/mods:mods/mods:titleInfo/mods:subTitle');
$sub_title = (string) $sub_title[0];
if (!empty($sub_title)) {
$title = $title . ': ' . $sub_title;
}
if (!empty($title)) {
$rows[] = array($label, $title);
}
}
function populate_place_row(&$rows, $label = "Place published") {
$place = $this->mods->xpath('/mods:mods/mods:originInfo/mods:place/mods:placeTerm');
$place = implode(', ', $place);
if (!empty($place) && strlen(trim($place)) > 1) {
$rows[] = array($label, $place);
}
}
/**
* gets the title we want to send to godot (UPEI resolver)
* we send the host title if it is a book chapter or section
* otherwise its the normal title
* @return string
*/
function get_godot_title() {
$title = $this->title;
if ($this->genre[0] == 'Book, Section' || $this->genre[0] == 'Book, Chapter') {
module_load_include('php', 'citeproc', 'generators/converter.php');
$title = convert_mods_to_citeproc_json_title($this->mods, '/mods:mods/mods:relatedItem[@type="host"]/mods:titleInfo/mods:title');
}
return $title;
}
function get_use(&$rows) {
$use = $this->mods->xpath('/mods:mods/mods:accessCondition[@type="use and reproduction"]');
$use = implode('<br /><br /> ', $use);
$search_arr = array('Contact Author', 'Contact Publisher');
$replace_arr = array(
'<a href="mailto:publications@upei.ca?subject=Scholar Contact request for object ' . $this->pid . '">Contact Author</a>',
'<a href="mailto:publications@upei.ca?subject=' . $pid . '">Contact Publisher</a>'
);
$use = str_replace($search_arr, $replace_arr, trim($use));
if (!empty($use)) {
$rows[] = array('Use/Reproduction', $use);
}
}
function get_availability(&$rows) {
if ($this->embargo_date != NULL && $this->is_embargoed($this->embargo_date)) {
$embargo_date = date('r', tstamptotime((string) $this->embargo_date));
$rows[] = array(
'Availability',
'This item is not yet available online, but may be available on request. Please contact the
<a href="mailto:publications@upei.ca?subject=IslandScholar Request">Robertson Library</a> if you wish to access this document. ' . $embargo_date
);
}
}
function is_embargoed($embargo_date) {
if ($embargo_date === NULL) {
return FALSE;
}
$embargo_timestamp = strtotime($embargo_date);
if (!$embargo_timestamp) {
return FALSE;
}
$today = time();
$embargoed = FALSE;
if ($embargo_timestamp > $today) {
$embargoed = TRUE;
}
return $embargoed;
}
}