Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
CatalogHandler.inc.php
1 <?php
2 
17 import('classes.handler.Handler');
18 
19 // import UI base classes
20 import('lib.pkp.classes.linkAction.LinkAction');
21 import('lib.pkp.classes.core.JSONMessage');
22 
23 class CatalogHandler extends Handler {
27  function CatalogHandler() {
28  parent::Handler();
29  }
30 
31 
32  //
33  // Overridden methods from Handler
34  //
38  function authorize($request, &$args, $roleAssignments) {
39  import('lib.pkp.classes.security.authorization.ContextRequiredPolicy');
40  $this->addPolicy(new ContextRequiredPolicy($request));
41  return parent::authorize($request, $args, $roleAssignments);
42  }
43 
44 
45  //
46  // Public handler methods
47  //
53  function index($args, $request) {
54  $templateMgr = TemplateManager::getManager($request);
55  $this->setupTemplate($request);
56  $press = $request->getPress();
57 
58  // Fetch the monographs to display
59  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
60  $publishedMonographs = $publishedMonographDao->getByPressId($press->getId());
61  $templateMgr->assign('publishedMonographs', $publishedMonographs->toAssociativeArray());
62 
63  // Display
64  $templateMgr->display('catalog/index.tpl');
65  }
66 
72  function newReleases($args, $request) {
73  $templateMgr = TemplateManager::getManager($request);
74  $this->setupTemplate($request);
75  $press = $request->getPress();
76 
77  // Provide a list of new releases to browse
78  $newReleaseDao = DAORegistry::getDAO('NewReleaseDAO');
79  $newReleases = $newReleaseDao->getMonographsByAssoc(ASSOC_TYPE_PRESS, $press->getId());
80  $templateMgr->assign('publishedMonographs', $newReleases);
81 
82  // Display
83  $templateMgr->display('catalog/newReleases.tpl');
84  }
85 
92  function category($args, $request) {
93  $templateMgr = TemplateManager::getManager($request);
94  $press = $request->getPress();
95  $this->setupTemplate($request);
96 
97  // Get the category
98  $categoryDao = DAORegistry::getDAO('CategoryDAO');
99  $categoryPath = array_shift($args);
100  $category =& $categoryDao->getByPath($categoryPath, $press->getId());
101  if (isset($category)) {
102  $templateMgr->assign('category', $category);
103  $additionalArgs = array('type' => 'category', 'path' => $category->getPath());
104  $templateMgr->assign('additionalArgs', $additionalArgs);
105 
106  // Fetch the monographs to display
107  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
108  $publishedMonographs =& $publishedMonographDao->getByCategoryId($category->getId(), $press->getId());
109  $templateMgr->assign('publishedMonographs', $publishedMonographs->toAssociativeArray());
110 
111  // Expose the featured monograph IDs and associated params
112  $featureDao = DAORegistry::getDAO('FeatureDAO');
113  $featuredMonographIds = $featureDao->getSequencesByAssoc(ASSOC_TYPE_CATEGORY, $category->getId());
114  $templateMgr->assign('featuredMonographIds', $featuredMonographIds);
115 
116  // Provide a list of new releases to browse
117  $newReleaseDao = DAORegistry::getDAO('NewReleaseDAO');
118  $newReleases = $newReleaseDao->getMonographsByAssoc(ASSOC_TYPE_CATEGORY, $category->getId());
119  $templateMgr->assign('newReleasesMonographs', $newReleases);
120  // Display
121  }
122  $templateMgr->display('catalog/category.tpl');
123  }
124 
131  function series($args, $request) {
132  $templateMgr = TemplateManager::getManager($request);
133  $press = $request->getPress();
134  $this->setupTemplate($request);
135 
136  // Get the series
137  $seriesDao = DAORegistry::getDAO('SeriesDAO');
138  $seriesPath = array_shift($args);
139  $series = $seriesDao->getByPath($seriesPath, $press->getId());
140  $templateMgr->assign('series', $series);
141  $additionalArgs = array('type' => 'series', 'path' => $series->getPath());
142  $templateMgr->assign('additionalArgs', $additionalArgs);
143 
144  // Fetch the monographs to display
145  $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
146  $publishedMonographs = $publishedMonographDao->getBySeriesId($series->getId(), $press->getId());
147  $templateMgr->assign('publishedMonographs', $publishedMonographs->toAssociativeArray());
148 
149  // Expose the featured monograph IDs and associated params
150  $featureDao = DAORegistry::getDAO('FeatureDAO');
151  $featuredMonographIds = $featureDao->getSequencesByAssoc(ASSOC_TYPE_SERIES, $series->getId());
152  $templateMgr->assign('featuredMonographIds', $featuredMonographIds);
153 
154  // Provide a list of new releases to browse
155  $newReleaseDao = DAORegistry::getDAO('NewReleaseDAO');
156  $newReleases = $newReleaseDao->getMonographsByAssoc(ASSOC_TYPE_SERIES, $series->getId());
157  $templateMgr->assign('newReleasesMonographs', $newReleases);
158 
159  // Display
160  $templateMgr->display('catalog/series.tpl');
161  }
162 
169  function results($args, $request) {
170  $templateMgr = TemplateManager::getManager($request);
171  $press = $request->getPress();
172  $this->setupTemplate($request);
173 
174  $query = $request->getUserVar('query');
175  $templateMgr->assign('searchQuery', $query);
176 
177  // Fetch the monographs to display
178  import('classes.search.MonographSearch');
179  $monographSearch = new MonographSearch();
180  $resultsIterator = $monographSearch->retrieveResults($press, array(null => $query));
181 
182  $publishedMonographs = array();
183  while ($result = $resultsIterator->next()) {
184  $publishedMonograph = $result['publishedMonograph'];
185  if ($publishedMonograph) {
186  $publishedMonographs[$publishedMonograph->getId()] = $publishedMonograph;
187  }
188  }
189  $templateMgr->assign('publishedMonographs', $publishedMonographs);
190 
191  // Display
192  $templateMgr->display('catalog/results.tpl');
193  }
194 
198  function fullSize($args, $request) {
199 
200  $press = $request->getPress();
201  $type = $request->getUserVar('type');
202  $id = $request->getUserVar('id');
203  $imageInfo = array();
204 
205  switch ($type) {
206  case 'category':
207  $path = '/categories/';
208  $categoryDao = DAORegistry::getDAO('CategoryDAO');
209  $category = $categoryDao->getById($id, $press->getId());
210  if ($category) {
211  $imageInfo = $category->getImage();
212  }
213  break;
214  case 'series':
215  $path = '/series/';
216  $seriesDao = DAORegistry::getDAO('SeriesDAO');
217  $series = $seriesDao->getById($id, $press->getId());
218  if ($series) {
219  $imageInfo = $series->getImage();
220  }
221  break;
222  default:
223  fatalError('invalid type specified');
224  break;
225  }
226 
227  if ($imageInfo) {
228  import('lib.pkp.classes.file.ContextFileManager');
229  $pressFileManager = new ContextFileManager($press->getId());
230  $pressFileManager->downloadFile($pressFileManager->getBasePath() . $path . $imageInfo['name'], null, true);
231  }
232  }
233 
237  function thumbnail($args, $request) {
238  $press = $request->getPress();
239  $type = $request->getUserVar('type');
240  $id = $request->getUserVar('id');
241  $imageInfo = array();
242 
243  switch ($type) {
244  case 'category':
245  $path = '/categories/';
246  $categoryDao = DAORegistry::getDAO('CategoryDAO');
247  $category = $categoryDao->getById($id, $press->getId());
248  if ($category) {
249  $imageInfo = $category->getImage();
250  }
251  break;
252  case 'series':
253  $path = '/series/';
254  $seriesDao = DAORegistry::getDAO('SeriesDAO');
255  $series = $seriesDao->getById($id, $press->getId());
256  if ($series) {
257  $imageInfo = $series->getImage();
258  }
259  break;
260  default:
261  fatalError('invalid type specified');
262  break;
263  }
264 
265  if ($imageInfo) {
266  import('lib.pkp.classes.file.ContextFileManager');
267  $pressFileManager = new ContextFileManager($press->getId());
268  $pressFileManager->downloadFile($pressFileManager->getBasePath() . $path . $imageInfo['thumbnailName'], null, true);
269  }
270  }
271 
275  function setupTemplate($request) {
276  $templateMgr = TemplateManager::getManager($request);
277  $press = $request->getPress();
278  if ($press) {
279  $templateMgr->assign('currency', $press->getSetting('currency'));
280  }
281  parent::setupTemplate($request);
282  }
283 }
284 
285 ?>
static & getDAO($name, $dbconn=null)
addPolicy($authorizationPolicy, $addToTop=false)
results($args, $request)
Class for retrieving monograph search results.
Policy to deny access if a context cannot be found in the request.
Handle requests for the press-specific part of the public-facing catalog.
Class defining operations for private context file management.
authorize($request, &$args, $roleAssignments)
index($args, $request)
Base request handler application class.
Definition: Handler.inc.php:20
downloadFile($filePath, $mediaType=null, $inline=false, $fileName=null)
thumbnail($args, $request)
category($args, $request)
fullSize($args, $request)
newReleases($args, $request)
series($args, $request)