forked from Daniel-KM/Omeka-plugin-CsvImportPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
136 lines (121 loc) · 3.82 KB
/
functions.php
File metadata and controls
136 lines (121 loc) · 3.82 KB
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
<?php
/**
* Install the plugin.
*
* @return void
*/
// this fork includes new db field for record type id
function csv_import_install()
{
$db = get_db();
// create csv imports table
$db->query("CREATE TABLE IF NOT EXISTS `{$db->prefix}csv_import_imports` (
`id` int(10) unsigned NOT NULL auto_increment,
`item_type_id` int(10) unsigned NOT NULL,
`collection_id` int(10) unsigned NOT NULL,
`record_type_id` int(10) unsigned NOT NULL,
`owner_id` int unsigned NOT NULL,
`delimiter` varchar(1) collate utf8_unicode_ci NOT NULL,
`original_filename` text collate utf8_unicode_ci NOT NULL,
`file_path` text collate utf8_unicode_ci NOT NULL,
`file_position` bigint unsigned NOT NULL,
`status` varchar(255) collate utf8_unicode_ci,
`skipped_row_count` int(10) unsigned NOT NULL,
`skipped_item_count` int(10) unsigned NOT NULL,
`is_public` tinyint(1) default '0',
`is_featured` tinyint(1) default '0',
`serialized_column_maps` text collate utf8_unicode_ci NOT NULL,
`added` timestamp NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");
// create csv imported items table
$db->query("CREATE TABLE IF NOT EXISTS `{$db->prefix}csv_import_imported_items` (
`id` int(10) unsigned NOT NULL auto_increment,
`item_id` int(10) unsigned NOT NULL,
`import_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY (`import_id`),
UNIQUE (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");
}
/**
* Uninstall the plugin.
*
* @return void
*/
function csv_import_uninstall()
{
// delete the plugin options
delete_option('csv_import_memory_limit');
delete_option('csv_import_php_path');
// drop the tables
$db = get_db();
$sql = "DROP TABLE IF EXISTS `{$db->prefix}csv_import_imports`";
$db->query($sql);
$sql = "DROP TABLE IF EXISTS `{$db->prefix}csv_import_imported_items`";
$db->query($sql);
}
/**
* Defines the ACL for the reports controllers.
*
* @param Omeka_Acl $acl Access control list
*/
function csv_import_define_acl($acl)
{
if (version_compare(OMEKA_VERSION, '2.0-dev', '>=')) {
$acl->addResource('CsvImport_Index');
} else {
// only allow super users and admins to import csv files
$acl->loadResourceList(array(
'CsvImport_Index' => array(
'index',
'map-columns',
'undo-import',
'clear-history',
'browse'
)
));
}
// Hack to disable CRUD actions.
$acl->deny(null, 'CsvImport_Index', array('show', 'add', 'edit', 'delete'));
$acl->deny('admin', 'CsvImport_Index');
}
/**
* Add the admin navigation for the plugin.
*
* @return array
*/
function csv_import_admin_navigation($tabs)
{
if (get_acl()->isAllowed(current_user(), 'CsvImport_Index', 'index')) {
$tabs['CSV Import'] = uri('csv-import');
}
return $tabs;
}
function csv_import_admin_header($request)
{
if ($request->getModuleName() == 'csv-import') {
queue_css('csv_import_main');
queue_js('csv-import');
}
}
/**
* @return array
*/
function csv_import_get_elements_by_element_set_name($itemTypeId)
{
$params = $itemTypeId ?
array('item_type_id' => $itemTypeId) :
array('exclude_item_type' => true);
return get_db()->getTable('Element')->findPairsForSelectForm($params);
}
/**
* @return array
*/
function csv_import_get_elements_by_element_set_name_file($recordTypeId = NULL)
{
$params = $recordTypeId ?
array('record_types' => array($recordTypeId)) :
array('record_types' => array('All', 'File'));
return get_db()->getTable('Element')->findPairsForSelectForm($params);
}