-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpokedbAccessionPlugin.php
138 lines (114 loc) · 3.64 KB
/
SpokedbAccessionPlugin.php
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
<?php
/**
* SpokedbAccession
*
* @copyright Copyright 2018 Eric C. Weig
* @license http://opensource.org/licenses/MIT MIT
*/
/**
* The SpokedbAccession plugin.
*
* @package Omeka\Plugins\spokedbAccession
*/
class SpokedbAccessionPlugin extends Omeka_Plugin_AbstractPlugin
{
// Define Hooks
protected $_hooks = array(
'install',
'uninstall',
'admin_footer',
'define_routes'
);
public function hookInstall()
{
}
public function hookUninstall()
{
}
function hookDefineRoutes($args)
{
$router = $args['router'];
}
# Ensure that interviews have an accession number.
#
# The interview must be assigned to a collection to get an accession
# number.
public function hookAdminFooter(){
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (strpos($actual_link, '/items/edit/') !== false) {
$interview_accession = metadata('item', array('General', 'Interview Accession'));
$collection = get_collection_for_item();
if ($collection) {
$collectionId = metadata($collection, 'id');
$nitems = metadata($collection, 'total items');
}
if ($interview_accession == NULL && $collectionId !== NULL) {
$proj = metadata($collection, array('Project', 'Project Code'));
$curYear = date('Y');
$abrev = "oh";
settype($numvar,'integer');
$proj_test = "_" . $proj . $numvar;
$items = get_records('Item', array(), 30000);
$all_accessions = array();
set_loop_records('items', $items);
foreach (loop('items') as $item):
$accnums = metadata('item', array('General','Interview Accession'));
$accessions[] = $accnums;
endforeach;
$numof = array();
foreach($accessions as $accession) {
if (strpos($accession, $curYear) !== false) {
$totalints = substr($accession, 0, 9);
$totalints = strtok($accession, '_');
$digits = substr($totalints, -3);
$digits = substr($totalints, 6);
$numof[] = $digits;
}
}
if (!empty($numof)) {
$total_seq = (max($numof));
} else {
$total_seq = 0;
}
$numbers = array();
foreach($accessions as $accession) {
if (strpos($accession, $proj_test) !== false) {
$arrseqs = explode("_", $accession);
$seqs = $arrseqs[1];
$seqs = str_replace("$proj","","$seqs");
$numbers[] = $seqs;
}
}
if (!empty($numbers)) {
$seq = (max($numbers));
} else {
$seq = 0;
}
$plus_one = 1;
$sum_total_seq = $total_seq + $plus_one;
$sum_total_seq = str_pad($sum_total_seq,4,"0",STR_PAD_LEFT);
$sum_seq = $seq + $plus_one;
$sum_seq = str_pad($sum_seq,4,"0",STR_PAD_LEFT);
$oh = "oh";
$div = "_";
$new_accession = $curYear . $oh . $sum_total_seq . $div . $proj . $sum_seq;
} else {
$new_accession = "";
}
?>
<script>
var myAccession = document.getElementById("Elements-252-0-text");
if (myAccession && myAccession.value) {
console.log("My input has a value!");
} else {
window.addEventListener('load', function() {
document.getElementById("Elements-252-0-text").value = "<?php echo $new_accession; // HTML ?>";
});
}
</script>
<?php
} elseif (strpos($actual_link, '/items/edit/') == false) {
//do nothing
}
}
}