/
NavigationModule.php
193 lines (169 loc) · 6.97 KB
/
NavigationModule.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2012, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* OntoWiki module – Navigation
*
* this is the main navigation module
*
* @category OntoWiki
* @package Extensions_Navigation
* @author {@link http://sebastian.tramp.name Sebastian Tramp}
*/
class NavigationModule extends OntoWiki_Module
{
protected $_session = null;
public function init()
{
$this->_session = $this->_owApp->session;
}
public function getTitle()
{
return "Navigation";
}
/**
* Returns the menu of the module
*
* @return string
*/
public function getMenu()
{
// check if menu must be shown
if (!$this->_privateConfig->defaults->showMenu) {
return new OntoWiki_Menu();
}
// build main menu (out of sub menus below)
$mainMenu = new OntoWiki_Menu();
// edit sub menu
if ($this->_owApp->erfurt->getAc()->isModelAllowed('edit', $this->_owApp->selectedModel) ) {
$editMenu = new OntoWiki_Menu();
$editMenu->setEntry('Add Resource here', "javascript:navigationAddElement()");
$mainMenu->setEntry('Edit', $editMenu);
}
// count sub menu
$countMenu = new OntoWiki_Menu();
$countMenu->setEntry('10', "javascript:navigationEvent('setLimit', 10)")
->setEntry('20', "javascript:navigationEvent('setLimit', 20)")
->setEntry('30', "javascript:navigationEvent('setLimit', 30)");
// toggle sub menu
$toggleMenu = new OntoWiki_Menu();
// hidden elements
$toggleMenu->setEntry('Hidden Elements', "javascript:navigationEvent('toggleHidden')");
// empty elements
$toggleMenu->setEntry('Empty Elements', "javascript:navigationEvent('toggleEmpty')");
// implicit
$toggleMenu->setEntry('Implicit Elements', "javascript:navigationEvent('toggleImplicit')");
// view sub menu
$viewMenu = new OntoWiki_Menu();
$viewMenu->setEntry('Number of Elements', $countMenu);
$viewMenu->setEntry('Toggle Elements', $toggleMenu);
$viewMenu->setEntry('Reset Navigation', "javascript:navigationEvent('reset')");
$mainMenu->setEntry('View', $viewMenu);
// navigation type submenu
/*$sortMenu = new OntoWiki_Menu();
foreach ($this->_privateConfig->sorting as $key => $config) {
$sortMenu->setEntry($config->title, "javascript:navigationEvent('setSort', '$config->type')");
}
$mainMenu->setEntry('Sort', $sortMenu);*/
// navigation type submenu
$typeMenu = new OntoWiki_Menu();
foreach ($this->_privateConfig->config as $key => $config) {
if ($this->_privateConfig->defaults->checkTypes) {
if (isset($config->checkVisibility) && $config->checkVisibility == false) {
$typeMenu->setEntry($config->title, "javascript:navigationEvent('setType', '$key')");
} else if ($this->checkConfig($config) > 0 ) {
$typeMenu->setEntry($config->title, "javascript:navigationEvent('setType', '$key')");
}
} else {
$typeMenu->setEntry($config->title, "javascript:navigationEvent('setType', '$key')");
}
}
$mainMenu->setEntry('Type', $typeMenu);
return $mainMenu;
}
/**
* Returns the content
*/
public function getContents()
{
// scripts and css only if module is visible
$this->view->headScript()->appendFile($this->view->moduleUrl . 'navigation.js');
$this->view->headLink()->appendStylesheet($this->view->moduleUrl . 'navigation.css');
// this gives the complete config array as json to the javascript parts
$this->view->inlineScript()->prependScript(
'/* from modules/navigation/ */'.PHP_EOL.
'var navigationConfig = '.json_encode($this->_privateConfig->toArray()).';'.PHP_EOL
);
// this gives the navigation session config to the javascript parts
if ($this->_session->navigation) {
$this->view->inlineScript()->prependScript(
'/* from modules/navigation/ */'.PHP_EOL.
'var navigationConfig = '.json_encode($this->_privateConfig->toArray()) . ';' .PHP_EOL
);
}
$sessionKey = 'Navigation'.(isset($config->_session->identifier) ? $config->_session->identifier : '');
$stateSession = new Zend_Session_Namespace($sessionKey);
if (isset($stateSession) && ( $stateSession->model == (string)$this->_owApp->selectedModel)) {
// load setup
$this->view->inlineScript()->prependScript(
'/* from modules/navigation/ */'.PHP_EOL.
'var navigationStateSetup = '.$stateSession->setup .';'.PHP_EOL
);
// load view
$this->view->stateView = $stateSession->view;
// set js actions
$this->view->inlineScript()->prependScript(
'$(document).ready(function() { navigationPrepareList(); } );'.PHP_EOL
);
}
// init view from scratch
$this->view->inlineScript()->prependScript(
'$(document).ready(function() { navigationEvent(\'init\'); } );'.PHP_EOL
);
$data['session'] = $this->_session->navigation;
$content = $this->render('navigation', $data, 'data'); //
return $content;
}
public function shouldShow()
{
return isset($this->_owApp->selectedModel);
}
private function checkConfig($config)
{
$resVar = new Erfurt_Sparql_Query2_Var('resourceUri');
$typeVar = new Erfurt_Sparql_Query2_IriRef(EF_RDF_TYPE);
$query = new Erfurt_Sparql_Query2();
$query->addProjectionVar($resVar)->setDistinct(true);
$union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
if (is_string($config->hierarchyTypes)) {
$config->hierarchyTypes = array($config->hierarchyTypes);
}
foreach (self::a($config->hierarchyTypes) as $type) {
$ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
$ggp->addTriple(
$resVar,
$typeVar,
new Erfurt_Sparql_Query2_IriRef($type)
);
$union->addElement($ggp);
}
$query->addElement($union);
$query->setLimit(1);
$allResults = $this->_owApp->selectedModel->sparqlQuery($query);
/*$this->_owApp->logger->info(
'Navigation Query: ' .PHP_EOL . $query->__toString()
);
$this->_owApp->logger->info(
'Navigation Query Results: ' .PHP_EOL . print_r($all_results)
);*/
return count($allResults);
}
protected static function a($a)
{
return OntoWiki_Extension_Manager::doapArrayFixer($a);
}
}