-
Notifications
You must be signed in to change notification settings - Fork 12
/
islandora_compound_batch.module
70 lines (62 loc) · 2.37 KB
/
islandora_compound_batch.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
<?php
/**
* @file
* Module used to handle compound object batches through the UI and drush.
*/
/**
* Implements hook_menu().
*/
// function islandora_compound_batch_menu() {
// $items = array();
// $items['islandora/object/%islandora_object/manage/collection/compound_batch'] = array(
// 'title' => 'Compound Batch',
// 'access callback' => 'islandora_compound_batch_menu_access',
// 'access arguments' => array(2),
// 'page callback' => 'drupal_get_form',
// 'page arguments' => array('islandora_compound_batch_form', 2),
// 'file' => 'includes/batch.form.inc',
// 'type' => MENU_LOCAL_ACTION,
// );
// return $items;
// }
/**
* Menu access callback.
*/
function islandora_compound_batch_menu_access($object) {
if (!islandora_object_access(ISLANDORA_INGEST, $object)) {
return FALSE;
}
$c = 'COLLECTION_POLICY';
if (isset($object[$c]) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object[$c])) {
$cp = new CollectionPolicy($object[$c]->content);
return array_key_exists('islandora:compoundCModel', $cp->getContentModels());
}
return FALSE;
}
/**
* Implements hook_islandora_datastream_ingested().
*
* Gives the parent object the TN of its first child.
*/
function islandora_compound_batch_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
$create_thumbs = variable_get('islandora_compound_object_thumbnail_child', TRUE);
if ($create_thumbs) {
$rels_predicate = variable_get('islandora_compound_object_relationship', 'isConstituentOf');
$part_of = $object->relationships->get(FEDORA_RELS_EXT_URI, $rels_predicate);
if (isset($part_of[0]['object']['value'])) {
$parent_pid = $part_of[0]['object']['value'];
$escaped_parent_pid = str_replace(':', '_', $parent_pid);
$sequence_numbers = $object->relationships->get(ISLANDORA_RELS_EXT_URI, "isSequenceNumberOf$escaped_parent_pid");
if (isset($sequence_numbers[0]['object']['value'])) {
$sequence_number = $sequence_numbers[0]['object']['value'];
// Use the TN from the first child (i.e., sequence number 1).
if ($sequence_number == '1') {
$parent_object = islandora_object_load($parent_pid);
if ($datastream->id == 'TN' && !$parent_object['TN']) {
islandora_compound_object_update_parent_thumbnail($parent_object);
}
}
}
}
}
}