-
Notifications
You must be signed in to change notification settings - Fork 7
/
islandora_workflow.module
1779 lines (1626 loc) · 64.6 KB
/
islandora_workflow.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
* Implement an editorial workflow around Fedora objects.
*
* @author
* William Panting
*
* @todo
* Address being able to add not-in-workflow objects
* and broken workflow objects to a workflow state.
* The distinction between the two states.
* I think this should be an integration piece: that
* the 'reject to workflow' should go in an object management UI.
*
* This module treats the object owner as the creator for its purposes.
*/
/**
* Check whether the current user has permission to publish workflow items.
*
* @return boolean
* TRUE if the current user has permission to publish items; FALSE otherwise.
*/
function _islandora_workflow_publish_access() {
return user_access('islandora_workflow_Administrator') || user_access('islandora_workflow_Manager');
}
/**
* Check whether the current user has permission to reject workflow items.
*
* @see _islandora_workflow_publish_access()
*
* @return boolean
* TRUE if the current user has permission to reject items; FALSE otherwise.
*/
function _islandora_workflow_reject_access() {
return _islandora_workflow_publish_access() || user_access('islandora_workflow_Editor');
}
/**
* Get a list of items within a given collection that are tracked by workflow.
*
* @param string $collection_id
* The PID of the parent collection.
*
* @return array
* An array of collection member PIDs.
*/
function islandora_workflow_tracked_collection_members($collection_id) {
module_load_include('inc', 'islandora_workflow');
module_load_include('collection.inc', 'islandora_workflow');
$members = islandora_workflow_get_all_members_of_collection($collection_id);
if (empty($members)) {
return array();
}
$subcollections = islandora_workflow_get_subcollections($collection_id);
$members = array_diff_key($members, $subcollections);
$tracked_members = array();
foreach ($members as $object_pid => $attributes) {
if (isset($attributes['state'])) {
$tracked_members[$object_pid] = $members[$object_pid];
}
}
return $tracked_members;
}
/**
* Get the items created by the given user.
*
* @param object $account
* A Drupal "user" object (or at least an object with the "name" property).
* @param int $limit
* An integer representing the number of items to return. The (default)
* value -1 is magic, and causes all items to be returned.
* @param int $offset
* An integer for the offset in the results, if performing paging or a
* similar task.
*
* @return array
* An associative array of associative arrays, mapping Fedora PIDs to the
* results of the Sparql query in member_query.sparql as given by
* ObjectHelper::performRiQuery(), with the exception of the "timestamp"
* being remapped to "islandora_workflow_modified".
*/
function _islandora_workflow_get_created_items($account = NULL, $limit = -1, $offset = 0) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
if (is_null($account)) {
global $user;
$account = drupal_clone($user);
}
// Get the stored query.
$query_file_name = drupal_get_path('module', 'islandora_workflow') . '/sparql/member_query.sparql';
$query_file_handle = fopen($query_file_name, "r");
$query = fread($query_file_handle, filesize($query_file_name));
fclose($query_file_handle);
$pattern = 'BOUND(?owner)';
$account_name = $account->name;
$replacement = "?owner = \"$account_name\"";
$query = str_replace($pattern, $replacement, $query);
$query_results = ObjectHelper::performRiQuery($query, 'sparql', $limit, $offset);
$processed_results = array();
foreach ($query_results as $result) {
$index = preg_replace('/^info:fedora\//', '', $result['member_object']);
$result['islandora_workflow_modified'] = $result['timestamp'];
unset($result['timestamp']);
$processed_results[$index] = $result;
}
return $processed_results;
}
/**
* This function is used to check if a Fedora object
* can be operated on by a manager. It assumes that the
* user has permission on the collection.
*
* @param array $item
* the returns from a SPARQL query that describe the Fedora object.
*
* @return boolean
* True if the user has access false otherwise.
*/
function _islandora_workflow_actionable_by_manager($item) {
return 'published' != $item['state'];
}
/**
* This function is used to check if a Fedora object
* can be operated on by an editor. It assumes that the
* user has permission on the collection.
*
* @param array $item
* the returns from a SPARQL query that describe the Fedora object.
*
* @return boolean
* True if the user has access false otherwise.
*/
function _islandora_workflow_actionable_by_editor($item) {
global $user;
if (('published' != $item['state'] && 'approved' != $item['state']) ||
($item['owner'] == $user->name && 'published' != $item['state'])) {
return TRUE;
}
return FALSE;
}
/**
* This function is used to check if a Fedora object
* can be show to a editor in the in_progress tab.
* It assumes that the user has permission on the collection.
*
* @param array $item
* the returns from a SPARQL query that describe the Fedora object.
*
* @return boolean
* True if the user should be seeing the object, false otherwise.
*/
function _islandora_workflow_in_progress_by_editor($item) {
if (!$item['owner'] && ('rejected' != $item['state'] || 'created' != $item['state'])) {
return TRUE;
}
return FALSE;
}
/**
* This function is used to check if a Fedora object
* can be operated on by a submitter. It assumes that the
* user has permission on the collection.
*
* @param array $item
* the returns from a SPARQL query that describe the Fedora object.
*
* @return boolean
* True if the user has access false otherwise.
*/
function _islandora_workflow_actionable_by_submitter($item) {
global $user;
if ($item['owner'] == $user->name && 'published' != $item['state']) {
return TRUE;
}
return FALSE;
}
/**
* This function is used to check if a Fedora object
* can be show to a submitter in the in_progress tab. It assumes that the
* user has permission on the collection.
*
* @param array $item
* The returns from a SPARQL query that describe the Fedora object.
*
* @return boolean
* True if the user should see the object false otherwise.
*/
function _islandora_workflow_in_progress_by_submitter($item) {
global $user;
if ($item['owner'] == $user->name && ($item['state'] == 'created' || $item['state'] == 'rejected')) {
return TRUE;
}
return FALSE;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* This form alter hook runs on object ingest to determine whether or not to
* add an object to workflow.
*
* @param array $form
* The form
* @param array $form_state
* The form state
*
* @return NULL
* Nothing
* @todo: make the form have a toggle for admins/managers
*/
function islandora_workflow_form_fedora_repository_ingest_form_alter(&$form, &$form_state) {
module_load_include('collection.inc', 'islandora_workflow');
$collection_pid = $form_state['storage']['collection_pid'];
if (islandora_workflow_is_collection_workflow_tracked($collection_pid)) {
$form['#submit'][] = 'islandora_workflow_ingest_submit';
}
return;
}
/**
* Form submit handler.
*
* This submit function will track a newly-ingested object into workflow.
*
* @param array $form
* The form
* @param array $form_state
* The form state
*/
function islandora_workflow_ingest_submit($form, &$form_state) {
module_load_include('inc', 'islandora_workflow');
return islandora_workflow_init_workflow($form_state['values']['pid']);
}
/**
* The menu entries for this module.
*
* @return array
* $menu_entries An arrray of the items to be added to the drupal menu
*/
function islandora_workflow_menu() {
$menu_entries = array();
// Settings associated with islandora_workflow and collection permissions.
$menu_entries['admin/settings/islandora_workflow'] = array(
'title' => 'Islandora Workflow',
'page callback' => 'islandora_workflow_collection_permissions',
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(array('islandora_workflow_Administrator', 'islandora_workflow_Manager')),
'type' => MENU_NORMAL_ITEM,
'description' => 'Edit workflow tracked collections and colleciton level workflow permissions.',
);
$menu_entries['admin/settings/islandora_workflow/perm'] = array(
'title' => 'Islandora Workflow Permissions',
'description' => 'Here you can assign permissions to roles and users on a collection by collection level.',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
// Settings associated with islandora_workflow and individual collections.
$menu_entries['admin/settings/islandora_workflow/collections'] = array(
'title' => 'Islandora Workflow Collections',
'description' => 'Here you can set what collections to track via workflow.',
'page callback' => '_islandora_workflow_get_form',
'page arguments' => array('islandora_workflow_collections'),
'access arguments' => array('islandora_workflow_Administrator'),
'file' => 'islandora_workflow.forms.inc',
'type' => MENU_LOCAL_TASK,
);
// Main working page for islandora_workflow.
$menu_entries['islandora_workflow'] = array(
'title' => 'My Islandora work',
'file' => 'islandora_workflow.forms.inc',
'description' => 'This is the main access point to islandora_workflow',
'page callback' => '_islandora_workflow_get_form',
'page arguments' => array('islandora_workflow_work_form', 'work_in_progress'),
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_NORMAL_ITEM,
);
$menu_entries['islandora_workflow/work_in_progress'] = array(
'title' => 'Work In Progress',
'file' => 'islandora_workflow.forms.inc',
'page callback' => '_islandora_workflow_get_form',
'page arguments' => array('islandora_workflow_work_form', 'work_in_progress'),
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$menu_entries['islandora_workflow/assigned'] = array(
'title' => 'Assigned To Me',
'file' => 'islandora_workflow.forms.inc',
'page callback' => '_islandora_workflow_get_form',
'page arguments' => array('islandora_workflow_work_form', 'assigned'),
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
$menu_entries['islandora_workflow/unpublished'] = array(
'title' => 'Unpublished Objects',
'file' => 'islandora_workflow.forms.inc',
'page callback' => '_islandora_workflow_get_form',
'page arguments' => array('islandora_workflow_work_form', 'unpublished'),
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
// Main working page for islandora_workflow.
$menu_entries['islandora_workflow_edit_note'] = array(
'title' => 'Edit Note',
'description' => 'You may edit the note on this object',
'page callback' => '_islandora_workflow_get_form',
'page arguments' => array('islandora_workflow_edit_note_form'),
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'file' => 'islandora_workflow.forms.inc',
'type' => MENU_CALLBACK,
);
$menu_entries['islandora_workflow/ahah/tracked_collections_user'] = array(
'page callback' => 'islandora_workflow_ahah_tracked_collections_user',
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_CALLBACK,
);
$menu_entries['islandora_workflow/ahah/tracked_collections_role'] = array(
'page callback' => 'islandora_workflow_ahah_tracked_collections_role',
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_CALLBACK,
);
$menu_entries['islandora_workflow/ahah/active_collections'] = array(
'page callback' => 'islandora_workflow_ahah_active_collections',
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_CALLBACK,
);
$menu_entries['islandora_workflow/ahah/inactive_collections'] = array(
'page callback' => 'islandora_workflow_ahah_inactive_collections',
'access callback' => 'islandora_workflow_check_permissions',
'access arguments' => array(islandora_workflow_perm()),
'type' => MENU_CALLBACK,
);
return $menu_entries;
}
/**
* Form definition for editing the workflow note on an object.
*
* @return array
* $edit_note_form The drupal form array for editing a note.
*/
function islandora_workflow_edit_note_form() {
if (isset($_GET['object'])) {
// For getting the current note state.
module_load_include('inc', 'islandora_workflow');
$object_id = $_GET['object'];
$subject = islandora_workflow_get_object_note_subject($object_id);
$body = islandora_workflow_get_object_note_body($object_id);
$edit_note_form['#redirect'] = array('islandora_workflow');
$edit_note_form['note_form'] = array(
'#type' => 'fieldset',
'#title' => t('Note'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#description' => t('Change the note attached to this object.'),
);
// Submit button.
$edit_note_form['note_form']['Subject'] = array(
'#type' => 'textfield',
'#weight' => '1',
'#default_value' => $subject,
);
// Submit button.
$edit_note_form['note_form']['Body'] = array(
'#type' => 'textarea',
'#weight' => '2',
'#default_value' => $body,
);
// Submit button.
$edit_note_form['note_form']['Submit'] = array(
'#type' => 'submit',
'#weight' => '3',
'#value' => t('Submit'),
);
// Drupal made me do it.
$edit_note_form['note_form']['object'] = array(
'#type' => 'textfield',
'#default_value' => $object_id,
'#access' => FALSE,
);
}
else {
$edit_note_form = array();
}
return $edit_note_form;
}
/**
* Access callback function.
*
* This function is the access callback used for access
* to the workflow page and configuration section.
*
* @param array $permission_array
* those user roles to allow access
*
* @return boolean
* whether or not to permit access
*/
function islandora_workflow_check_permissions($permission_array) {
module_load_include('collection.inc', 'islandora_workflow');
module_load_include('inc', 'islandora_workflow');
// If the user is anonymous then return FALSE.
if (!user_is_logged_in()) {
return FALSE;
}
// Let the user into any page if they are a workflow admin.
if (in_array('islandora_workflow_Administrator', $permission_array) && user_access('islandora_workflow_Administrator')) {
return TRUE;
}
// Loop through permissions allowed.
foreach ($permission_array as $permission) {
// Return true if the user has an allowed permission.
if ($permission != 'islandora_workflow_Administrator' && user_access($permission) && islandora_workflow_get_users_collections($permission) != FALSE) {
return TRUE;
}
}
// If no permission matched then return false.
return FALSE;
}
/**
* Form definition.
*
* This function returns the form that will allow an administrator to
* track collections in the workflow.
*
* @param array $form_state
* The current state of the form
*
* @todo: populate with current state
*/
function islandora_workflow_collections(&$form_state) {
module_load_include('inc', 'islandora_workflow');
module_load_include('collection.inc', 'islandora_workflow');
if (!$form_state['storage']['workflow_collections']['inactive'] && !$form_state['storage']['workflow_collections']['active']) {
$collection_data = islandora_workflow_get_collections();
$tracked_option = 'workflow tracked';
}
elseif ($form_state['storage']['workflow_collections']['active'] && $form_state['storage']['workflow_collections']['inactive']) {
$collection_data = islandora_workflow_get_collections('both');
$tracked_option = 'inactive or active';
}
elseif ($form_state['storage']['workflow_collections']['active']) {
$collection_data = islandora_workflow_get_collections('active');
$tracked_option = 'active';
}
elseif ($form_state['storage']['workflow_collections']['inactive']) {
$collection_data = islandora_workflow_get_collections('inactive');
$tracked_option = 'inactive';
}
$form = array(
'#prefix' => '<div id="islandora_workflow_collection_filtering">',
'#suffix' => '</div>',
);
if (!$form_state['storage']['workflow_collections']) {
$form_state['storage']['workflow_collections']['active'] = FALSE;
$form_state['storage']['workflow_collections']['inactive'] = FALSE;
}
$form['workflow_filtering'] = array(
'#type' => 'fieldset',
'#title' => t('Collection filtering'),
'#collapsible' => FALSE,
'#collapsed' => TRUE,
'#description' => t('Filter the results of the collections shown below. By default all collections regardless of state are shown.'),
);
$form['workflow_filtering']['workflow_active_collections'] = array(
'#type' => 'checkbox',
'#title' => t('Display active collections?'),
'#default_value' => $form_state['storage']['workflow_collections']['active'] ? TRUE : FALSE,
'#ahah' => array(
'event' => 'click',
'path' => 'islandora_workflow/ahah/active_collections',
'wrapper' => 'islandora_workflow_collection_filtering',
),
);
$form['workflow_filtering']['workflow_inactive_collections'] = array(
'#type' => 'checkbox',
'#title' => t('Display inactive collections?'),
'#default_value' => $form_state['storage']['workflow_collections']['inactive'] ? TRUE : FALSE,
'#ahah' => array(
'event' => 'click',
'path' => 'islandora_workflow/ahah/inactive_collections',
'wrapper' => 'islandora_workflow_collection_filtering',
),
);
if (count($collection_data) > 0) {
// Make the form.
// $form['#theme'] = 'workflow_collections';
foreach ($collection_data as $collection_pid => $collection_info) {
$form[$collection_pid] = array(
'#type' => 'checkbox',
'#title' => ($collection_info['label']) ? $collection_info['label'] : $collection_pid,
'#default_value' => ($collection_info['workflow_tracking']) ? 1 : 0,
);
}
}
else {
$form['no_collections'] = array(
'#type' => 'item',
'#value' => t('No %tracked collections found!',
array(
'%tracked' => $tracked_option,
)
)
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save collection configuration'),
);
if (isset($form_state['action'])) {
$form['#action'] = $form_state['action'];
}
$form['#submit'] = array('islandora_workflow_collections_submit');
return $form;
}
/**
* Form submit handler.
*
* This function handles the submission of the form
* that will allow an administrator to track collections in the workflow.
*
* we only want to hit the objects that require changing...
* so we need the initial state to compare
*
* @param array $form
* The form submitted.
* @param array &$form_state
* The complete state of the form submitted.
*/
function islandora_workflow_collections_submit($form, &$form_state) {
module_load_include('collection.inc', 'islandora_workflow');
if (!$form_state['storage']['workflow_collections']['inactive'] && !$form_state['storage']['workflow_collections']['active']) {
$collections = islandora_workflow_get_collections();
}
elseif ($form_state['storage']['workflow_collections']['active'] && $form_state['storage']['workflow_collections']['inactive']) {
$collections = islandora_workflow_get_collections('both');
}
elseif ($form_state['storage']['workflow_collections']['active']) {
$collections = islandora_workflow_get_collections('active');
}
elseif ($form_state['storage']['workflow_collections']['inactive']) {
$collections = islandora_workflow_get_collections('inactive');
}
foreach ($collections as $collection_pid => $collection_data) {
if ($form_state['values'][$collection_pid] != $form[$collection_pid]['#default_value']) {
if ($form_state['values'][$collection_pid]) {
islandora_workflow_track_collection_in_workflow($collection_pid);
drupal_set_message(t('Collection <em>%label</em> (%pid) is now tracked in workflow.',
array(
'%label' => $collection_data['label'],
'%pid' => $collection_pid,
)
));
}
else {
islandora_workflow_stop_tracking_collection_in_workflow($collection_pid);
drupal_set_message(t('Collection <em>%label</em> (%pid) is no longer tracked in workflow.',
array(
'%label' => $collection_data['label'],
'%pid' => $collection_pid,
)
));
}
}
}
}
/**
* Implements hook_perm().
*
* The list of available permissions for this module.
*
* @return array
* The list of permissions.
*/
function islandora_workflow_perm() {
return array(
'islandora_workflow_Administrator',
'islandora_workflow_Editor',
'islandora_workflow_Manager',
'islandora_workflow_Submitter',
);
}
/**
* Implements hook_help().
*
* Show help.
*
* @param string $path
* The path that the help is being accessed from.
*
* @return string
* $help The help string that will be returned to the user.
*/
function islandora_workflow_help($path, $arg) {
// Default.
$help = '';
switch ($path) {
case 'admin/modules#description':
$help = t('A generic workflow module for Fedora objects.');
break;
case 'admin/settings/islandora_workflow_opts':
$help = t('If the repository is full of objects this operation could take awhile. Every object needs to be updated. Use this with care.');
break;
case 'admin/settings/islandora_workflow_collections':
$help = t('Here you can set what collections have new members ingested into a workflow state. Managers and Admins can bypass a positive setting set here during ingest.');
break;
}
return $help;
}
/**
* This function registers themeing functions with Drupal.
*
* @return array
* $themes the array of available themes
*/
function islandora_workflow_theme() {
$path = drupal_get_path('module', 'islandora_workflow');
$themes = array();
$themes['permissions_role_table'] = array(
'arguments' => array('list' => NULL, 'form' => NULL),
'template' => 'permissions_role_table',
'path' => "$path/theme",
'file' => "islandora_workflow.theme.inc",
);
$themes['permissions_user_table'] = array(
'arguments' => array('list' => NULL, 'form' => NULL),
'template' => 'permissions_user_table',
'path' => "$path/theme",
'file' => "islandora_workflow.theme.inc",
);
// Both workflow and overview tabs should be able to use this template.
$themes['workflow_table'] = array(
'arguments' => array('form' => NULL),
'path' => "$path/theme",
'file' => "islandora_workflow.theme.inc",
);
// Both workflow and overview tabs should be able to use this template.
$themes['workflow_collections'] = array(
'arguments' => array('list' => NULL, 'form' => NULL),
'template' => 'workflow_collections',
'path' => "$path/theme",
'file' => "islandora_workflow.theme.inc",
);
return $themes;
}
/**
* Generate a tabbed page for editing collection-level permissions.
*
* @return array
* $form The form for changing collection
* permissions granted to roles
*/
function islandora_workflow_collection_permissions() {
$page_tabs = array(
'#type' => 'tabset',
);
$page_tabs['Users'] = array(
'#type' => 'tabpage',
'#title' => t('Users'),
'#content' => drupal_get_form('islandora_workflow_user_permissions_form'),
'#weight' => '1',
);
$page_tabs['Roles'] = array(
'#type' => 'tabpage',
'#title' => t('Roles'),
'#content' => drupal_get_form('islandora_workflow_role_permissions_form'),
'#weight' => '2',
);
return tabs_render($page_tabs);
}
/**
* Form definition.
*
* This function builds the form that allows users to
* modify role based permissions for individual collections
*
* @param array $form_state
* The state of a previously submitted form.
*
* @return array
* $form the array containing the form.
*/
function islandora_workflow_role_permissions_form(&$form_state) {
module_load_include('collection.inc', 'islandora_workflow');
module_load_include('permissions.inc', 'islandora_workflow');
module_load_include('inc', 'islandora_workflow');
module_load_include('inc', 'php_lib', 'Ahah');
Ahah::get_ahah_js();
$form = array(
'#prefix' => '<div id="islandora_workflow_role_perm">',
'#suffix' => '</div>',
);
$current_module_permissions = array();
// Collect current state data.
if ($form_state['storage']['tracked_collections_role']) {
$my_collections = islandora_workflow_get_users_collections(NULL, NULL, TRUE);
}
else {
$my_collections = islandora_workflow_get_users_collections();
}
// Used to get what roles to display and avaialbe options for selects.
$current_module_permissions = islandora_workflow_get_roles_with_module_permissions();
// Used to find the default options for slects.
$current_collection_permissions = islandora_workflow_get_all_role_permissions();
// Setup the form. See http://drupal.org/node/751826 .
$form['islandora_workflow_collection_permissions_table'] = array(
'#type' => 'fieldset',
'#title' => t('Collection Permissions'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#description' => count($my_collections) > 0 ? t('Assign collection level permissions to roles.') : t('No collections currently tracked in workflow!'),
);
$form['islandora_workflow_collection_permissions_table']['workflow_tracked_role'] = array(
'#type' => 'checkbox',
'#title' => t('Display only workflow tracked collections?'),
'#default_value' => $form_state['storage']['tracked_collections_role'] ? TRUE : FALSE,
'#ahah' => array(
'event' => 'click',
'path' => 'islandora_workflow/ahah/tracked_collections_role',
'wrapper' => 'islandora_workflow_role_perm',
),
);
// Needed to get around a Drupal AHAH/Submit problem.
if (isset($form_state['action'])) {
$form['#action'] = $form_state['action'];
}
if (count($my_collections) > 0) {
// Theme.
$form['islandora_workflow_collection_permissions_table']['permissions_table'] = array(
'#theme' => 'permissions_role_table',
);
// Collection selector and submit button.
$my_collections_ids = array();
foreach ($my_collections as $collection_id => $collection_info) {
if (!isset($_SESSION['workflow_permissions_page']['active_collection'])) {
$_SESSION['workflow_permissions_page']['active_collection'] = $collection_id;
}
$my_collections_ids[$collection_id] = $collection_info['label'] . ' [' . $collection_id . ']';
}
$form['islandora_workflow_collection_permissions_table']['permissions_table']['collection_selector'] = array(
'#type' => 'select',
'#options' => $my_collections_ids,
'#default_value' => $_SESSION['workflow_permissions_page']['active_collection'],
);
$form['islandora_workflow_collection_permissions_table']['permissions_table']['collection_submit'] = array(
'#type' => 'submit',
'#value' => t('Select Collection'),
);
}
else {
}
// Submit button.
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => '1');
// Restore button.
$form['restore'] = array(
'#type' => 'submit',
'#value' => t('Restore'),
'#weight' => '2');
if (count($my_collections) > 0) {
// Populate the form, Roles.
foreach ($current_module_permissions as $role_id => $role_name) {
if (sizeof($current_module_permissions[$role_id][key($role_name)]) == 1) {
if (in_array('islandora_workflow_Administrator', $current_module_permissions[$role_id][key($role_name)])) {
// This role has Admin permissions only.
continue;
}
}
// Add none to the possible options.
array_unshift($current_module_permissions[$role_id][key($role_name)], '');
// Remove the islandora_workflow_Administrator permission.
if (in_array('islandora_workflow_Administrator', $current_module_permissions[$role_id][key($role_name)])) {
unset($current_module_permissions[$role_id][key($role_name)][array_search('islandora_workflow_Administrator', $current_module_permissions[$role_id][key($role_name)])]);
}
// Change the left over permission strings to be more user friendly.
if (in_array('islandora_workflow_Manager', $current_module_permissions[$role_id][key($role_name)])) {
$current_module_permissions[$role_id][key($role_name)][array_search('islandora_workflow_Manager', $current_module_permissions[$role_id][key($role_name)])] = 'Manager';
}
if (in_array('islandora_workflow_Editor', $current_module_permissions[$role_id][key($role_name)])) {
$current_module_permissions[$role_id][key($role_name)][array_search('islandora_workflow_Editor', $current_module_permissions[$role_id][key($role_name)])] = 'Editor';
}
if (in_array('islandora_workflow_Submitter', $current_module_permissions[$role_id][key($role_name)])) {
$current_module_permissions[$role_id][key($role_name)][array_search('islandora_workflow_Submitter', $current_module_permissions[$role_id][key($role_name)])] = 'Submitter';
}
// Remove the editor and manager permissions from the anonymous role.
if ($role_id == 1) {
foreach ($current_module_permissions[$role_id][key($role_name)] as $key => $permission) {
if ($permission == 'Editor' || $permission == 'Manager') {
unset($current_module_permissions[$role_id][key($role_name)][$key]);
}
}
}
$collection_id = $_SESSION['workflow_permissions_page']['active_collection'];
/* Change the default permission
* string to be inline with the user friendly strings.*/
$default_value = '';
if (array_key_exists($role_id, $current_collection_permissions)) {
if (array_key_exists($collection_id, $current_collection_permissions[$role_id])) {
if ($current_collection_permissions[$role_id][$collection_id] == 'islandora_workflow_Manager') {
$current_collection_permissions[$role_id][$collection_id] = 'Manager';
}
if ($current_collection_permissions[$role_id][$collection_id] == 'islandora_workflow_Editor') {
$current_collection_permissions[$role_id][$collection_id] = 'Editor';
}
if ($current_collection_permissions[$role_id][$collection_id] == 'islandora_workflow_Submitter') {
$current_collection_permissions[$role_id][$collection_id] = 'Submitter';
}
$default_value = array_search($current_collection_permissions[$role_id][$collection_id], $current_module_permissions[$role_id][key($role_name)]);
}
}
// Drupal made me do it...
$form['islandora_workflow_collection_permissions_table']['permissions_table'][$role_id][$collection_id] = array(
'#type' => 'select',
/* Default value works, but if you hit refresh on the page the values
* do not go back to the
* default... navigating away does reset the value.
* make this into whatever the current setting
* is for that collection/role
* what are available to the current role*/
'#default_value' => $default_value,
'#options' => $current_module_permissions[$role_id][key($role_name)],
);
}
}
return $form;
}
/**
* Form submit handler.
*
* This function processes the form submitted from the collection
* permission page
*
* @param array $form
* Holds all the data on the state of the form submitted
* @param array $form_state
* An easier to use version of $form
*/
function islandora_workflow_role_permissions_form_submit($form, &$form_state) {
module_load_include('permissions.inc', 'islandora_workflow');
module_load_include('inc', 'islandora_workflow', 'normalize_assignees');
$clicked_button = $form_state['clicked_button']['#value'];
// Handle updating the page.
if ($clicked_button == 'Update') {
$current_permissions = islandora_workflow_get_all_role_permissions();
// These arrays all follow array[$role_id][$collection_id]str.
$changed_permissions = array();
$new_permissions = array();
$removed_permissions = array();
// Get the values returned by the form.
$possible_permission = $form_state['values']['islandora_workflow_collection_permissions_table']['permissions_table'];
foreach ($possible_permission as $role_id => $collection) {
if (is_array($collection)) {
foreach ($collection as $collection_id => $select_element) {
$select_element_index = $possible_permission[$role_id][$collection_id];
$select_element_value = $form['islandora_workflow_collection_permissions_table']['permissions_table'][$role_id][$collection_id]['#options'][$select_element_index];
// Remap user friendly element option values to permission names.
if ($select_element_value == 'Manager') {
$select_element_value = 'islandora_workflow_Manager';
}
elseif ($select_element_value == 'Editor') {
$select_element_value = 'islandora_workflow_Editor';
}
elseif ($select_element_value == 'Submitter') {
$select_element_value = 'islandora_workflow_Submitter';
}
/* Compare the form values against the
* database and record the changes necessary.*/
// If there is currently a DB rule.
if (isset($current_permissions[$role_id][$collection_id])) {
// If the DB and FORM disagree.
if ($current_permissions[$role_id][$collection_id] != $select_element_value) {
if ($select_element_value == '') {
// If the form element is empty.
// Add the form rule to the DB queue for deleting the rule.
$removed_permissions[$role_id][$collection_id] = $current_permissions[$role_id][$collection_id];
}
else {
// If the form element is populated.
// Add the form rule to the DB queue for rewriting the rule.
$changed_permissions[$role_id][$collection_id] = $select_element_value;
}
}
}
// If there is NOT a DB rule.
else {
// If the form's rule is NOT empty.
if ($select_element_value != '') {
// Add the form rule to the DB queue for adding a permission.
$new_permissions[$role_id][$collection_id] = $select_element_value;
}
// If it is empty do nothing.
}
}
}
}
// Send changes to DB.
foreach ($changed_permissions as $role_id => $collection) {
foreach ($collection as $collection_id => $permission) {
$query = 'UPDATE {islandora_workflow_role_permissions}';
$query = $query . ' SET role=' . $role_id . ', collection="' . $collection_id . '", permission="' . $permission . '"';
$query = $query . ' WHERE role=' . $role_id . ' AND collection="' . $collection_id . '"';
db_query($query);
}
}
// Send new permissions to DB.
foreach ($new_permissions as $role_id => $collection) {
foreach ($collection as $collection_id => $permission) {
$record = array(
'role' => $role_id,
'collection' => $collection_id,
'permission' => $permission,
);
drupal_write_record('islandora_workflow_role_permissions', $record);
}
}
// Delete now unnecessary entries in DB.
foreach ($removed_permissions as $role_id => $collection) {
foreach ($collection as $collection_id => $permission) {