-
Notifications
You must be signed in to change notification settings - Fork 3
/
IndexController.php
208 lines (192 loc) · 7.49 KB
/
IndexController.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/** Controller for the list of all extensions */
class Slicerappstore_IndexController extends Slicerappstore_AppController
{
/**
* Gets FolderDaos for package type and submission type
*/
private function _getPackageFolder($packagetype, $submissiontype)
{
$modelLoader = new MIDAS_ModelLoader();
$settingModel = $modelLoader->loadModel('Setting');
$folderModel = $modelLoader->loadModel('Folder');
$key = strtolower($packagetype).'s.'.$submissiontype.'.folder';
$folderId = $settingModel->getValueByName($key, 'slicerpackages');
if(!$folderId || !is_numeric($folderId))
{
throw new Exception('You must configure a folder id for key '.$key, -1);
}
$folder = $folderModel->load($folderId);
if(!$folder)
{
throw new Exception('Folder with id '.$folderId.' does not exist', -1);
}
if(!$folderModel->policyCheck($folder, $this->userSession->Dao, MIDAS_POLICY_READ))
{
throw new Exception('Invalid policy on folder '.$folderId, -1);
}
return $folder;
}
/**
* Action for rendering the page that lists extensions
* @param os (Optional) The default operating system to filter by
* @param arch (Optional) The default architecture to filter by
* @param release (Optional) The default release to filter by
*/
function indexAction()
{
$extensionModel = MidasLoader::loadModel('Extension', 'slicerpackages');
$packageModel = MidasLoader::loadModel('Package', 'slicerpackages');
$layout = $this->_getParam('layout');
if(!isset($layout) || $layout != 'empty')
{
$this->view->availableReleases = $extensionModel->getAllReleases();
$this->view->layout = 'layout';
}
$defaultRevision = '';
if (!$this->hasParam('revision'))
{
$folderDaos = array(
$this->_getPackageFolder('Package', 'nightly'));
$defaultRevision = $packageModel->getMostRecentRevision($folderDaos);
}
foreach(array('os', 'arch', 'release', 'revision', 'category', 'search') as $option)
{
$default = '';
if ($option == 'revision')
{
$default = $defaultRevision;
}
$this->view->json[$option] = $this->_getParam($option, $default);
}
$this->view->layout = $this->view->json['layout'];
}
/**
* If a filter param changes on the normal layout view, call into this
* to retrieve updated category counts based on the current filter
*/
function categoriesAction()
{
$this->disableLayout();
$this->disableView();
$filterParams = array();
foreach(array('os' => 'os', 'arch' => 'arch',
'revision' => 'slicer_revision',
'search' => 'search') as $option => $key)
{
$value = $this->_getParam($option);
if($value)
{
$filterParams[$key] = $value;
}
// Explicitly setting revision to empty string so that database returns correct counts
if(empty($value) and $option == 'revision')
{
$filterParams[$key] = '';
}
}
$extensionModel = MidasLoader::loadModel('Extension', 'slicerpackages');
$categories = $extensionModel->getCategoriesWithCounts($filterParams);
ksort($categories);
echo JsonComponent::encode($categories);
}
/**
* Call with ajax and filter parameters to get a list of extensions
* @param category The category filter
* @param os The os filter (win | linux | macosx)
* @param arch The architecture filter (i386 | amd64)
* @param release The release filter
* @param limit Pagination limit
* @param offset Pagination offset
* @param search The search text
*/
function listextensionsAction()
{
$this->disableLayout();
$this->disableView();
$category = $this->_getParam('category', 'any');
$os = $this->_getParam('os');
$arch = $this->_getParam('arch');
$release = $this->_getParam('release', 'any');
$revision = $this->_getParam('revision');
$limit = $this->_getParam('limit', 0);
$offset = $this->_getParam('offset', 0);
$search = $this->_getParam('search', '');
$modelLoader = new MIDAS_ModelLoader();
$settingModel = $modelLoader->loadModel('Setting');
$itemratingModel = $modelLoader->loadModel('Itemrating', 'ratings');
$extensionModel = $modelLoader->loadModel('Extension', 'slicerpackages');
$extensions = $extensionModel->get(array('os' => $os,
'arch' => $arch,
'release' => $release,
'category' => $category,
'slicer_revision' => $revision,
'limit' => $limit,
'offset' => $offset,
'search' => $search));
$defaultIcon = $settingModel->getValueByName('defaultIcon', $this->moduleName);
$results = array();
foreach($extensions['extensions'] as $extension)
{
$icon = $extension->getIconUrl();
if(!$icon)
{
$icon = $defaultIcon;
}
$contributors = $extension->getContributors();
if($contributors == '')
{
$contributors = 'Unknown contributors';
}
$result = array('slicerpackages_extension_id' => $extension->getKey(),
'item_id' => $extension->getItemId(),
'icon' => $icon,
'productname' => $extension->getProductname(),
'category' => $extension->getCategory(),
'subtitle' => $contributors);
$result['ratings'] = $itemratingModel->getAggregateInfo($extension->getItem());
$results[] = $result;
}
echo JsonComponent::encode(array('extensions' => $results, 'total' => $extensions['total']));
}
/**
* Used to download an extension. Simply forwards the request to the core item download controller
* for the extension's corresponding item.
* @param extensionId The id of the extension to download
*/
public function downloadextensionAction()
{
$extensionId = $this->_getParam('extensionId');
$modelLoader = new MIDAS_ModelLoader();
$extensionModel = $modelLoader->loadModel('Extension', 'slicerpackages');
$extension = $extensionModel->load($extensionId);
if(!$extension)
{
throw new Zend_Exception('Invalid extensionId parameter');
}
// Redirect to the download controller with the extension's item id
$this->_redirect('/download/index?items='.$extension->getItemId());
}
/**
* Call this to render the kitware info dialog
*/
public function kwinfoAction()
{
$this->disableLayout();
}
} // end class