Project

General

Profile

1
<?php
2

    
3
defined('_JEXEC') or die('Access denied');
4

    
5
jimport('joomla.application.component.view');
6
jimport('joomla.environment.request');
7
jimport('joomla.log.log');
8

    
9
class OpenAireViewBrowseDatasources extends JView {
10
	const LOG = 'openaire';
11
	const MODEL = 'search';
12
	const DEFAULT_PAGE = 1;
13
	const DEFAULT_SIZE = 10;
14
	const MAX_PAGES = 5;
15
	
16
	function display($template = NULL) {
17
		$model = $this -> getModel(self :: MODEL);
18
		$locale = JFactory :: getLanguage() -> getTag();
19
		$this -> itemId = JRequest :: getUInt('Itemid', 0);
20
		$this -> filters = array();
21
		$type = JRequest :: getString('type');
22
		if ($type != NULL) {
23
			$this -> filters['type'] = new JObject();
24
			$this -> filters['type'] -> name = 'type';
25
			$this -> filters['type'] -> value = $type;
26
		}
27
		$language = JRequest :: getString('languageFilter');
28
		if ($language != NULL) {
29
			$this -> filters['languageFilter'] = new JObject();
30
			$this -> filters['languageFilter'] -> name = 'languageFilter';
31
			$this -> filters['languageFilter'] -> value = $language;
32
		}
33
		$content = JRequest :: getString('content');
34
		if ($content != NULL) {
35
			$this -> filters['content'] = new JObject();
36
			$this -> filters['content'] -> name = 'content';
37
			$this -> filters['content'] -> value = $content;
38
		}
39
		$compatibility = JRequest :: getString('compatibility');
40
		if ($compatibility != NULL) {
41
			$this -> filters['compatibility'] = new JObject();
42
			$this -> filters['compatibility'] -> name = 'compatibility';
43
			$this -> filters['compatibility'] -> value = $compatibility;
44
		}
45
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
46
		$this -> size = JRequest :: getUInt('size', self :: DEFAULT_SIZE);
47
		JView :: loadHelper('PiwikHelper');
48
		PiwikHelper :: logPageView('browseDatasources', 'type=' . urlencode($type) . '&language=' . urlencode($language) . '&content=' . urlencode($content) . '&compatibility=' . urlencode($compatibility) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
49
		$this -> result = $model -> browseDatasources($type, $language, $content, $compatibility, $this -> page, $this -> size, $locale);
50
		$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalDatasources / $this -> size);
51
		if ($this -> totalPages == NULL)
52
			$this -> totalPages = 1;
53
		$this -> pagingStart = $this -> page;
54
		$this -> pagingEnd = $this -> page;
55
		while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
56
			if ($this -> pagingStart > 1)
57
				$this -> pagingStart--;
58
			if ($this -> pagingEnd < $this -> totalPages)
59
				$this -> pagingEnd++;
60
		}
61
		if (count($errors = $this -> get('Errors')) > 0) {
62
			JLog :: add('Error viewing browsedatasources: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
63
			return FALSE;
64
		}
65
		parent :: display($template);
66
	}
67
}
68

    
(2-2/2)