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 OpenAireViewBrowseOrganizations 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
		$country = JRequest :: getString('country');
22
		if ($country != NULL) {
23
			$this -> filters['country'] = new JObject();
24
			$this -> filters['country'] -> name = 'country';
25
			$this -> filters['country'] -> value = $country;
26
		}
27
		$type = JRequest :: getString('type');
28
		if ($type != NULL) {
29
			$this -> filters['type'] = new JObject();
30
			$this -> filters['type'] -> name = 'type';
31
			$this -> filters['type'] -> value = $type;
32
		}
33
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
34
		$this -> size = JRequest :: getUInt('size', self :: DEFAULT_SIZE);
35
		JView :: loadHelper('PiwikHelper');
36
		PiwikHelper :: logPageView('browseOrganizations', 'country=' . urlencode($country) . '&type=' . urlencode($type) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
37
		$this -> result = $model -> browseOrganizations($country, $type, $this -> page, $this -> size, $locale);
38
		$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalOrganizations / $this -> size);
39
		if ($this -> totalPages == NULL)
40
			$this -> totalPages = 1;
41
		$this -> pagingStart = $this -> page;
42
		$this -> pagingEnd = $this -> page;
43
		while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
44
			if ($this -> pagingStart > 1)
45
				$this -> pagingStart--;
46
			if ($this -> pagingEnd < $this -> totalPages)
47
				$this -> pagingEnd++;
48
		}
49
		if (count($errors = $this -> get('Errors')) > 0) {
50
			JLog :: add('Error viewing browseorganizations: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
51
			return FALSE;
52
		}
53
		parent :: display($template);
54
	}
55
}
56

    
(2-2/2)