This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentificationCodesHandler.inc.php
executable file
·83 lines (65 loc) · 2.78 KB
/
IdentificationCodesHandler.inc.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
<?php
/**
* @file plugins/generic/identificationCodes/IdentificationCodesHandler.inc.php
*
* Copyright (c) 2016 Language Science Press
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class IdentificationCodesHandler
*
*/
import('classes.handler.Handler');
import('plugins.generic.identificationCodes.IdentificationCodesDAO');
class IdentificationCodesHandler extends Handler {
static $plugin;
function IdentificationCodesHandler() {
parent::Handler();
}
/**
* Provide the plugin to the handler.
*/
static function setPlugin($plugin) {
self::$plugin = $plugin;
}
function index($args, $request) {
$authorizedUserGroups = array(ROLE_ID_SITE_ADMIN,ROLE_ID_MANAGER);
$userRoles = $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
// redirect to index page if user does not have the rights
$user = $request->getUser();
if (!array_intersect($authorizedUserGroups, $userRoles)) {
$request->redirect(null, 'index');
}
$press = $request->getPress();
// get codes from the settings
//$identifcationCodesSettings = array_map('trim', explode(',', $press->getSetting('langsci_identificationCodes_codes')));
//$identifcationCodesSettings = array_map('trim', explode(',',self::$plugin->getSetting($press->getId(), 'langsci_identificationCodes_codes')));
$identifcationCodesSettings = array_map('trim', explode(',',self::$plugin->getSetting($press->getId(), 'langsci_identification_codes')));
// get codes from the ONIX code list
$onixCodelistItemDao = DAORegistry::getDAO('ONIXCodelistItemDAO');
$onixCodes = $onixCodelistItemDao->getCodes('List5');
// get all codes from the settings that really exist
$selectedIdentificationCodes = array();
foreach ($onixCodes as $id => $codename) {
// remove id from name
$pos = -strrpos($codename," ");
if ($pos) {
$codename = substr($codename,0,-$pos);
}
if (in_array(trim($codename),$identifcationCodesSettings,true)) {
$selectedIdentificationCodes[] = $id;
}
}
// get all code values from the database
$identificationCodesDAO = new IdentificationCodesDAO();
$identificationCodes = $identificationCodesDAO->getData();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('pageTitle', 'plugins.generic.title.identificationCodes');
$templateMgr->assign('userRoles', $userRoles); // necessary for the backend sidenavi to appear
$templateMgr->assign('identificationCodes', $identificationCodes);
$templateMgr->assign('selectedIdentificationCodes', $selectedIdentificationCodes);
$templateMgr->assign('onixCodes', $onixCodes);
$identificationCodesPlugin = PluginRegistry::getPlugin('generic', IDENTIFICATIONCODES_PLUGIN_NAME);
$templateMgr->display($identificationCodesPlugin->getTemplatePath().'identificationCodes.tpl');
}
}
?>