-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlumAnalyticsBlockPlugin.php
131 lines (114 loc) · 3.05 KB
/
PlumAnalyticsBlockPlugin.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
<?php
/**
* @file plugins/generic/plumAnalytics/PlumAnalyticsBlockPlugin.inc.php
*
* Copyright (c) 2018 University of Pittsburgh
* Distributed under the GNU GPL v2 or later. For full terms see the file docs/COPYING.
*
* @class PlumAnalyticsBlockPlugin
* @ingroup plugins_generic_plumAnalytics
*
* @brief Class for Plum Analytics block plugin
*/
namespace APP\plugins\generic\plumAnalytics;
use PKP\plugins\BlockPlugin;
use PKP\config\Config;
use PKP\plugins\PluginRegistry;
class PlumAnalyticsBlockPlugin extends BlockPlugin {
/** @var $parentPluginName string name of PlumAnalytics plugin */
var $parentPluginName;
/** @var $pluginPath string path to PlumAnalytics plugins */
var $pluginPath;
/**
* Constructor
* @param $parentPluginName string
* @param $pluginPath string
*/
function __construct($parentPluginName, $pluginPath) {
parent::__construct();
$this->parentPluginName = $parentPluginName;
$this->pluginPath = $pluginPath;
}
/**
* Override currentVersion to prevent upgrade and delete management.
* @return boolean
*/
function getCurrentVersion() {
return false;
}
/**
* @copydoc LazyLoadPlugin::getEnabled()
*/
function getEnabled($contextId = null) {
if (!Config::getVar('general', 'installed')) return true;
return parent::getEnabled($contextId);
}
/**
* Get the display name of this plugin.
* @return String
*/
function getDisplayName() {
return __('plugins.generic.plumAnalytics.block.displayName');
}
/**
* Get a description of the plugin.
* @return String
*/
function getDescription() {
return __('plugins.generic.plumAnalytics.block.description');
}
/**
* Hide this plugin from the management interface (it's subsidiary)
* @return boolean
*/
function getHideManagement() {
return true;
}
/**
* Get the supported contexts (e.g. BLOCK_CONTEXT_...) for this block.
* @return array
*/
function getSupportedContexts() {
return array(BLOCK_CONTEXT_SIDEBAR);
}
/**
* Get the plum plugin
* @return object
*/
function &getPlumPlugin() {
$plugin = PluginRegistry::getPlugin('generic', $this->parentPluginName);
return $plugin;
}
/**
* Override the builtin to get the correct plugin path.
* @return string
*/
function getPluginPath() {
return $this->pluginPath;
}
/**
* Get the name of the block template file.
* @return String
*/
function getBlockTemplateFilename() {
$plugin = $this->getPlumPlugin();
return (method_exists($plugin, 'getTemplateResource') ? '' : 'templates'.DIRECTORY_SEPARATOR) . 'blockPlumWidget.tpl';
}
/**
* @copydoc BlockPlugin::getContents()
*/
function getContents($templateMgr, $request = null) {
$plugin = $this->getPlumPlugin();
$context = $request->getContext();
if ($templateMgr) {
$doi = $plugin->getSubmissionDOI($templateMgr, $context->getId(), 'block');
if ($doi) {
$templateMgr->assign('blockTitle', $plugin->getSetting($context->getId(), 'blockTitle'));
$plugin->setupTemplateManager($context->getId(), $doi, $templateMgr);
return parent::getContents($templateMgr);
}
}
return false;
}
}
?>