-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscholar.module
1149 lines (1044 loc) · 40.3 KB
/
scholar.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
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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
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
898
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
934
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
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @file
*/
/**
* Constants
*/
define('ISLANDORA_SCHOLAR_JOURNAL_FORM_NAME', 'Islandora Scholar Journal Form');
define('ISLANDORA_SCHOLAR_THESIS_FORM_NAME', 'Islandora Scholar Thesis Form');
define('MENU_SCHOLAR_HOME', 'scholar');
define('MENU_SCHOLAR_ADVANCED_SEARCH_ADD_FIELD', 'scholar/search/advanced/field/add');
define('MENU_SCHOLAR_ADVANCED_SEARCH_REMOVE_FIELD', 'scholar/search/advanced/field/remove');
define('THEME_SCHOLAR_HOME', 'scholar_home');
define('THEME_SCHOLAR_SEARCH_ITEM', 'scholar_search_item');
define('THEME_SCHOLAR_SEARCH_TABLE', 'scholar_search_results_table');
define('THEME_SCHOLAR_OVERVIEW_PANEL_CITATION', 'scholar_overview_panel_citation');
module_load_include('php', 'scholar', 'IrClass');
function scholar_edit_refworks($pid) {
return drupal_get_form('scholar_edit_refworks_form', $pid);
}
function scholar_edit_refworks_form($form_state, $pid) {
$edit_refworks_form = new IrClass();
return $edit_refworks_form->buildRefworksEditForm($pid);
}
function scholar_edit_refworks_form_submit($form, &$form_state) {
$irClass = new IrClass();
$form_state['redirect'] = $irClass->updateRefworksMetaData($form_state['values']);
}
function scholar_by_name($type, $query) {
$irClass = new IrClass();
$user = $irClass->get_user_by_username($query);
$output = "<h4 align='center'>$user</h4>";
$output .= '<center><table class="table-form"><tr>' . drupal_get_form('scholar_browse_by_user_form') . '</tr></table></center>';
$output .= scholar_custom_search($type, $query, 0);
return $output;
}
function scholar_role($type, $query) {
$role = $query; //
$irClass = new IrClass();
//real bad hack to change home economics and ohters to something different (ldap groups are incorrect in ldap server so they say)
$department = $query;
if ('Home Economics' == $department) {
$department = 'Family and Nutritional Sciences';
}
elseif ('Anatomy Physiology' == $department) {
$department = 'Biomedical Sciences';
}
elseif ('Womens Studies' == $department) {
$department = "Women's Studies";
}
elseif ('Path Micro' == $department) {
$department = "Pathology and Microbiology";
}
elseif ('Soc Anth' == $department) {
$department = "Sociology and Anthropology";
}
$output = "<h4 align='center'>$department</h4>";
$usersArray = array();
$results = scholar_custom_search($type, $query, 0, 0, $usersArray);
$output .= '<center><table class="table-form"><tr>' . drupal_get_form('scholar_browse_by_user_form', $role, $usersArray) . '</tr></table></center>';
return $output . $results;
}
function scholar_add_ir_datastream_form($form_state, $pid) {
$datastream_form = new IrClass();
return $datastream_form->build_add_datastream_form($pid);
}
function scholar_add_ir_datastream_form_submit($form, &$form_state) {
$ir = new IrClass();
$ir->addStreamFormSubmit($form_state['values']['form_id'], $form_state['values']);
}
/*
* defines the list of paths and hooks/callbacks for the scholar module
*/
function scholar_menu() {
$items = array();
$items[MENU_SCHOLAR_ADVANCED_SEARCH_ADD_FIELD] = array(
'file' => 'SearchForm.inc',
'page callback' => 'scholar_search_advanced_add_field',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items[MENU_SCHOLAR_ADVANCED_SEARCH_REMOVE_FIELD] = array(
'file' => 'SearchForm.inc',
'page callback' => 'scholar_search_advanced_remove_field',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['admin/settings/scholar'] = array(
'title' => t('Islandora Scholar Settings'),
'description' => t('Configure Islandora Scholar settings.'),
'file' => 'includes/scholar.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_admin_settings'),
'access callback' => 'user_access',
'access arguments' => array('administer scholar settings'),
'type' => MENU_NORMAL_ITEM,
);
$items['add_users/%'] = array(
'title' => t('Add Users'),
'file' => 'Users.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_get_ldap_users_form', 1),
'access callback' => 'user_access',
'access arguments' => array('add users'),
'type' => MENU_NORMAL_ITEM,
);
$items['search_users'] = array(
'title' => t('Import Users'),
'file' => 'Users.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_ldap_users_search_form'),
'access callback' => 'user_access',
'access arguments' => array('add users'),
'type' => MENU_NORMAL_ITEM,
);
$items['browse_authors/%'] = array(
'title' => t('Browse Authors'),
'file' => 'BrowseByUserForm.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_browse_by_user_form', 1),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['browse_scholars'] = array(
'title' => t('Scholars'),
'file' => 'BrowseByUserForm.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_scholar_browse_by_author_form'),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['browse_scholars/%'] = array(
'title' => t('Scholars'),
'file' => 'BrowseByUserForm.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_scholar_browse_by_author_form', 1),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['browse_users_dept/%'] = array(
'title' => t('Browse Users by Dept'),
'file' => 'BrowseByUserForm.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_browse_by_user_dept_form', 1),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['browse_dept'] = array(
'title' => t('Browse Organizations'),
'file' => 'BrowseByDeptForm.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_browse_by_dept_form'),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['islandora_autocomplete/%/%/%'] = array(
'title' => 'Auto Complete',
'description' => 'Islandora autocomplete',
'file' => 'includes/scholar.autocomplete.inc',
'page callback' => 'islandora_autocomplete',
'page arguments' => array(1, 2, 3),
'access arguments' => array('view fedora collection'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
$items['islandora_autocomplete/%/%'] = array(
'title' => 'Auto Complete',
'description' => 'Islandora autocomplete',
'file' => 'includes/scholar.autocomplete.inc',
'page callback' => 'islandora_autocomplete',
'page arguments' => array(1, 2),
'access arguments' => array('view fedora collection'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
$items['rss/%'] = array(
'title' => 'RSS feed',
'description' => 'RSS feed',
'file' => 'SearchForm.inc',
'page callback' => 'scholar_rss_feed',
'page arguments' => array(1),
'access arguments' => array('view fedora collection'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
$items['refworks_migrate'] = array(
'title' => 'Refworks migrate',
'description' => 'Migrate content from refworks',
'file' => 'includes/scholar.migrate.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('scholar_migrate_refworks_form'),
'access callback' => 'user_access',
'access arguments' => array('migrate content'), // Use something fedora specific.
'type' => MENU_NORMAL_ITEM,
);
$items['refworks_entry/%'] = array(
'title' => 'Refworks entry',
'description' => 'Page to display refworks entry for a given pid',
'file' => 'refworks.inc',
'page callback' => 'scholar_refworks_add_form',
'page arguments' => array(1),
'access callback' => 'user_access',
'access arguments' => array('refworks entry'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
$items['users_suggest'] = array(
'title' => 'Users suggest',
'description' => 'Migrate content from refworks',
'file' => 'Users.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_scholar_researcher_compare_form'),
'access callback' => 'user_access',
'access arguments' => array('migrate content'), // Use something fedora specific.
'type' => MENU_NORMAL_ITEM,
);
$items['scholar_associate/%'] = array(
'title' => 'Associate citation',
'description' => 'Associate citation with researcher and department',
'file' => 'Users.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_scholar_associate_citation_form', 1),
'access callback' => 'user_access',
'access arguments' => array('migrate content'), // Use something fedora specific.
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Valid permissions for this module
* @return array An array of valid permissions for the IR module
*/
function scholar_perm() {
return array(
'view signature tab',
'add scholarly research',
'view scholarly research',
'administer scholarly research',
'add users',
'migrate content',
'refworks entry',
'manage tracking',
'administer scholar settings',
);
}
/**
* implement our own query block so we can style it
* @return type
*/
function scholar_islandora_solr_query_blocks() {
return array(
'scholar_current_query' => array(
'name' => t('Scholar Current Query'),
'module' => 'scholar',
'file' => 'includes/scholar.blocks.inc',
'class' => 'ScholarSearchResults',
'function' => 'currentQuery',
'form' => NULL,
),
);
}
/**
* Alter the login block to say UPEI
*
* @param type $form
* @param type $form_state
* @param type $form_id
*/
function scholar_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_login') {
$form['name']['#attributes']['placeholder'] = t('Username');
$form['pass']['#attributes']['placeholder'] = t('Password');
$form['name']['#description'] = t('Enter your UPEI username.');
}
}
/**
* alter the user creation form.
*
*
*/
function scholar_form_user_register_alter(&$form, &$form_state) {
$form['scholar'] = array(
'#type' => 'fieldset',
'#title' => t('Scholar'),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['scholar']['given_name'] = array(
'#type' => 'textfield',
'#title' => t('Given Name'),
'#maxlength' => '128',
//'#required' => TRUE,
);
$form['scholar']['family_name'] = array(
'#type' => 'textfield',
'#title' => t('Family Name'),
'#maxlength' => '128',
//'#required' => TRUE,
);
$form['scholar']['display_name'] = array(
'#type' => 'textfield',
'#title' => t('Display Name'),
'#maxlength' => '128',
// '#required' => TRUE,
'#description' => 'Enter the name as you would like to see it displayed. ie. John Doe. If this field is blank then no Authority object will be created in the repository.
A drupal user will still be created.'
);
$form['scholar']['date'] = array(
'#type' => 'textfield',
'#title' => t('Date'),
'#maxlength' => '128',
//'#required' => TRUE,
'#description' => t('Birth date - death date'),
);
$form['scholar']['department'] = array(
'#type' => 'textfield',
'#title' => t('Department'),
'#maxlength' => '128',
//'#required' => TRUE,
);
$form['scholar']['position'] = array(
'#type' => 'select',
'#title' => t('Position'),
'#maxlength' => '128',
//'#required' => TRUE,
'#options' => array(
'EmeritusFaculty' => t('Emeritus Faculty'),
'Emeritis Librarian' => t('Emeritus Librarian'),
'Faculty Member' => t('Faculty Member'),
'Librarian' => t('Librarian'),
'NonAcademic' => t('Non Academic'),
'Postdoc' => t('Postdoc'),
'GraduateStudent' => t('Graduate Student'),
'UndergraduateStudent' => t('Under Graduate Student'),
),
);
$form['scholar']['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#maxlength' => '128',
//'#required' => TRUE,
);
$form['scholar']['start_date'] = array(
'#type' => 'date',
'#title' => t('Start Date at UPEI'),
'#required' => TRUE,
);
$form['scholar']['end_date'] = array(
'#type' => 'date',
'#title' => t('End Date at UPEI'),
//'#required' => TRUE,
);
$form['scholar']['scholar_status'] = array(
'#type' => 'select',
'#title' => t('Status'),
'#options' => array(
'Current' => t('Current'),
'Retired' => t('Retired'),
'Other' => t('Other'),
),
);
$form['scholar']['notes'] = array(
'#type' => 'textarea',
'#title' => t('Notes'),
'#maxlength' => '128',
//'#required' => TRUE,
);
$form['scholar']['url'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#maxlength' => '255',
//'#required' => TRUE,
);
//$form['#validate'][] = 'scholar_add_user_to_fedora_validate';
$form['#submit'][] = 'scholar_add_user_to_fedora';
}
//function scholar_add_user_to_fedora_validate(&$form, &$form_state) {
//}
function scholar_add_user_to_fedora(&$form, &$form_state) {
module_load_include('inc', 'scholar', 'includes/scholar.user');
scholar_create_user_object($form, $form_state);
}
function scholar_uninstall() {
return drupal_uninstall_schema('scholar');
}
// end function scholar_uninstall
function fedora_repository_scholar_settings_page() {
}
/**
* Function specifying all of the required objects and database
* entries for Fedora/Islandora
* @return type
*/
function scholar_required_fedora_objects() {
$module_path = drupal_get_path('module', 'scholar');
// Put the form in the database
module_load_include('inc', 'xml_form_builder', 'XMLFormDatabase');
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_JOURNAL_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/journal_article_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_JOURNAL_FORM_NAME, $definition);
}
if (!XMLFormDatabase::Exists(ISLANDORA_SCHOLAR_THESIS_FORM_NAME)) {
$definition = new DOMDocument();
$definition->load($module_path . '/forms/thesis_form.xml');
XMLFormDatabase::Create(ISLANDORA_SCHOLAR_THESIS_FORM_NAME, $definition);
}
// Associates the form with the content model
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:citationCModel', 'Islandora Scholar Journal Form'));
if (!$result) {
$object = new stdClass();
$object->content_model = 'islandora:citationCModel';
$object->form_name = 'Islandora Scholar Journal Form';
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
}
$result2 = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"', 'islandora:researcherCModel', 'Islandora Scholar MADS Form'));
if (!$result2) {
$object2 = new stdClass();
$object2->content_model = 'islandora:researcherCModel';
$object2->form_name = 'Islandora Scholar MADS Form';
$object2->dsid = 'MADS';
$object2->title_field = "['titleInfo']['title']";
$object2->transform = 'mads_to_dc.xsl';
$result2 = drupal_write_record('islandora_content_model_forms', $object2);
}
return array(
'scholar' => array(
'module' => 'scholar',
'title' => 'Islandora Scholar Module',
'objects' => array(
array(
'pid' => 'ir:scholar',
'label' => 'Institutional Repository',
'cmodel' => 'islandora:collectionCModel',
// 'parent' => variable_get('fedora_repository_pid', 'islandora:root'),
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/COLLECTION-COLLECTION POLICY.xml",
),
),
),
array(
'pid' => 'islandora:citationCModel',
'label' => 'Islandora Scholar Citation Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/models/citationCModel.xml",
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'islandora:thesisCModel',
'label' => 'Islandora Scholar Thesis Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/models/thesisCModel.xml",
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'islandora:researcherCModel',
'label' => 'Islandora Scholar Authority Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/models/researcherCModel.xml",
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'islandora:departmentCModel',
'label' => 'Islandora Scholar Department Content Model',
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/models/departmentCModel.xml",
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array(
'pid' => 'ir:citationCollection',
'label' => 'Citation Collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'ir:scholar',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/CITATION-COLLECTION POLICY.xml",
),
array(
'dsid' => 'COLLECTION_VIEW',
'datastream_file' => "$module_path/xsl/citation_collection_view.xsl",
),
),
),
array(
'pid' => 'ir:thesisCollection',
'label' => 'Thesis Collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'ir:scholar',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/THESIS-COLLECTION POLICY.xml",
),
array(
'dsid' => 'CHILD_SECURITY',
'datastream_file' => "$module_path/xacml/both-embargo.xml",
),
),
),
array(
'pid' => 'ir:authorityCollection',
'label' => 'IR Authority Collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'ir:scholar',
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_filesystem_folder_grey.png",
'mimetype' => 'image/png',
),
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/AUTHORITY-COLLECTION POLICY.xml",
),
),
),
),
),
);
}
function scholar_form_fedora_repository_ingest_form_alter(array &$form, array &$form_state) {
if ($form_state['storage']['step'] == 1 && isset($form['indicator'])) {
$models = array('islandora:citationCModel/ISLANDORACM');
$show_bulk_ingest = FALSE;
foreach ($form['indicator']['models']['#options'] as $model => $label) {
if (array_search($model, $models) !== FALSE) {
$show_bulk_ingest = TRUE;
}
}
if ($show_bulk_ingest) {
$bulk_ingest = scholar_bulk_ingest_form($form_state, $form['collection_pid']['#value']);
// Move the next button within the field set to make it clearer.
$form['indicator']['submit'] = $form['submit'];
unset($form['submit']);
array_unshift($form, $bulk_ingest);
$form['#attributes'] = array('enctype' => 'multipart/form-data'); // Allow the uploading of files.
$form['#validate'] = array('scholar_bulk_ingest_form_validate');
}
}
//add a handler so we can update the rels-ext
$form['#submit'][] = 'scholar_auto_associate';
}
function scholar_auto_associate(&$form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($form_state['values']['pid']);
if (!empty($form_state['values']['identifier_u1_tags'])) {
foreach ($form_state['values']['identifier_u1_tags'] as $user) {
// add a rels relationship
//add_relationship($relationship, $object, $namespaceURI = RELS_EXT_URI, $literal_value = RELS_TYPE_URI) {
$item->add_relationship('hasResearcher', $user['identifier_u1'], 'info:fedora/fedora-system:def/relations-external#');
}
}
if (!empty($form_state['values']['identifier_u2_tags'])) {
foreach ($form_state['values']['identifier_u2_tags'] as $department) {
// add a rels relationship
$value = str_replace(' ', '_', $department['identifier_u2']);
$item->add_relationship('hasDepartment', $value, 'info:fedora/fedora-system:def/relations-external#');
}
}
}
/**
* Performs a bulk ingestion.
*
* This is not meant to be called from drupal_get_form,
* this is a sub-form that part of the content_model_viewer_ingest_metadata
*
* @param array $form_state
* The Drupal form state.
* @param string $collection_pid
* The pid of the collection we will ingest into.
*
* @return array
* The Drupal form.
*/
function scholar_bulk_ingest_form(array &$form_state, $collection_pid) {
$path = drupal_get_path('module', 'scholar');
drupal_add_js("$path/js/islandora_scholar.js");
drupal_add_css("$path/css/scholar.css");
$potential_models = scholar_bulk_ingest_get_potential_models($collection_pid);
reset($potential_models);
$identifier = key($potential_models);
$selected_model = isset($form_state['values']['models']) ? $form_state['values']['models'] : $identifier;
$markup = '<div id = "scholar_choice_buttons">';
$markup .= '<button id = "single" class = "scholar_button">Create Single Citation</button><br />';
$markup .= '<button id = "RIS" class = "scholar_button">RIS, Endnote or RefWorks</button><br />';
$markup .= '<button id = "PUBMD" class = "scholar_button">Import using PMIDs</button><br />';
$markup .= '<button id = "DOI" class = "scholar_button">Import using DOIs</button>';
$form['buttons'] = array(
'#type' => 'markup',
'#value' => $markup,
'#attributes' => array('class' => 'myclass')
);
$form['bulk_ingest'] = array(
'#type' => 'fieldset',
'#title' => t('Ingest digital objects generated by RIS, EndNote or RefWorks into collection_pid Step #1', array('collection_pid' => $collection_pid)),
'#attributes' => array('id' => 'bulk_ingest', 'class' => 'scholar_choice'),
'file' => array(
'#type' => 'file',
'#title' => t('Upload "RIS", "EndNote XML" or "RefWorks XML" Document'),
'#description' => t('A RIS, EndNote XML, or RefWorks XML document that will generate multiple digital objects on ingest. One for each record within the RIS, EndNote XML, or RefWorks document.'),
'#element_validate' => array('scholar_bulk_ingest_file_upload_validate'),
),
'content_model_pid' => array(
'#type' => 'select',
'#title' => t('Content models available'),
'#options' => $potential_models,
'#default_value' => $selected_model,
'#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.<br /> Additional information may be found <a href="https://wiki.duraspace.org/display/FEDORACREATE/Content+Models+Overview">here.</a> '),
),
'submit' => array(
'#type' => 'submit',
'#executes_submit_callback' => TRUE,
'#submit' => array('scholar_bulk_ingest_form_submit'),
'#value' => t('Create objects from document.'),
'#attributes' => array('class' => 'file_submit', 'source' => 'ris'),
),
);
// Harvest records from pubmed.
$form['pubmed'] = array(
'#type' => 'fieldset',
'#title' => t('Pubmed IDs'),
'#description' => t('A list Pubmed IDs.'),
'#attributes' => array('id' => 'pubmed', 'class' => 'scholar_choice'),
);
$form['pubmed']['pubmed_file'] = array(
'#type' => 'file',
'#title' => t('Pubmed Batch Importer'),
'#description' => t("Give either a list of Pubmed IDs in a file, or enter the list in the textarea. In either case, the items in the list should be separated by either whitespace or commas (or some combination thereof)."),
'#element_validate' => array('scholar_bulk_ingest_file_upload_validate'),
);
$form['pubmed']['pubmed_list'] = array(
'#type' => 'textarea',
'#title' => t('Pubmed IDs'),
'#description' => t('A list Pubmed IDs.'),
'#element_validate' => array('scholar_bulk_ingest_file_upload_validate'),
);
$form['pubmed']['submit'] = array(
'#type' => 'submit',
'#executes_submit_callback' => TRUE,
'#submit' => array('scholar_bulk_ingest_form_submit'),
'#value' => t('Create Pubmed Objects'),
'#attributes' => array('class' => 'file_submit', 'source' => 'pubmed'),
);
// Harvest records from DOI
$form['doi'] = array(
'#type' => 'fieldset',
'#title' => t('DOI IDs'),
'#description' => t('A list DOI IDs.'),
'#attributes' => array('id' => 'doi', 'class' => 'scholar_choice'),
);
$form['doi']['doi_file'] = array(
'#type' => 'file',
'#title' => t('DOI Batch Importer'),
'#description' => t('Provide either a list of Digital Object Identifiers in a file, or enter DOIs in the textarea below. In either case, the DOIs in the list should be separated by either whitespace or commas (or some combination thereof). NOTE: Presently, only journal (articles) are supported.'),
'#element_validate' => array('scholar_bulk_ingest_file_upload_validate'),
);
$form['doi']['doi_list'] = array(
'#type' => 'textarea',
'#title' => t('DOI IDs'),
'#description' => t('Provide a list Digital Object Identifiers (DOI) - eg. 10.1016/j.jorganchem.2011.11.018, 10.1016/j.tiv.2011.10.017, 10.1111/j.1540-4560.2012.01733.x '),
'#element_validate' => array('scholar_bulk_ingest_file_upload_validate'),
);
$form['doi']['submit'] = array(
'#type' => 'submit',
'#executes_submit_callback' => TRUE,
'#submit' => array('scholar_bulk_ingest_form_submit'),
'#value' => t('Create DOI Objects'),
'#attributes' => array('class' => 'file_submit', 'source' => 'doi'),
);
return $form;
}
/**
* Get Potential Models that can be part of the given collection.
*
* @param string $collection_pid
* The pid of the collection.
* @return array
* Where the key is the Content Model PID and the value is the human readable name for the Content Model.
*/
function scholar_bulk_ingest_get_potential_models($collection_pid) {
if (($collection_policy = CollectionPolicy::loadFromCollection($collection_pid)) === FALSE) {
drupal_set_message(t("Unable to load collection policy '@collection_pid'", array('@collection_pid' => $collection_pid)));
return FALSE;
}
if (!($content_models = $collection_policy->getContentModels())) {
drupal_set_message(t('No content models associated with this collection: @collection_pid. Please contact your administrator.', array('@collection_pid' => $collection_pid)), 'error');
return FALSE;
}
$potential_models = array();
foreach ($content_models as $content_model) {
$identifier = $content_model->getIdentifier();
$pid = $content_model->getPidFromIdentifier($identifier);
$name = $content_model->name;
$potential_models["$pid"] = "$name";
}
unset($potential_models['islandora:contentCModel']);
return $potential_models;
}
/**
* Over writes the default 'content_model_viewer_ingest_metadata_form_validate' function.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function scholar_bulk_ingest_form_validate(array &$form, array &$form_state) {
$bulk_ingest_clicked = $form_state['clicked_button']['#attributes']['class'] == 'file_submit';
if (!$bulk_ingest_clicked) {
if ($form_state['storage']['step'] == 1) {
$form_state['storage']['step']++;
$form_state['rebuild'] = TRUE;
}
else {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
}
}
}
/**
* Makes sure the file was uploaded and is of the right type.
*
* @param array $element
* The file upload field
* @param array $form_state
* The Drupal form state.
*/
function scholar_bulk_ingest_file_upload_validate(array $element, array &$form_state) {
if ($form_state['clicked_button']['#attributes']['source'] == 'pubmed') {
if (!isset($_FILES['files']['name']['pubmed_file']) && $form_state['values']['pubmed_list'] == '' && $element['#title'] == "DOI Batch Importer") {
form_error($element, t("You must either add a file or input one or more pubmed id's."));
$path = drupal_get_path('module', 'scholar');
drupal_add_js("$path/js/islandora_scholar.js");
}
return;
}
if ($form_state['clicked_button']['#attributes']['source'] == 'doi') {
if (!isset($_FILES['files']['name']['doi_file']) && $form_state['values']['doi_list'] == '' && $element['#title'] == "Pubmed Batch Importer") {
form_error($element, t("You must either add a file or input one or more pubmed id's."));
$path = drupal_get_path('module', 'scholar');
drupal_add_js("$path/js/islandora_scholar.js");
}
return;
}
module_load_include('inc', 'fedora_repository', 'MimeClass');
$bulk_ingest_clicked = $form_state['clicked_button']['#attributes']['class'] == 'file_submit';
$file_uploaded = isset($_FILES['files']['error']['file']) && $_FILES['files']['error']['file'] == 0;
if ($bulk_ingest_clicked) {
if (!$file_uploaded) {
form_error($element, t('You must upload a "RIS" or "EndNote XML" document.'));
}
else { // Only support for one file.
// $mime_type = $_FILES['files']['type']['file'];
$file = file_save_upload('file');
$filename = $file->filepath;
$mime = new MimeClass();
$mime_type = $mime->get_mimetype($filename);
$valid_types = array('text/xml', 'text/plain', 'application/x-research-info-systems');
if (array_search($mime_type, $valid_types) === FALSE) {
form_error($element, t('The upload file is not the correct type. You must upload a "RIS" or "EndNote XML" document.'));
}
}
}
}
/**
* Bulk Ingest object.
*
* @param array $form
* The Drupal form.
* @param array $form_state
* The Drupal form state.
*/
function scholar_bulk_ingest_form_submit(array &$form, array &$form_state) {
module_load_include('inc', 'fedora_repository', 'MimeClass');
$collection_pid = $form_state['values']['collection_pid'];
$content_model_pid = $form_state['values']['content_model_pid'];
// Build full pubmed list from textfield and/or file.
$contents_as_string = '';
if ($form_state['clicked_button']['#attributes']['source'] == 'pubmed') {
// From the textarea
if ($form_state['values']['pubmed_list'] != '') {
$contents_as_string .= $form_state['values']['pubmed_list'] . ' ';
}
if (!empty($_FILES['files']['name']['pubmed_file'])) {
$file = file_save_upload('pubmed_file');
$contents_as_string .= file_get_contents($file->filepath);
}
$pubmed_list_ids = preg_split('/[\s,]+/', $contents_as_string, NULL, PREG_SPLIT_NO_EMPTY);
$context = array();
foreach ($pubmed_list_ids as $id) {
$operations[] = array(islandora_scholar_build_pubmed_object, array(trim($id)), $context);
}
$batch = array(
'title' => t('Ingesting PUBMED Files'),
'operations' => $operations,
'file' => drupal_get_path('module', 'scholar') . '/Batch.inc',
'finished' => 'islandora_scholar_build_pubmed_object_finished',
);
batch_set($batch);
unset($form_state['storage']);
return;
}
// Build full DOI list from textfield and/or file.
if ($form_state['clicked_button']['#attributes']['source'] == 'doi') {
// From the textarea
if ($form_state['values']['doi_list'] != '') {
$contents_as_string .= $form_state['values']['doi_list'] . ' ';
}
if (!empty($_FILES['files']['name']['doi_file'])) {
$file = file_save_upload('doi_file');
$contents_as_string .= file_get_contents($file->filepath);
}
$doi_list_ids = preg_split('/[\s,]+/', $contents_as_string, NULL, PREG_SPLIT_NO_EMPTY);
$context = array();
foreach ($doi_list_ids as $id) {
$operations[] = array(islandora_scholar_build_doi_object, array(trim($id)), $context);
}
$batch = array(
'title' => t('Ingesting DOI Files'),
'operations' => $operations,
'file' => drupal_get_path('module', 'scholar') . '/Batch.inc',
'finished' => 'islandora_scholar_build_doi_object_finished',
);
batch_set($batch);
unset($form_state['storage']);
return;
}
$file = file_save_upload('file');
$filename = $file->filepath;
$mime = new MimeClass();
$mime_type = $mime->get_mimetype($filename);
//need to inspect this to see if it is refworks or end note
$doc = new DOMDocument();
$raw_xml = file_get_contents($filename);
$xml = trim($raw_xml); //refworks has a nasty habit of outputing an xml file with
// the xml declartion being the second line, the first line being blank
$success = $doc->loadXML($xml);
$root = $doc->documentElement;
$nodeName = $root->nodeName;
if ($success && $root->nodeName == 'refworks') {
$function = 'scholar_batch_ingest_refworks_document';
}
else {
$function = ($mime_type == 'text/xml') ? 'scholar_batch_ingest_endnote_document' : 'scholar_batch_ingest_ris_document';
}
$operations = array(
array($function, array($filename, $collection_pid, $content_model_pid))
);
$batch = array(
'title' => t('Ingesting Files'),
'operations' => $operations,
'file' => drupal_get_path('module', 'scholar') . '/Batch.inc',
);
batch_set($batch);
unset($form_state['storage']); // Return to the viewer.
}
/**
* Implementation of solr_primary_display hook to customise the results
* display.
* @return type
*/
function scholar_islandora_solr_primary_display() {
return array(
'scholar' => array(
'name' => t('Scholar'),
'module' => 'scholar',
'file' => 'SolrResultsScholar.inc',
'class' => "ScholarSolrResults",
'function' => "displayResultsScholar",
'description' => t("Results displayed for Islandscholar."),
)
);
}
function scholar_block($op = 'list', $delta = 0, $edit = array()) {
module_load_include('inc', 'scholar', 'includes/scholar.blocks');
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Recently added items');
$blocks[0]['cache'] = BLOCK_NO_CACHE;
$blocks[1]['info'] = t('Total records added');
$blocks[1]['cache'] = BLOCK_NO_CACHE;
$blocks[2]['info'] = t('Total citation views');
$blocks[2]['cache'] = BLOCK_NO_CACHE;
$blocks[3]['info'] = t('Total full-text downloads');
$blocks[3]['cache'] = BLOCK_NO_CACHE;
$blocks[4]['info'] = t('Top viewed citations');
$blocks[4]['cache'] = BLOCK_NO_CACHE;
$blocks[5]['info'] = t('Random citation');
$blocks[5]['cache'] = BLOCK_NO_CACHE;
//$blocks[6]['info'] = t('Scholar Scrape');
//$blocks[6]['cache'] = BLOCK_NO_CACHE;
return $blocks;