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 OpenAireViewBrowsePeople extends JViewLegacy {
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
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
28
		$this -> size = JRequest :: getUInt('size', self :: DEFAULT_SIZE);
29
		JViewLegacy :: loadHelper('PiwikHelper');
30
		PiwikHelper :: logPageView('browsePeople', 'country=' . urlencode($country) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
31
		$this -> result = $model -> browsePeople($country, $this -> page, $this -> size, $locale);
32
		$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalPeople / $this -> size);
33
		if ($this -> totalPages == NULL)
34
			$this -> totalPages = 1;
35
		$this -> pagingStart = $this -> page;
36
		$this -> pagingEnd = $this -> page;
37
		while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
38
			if ($this -> pagingStart > 1)
39
				$this -> pagingStart--;
40
			if ($this -> pagingEnd < $this -> totalPages)
41
				$this -> pagingEnd++;
42
		}
43
		if (count($errors = $this -> get('Errors')) > 0) {
44
			JLog :: add('Error viewing browsepeople: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
45
			return FALSE;
46
		}
47
		parent :: display($template);
48
	}
49
}
50

    
(2-2/2)