This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Utilities.inc
82 lines (77 loc) · 2.67 KB
/
Utilities.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
<?php
// $Id$
/*
* @file
*
* Defines useful constants for this modules as well as helper functions that don't
* really belong anywhere else.
*/
define('STORAGE_KEY', 'islandora_form_builder');
define('FORM_ROOT', 'form_builder');
/**
* Sets up the bread crumbs for drupal.
*
* @param string $pid
* Pid for either a collection or content model.
*/
function islandora_form_builder_set_bread_crumbs($pid) {
$breadcrumbs = array();
$object_helper = new ObjectHelper();
$object_helper->getBreadcrumbs($pid, $breadcrumbs);
drupal_set_breadcrumb(array_reverse($breadcrumbs));
}
/**
* Takes a url argument passed to a MENU_CALLBACK, and checks if it is a valid Collection Pid.
* If it is not valid an attempt will be made to convert it to a valide Collection Pid.
*
* @param string $collection_pid
* Returns a valid Collection pid from the url argument if possible,
* otherwise it returns FALSE.
*/
function islandora_form_builder_validate_url_argument_collection_pid($collection_pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
if (!user_access('ingest new fedora objects')) {
drupal_set_message(t('You do not have permission to ingest.'), 'error');
return FALSE;
}
if (!validPid($collection_pid)) {
if (validPid(urldecode($collection_pid))) {
$collection_pid = urldecode($collection_pid);
}
else {
drupal_set_message(t("This collection PID $collection_pid is not valid"), 'error');
return FALSE;
}
}
if ($collection_pid == NULL) {
drupal_set_message(t('You must specify a collection object pid to ingest an object.'), 'error');
return FALSE;
}
return $collection_pid;
}
/**
* Checks if the users has access to edit data streams, and if the arguments are valid.
*
* @global string $user
* The current user.
* @param string $pid
* The objects pid.
*
* @return boolean
* TRUE if the user has permission to edit the datastream, and the arguments are valid,
* FALSE otherwise.
*/
function islandora_form_builder_check_edit_form_arguments_and_permissions($pid, $form_name) {
global $user;
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
if ($pid == NULL || $form_name == NULL) {
drupal_set_message(t('You must specify an object pid and a form name to edit.'), 'error');
return FALSE;
}
else if (!fedora_repository_access(OBJECTHELPER :: $EDIT_FEDORA_METADATA, $pid, $user)) {
drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or you do not have permission to edit meta data for this object."), 'error');
return FALSE;
}
return TRUE;
}