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 OpenAireViewAdvancedSearchOrganizations extends JView {
10
	const LOG = 'openaire';
11
	const MODEL = 'search';
12
	const NAME = 'name';
13
	const SHORT_NAME = 'shortName';
14
	const ALL = 'all';
15
	const ANY = 'any';
16
	const DEFAULT_PAGE = 1;
17
	const MIN_SIZE = 10;
18
	const MAX_SIZE = 50;
19
	const SIZE_STEP = 10;
20
	const MAX_PAGES = 5;
21
	
22
	public function __construct($configuration = array()) {
23
		parent :: __construct($configuration);
24
	}
25
	
26
	function display($template = NULL) {
27
		$locale = JFactory :: getLanguage() -> getTag();
28
		$model = $this -> getModel(self :: MODEL);
29
		$this -> statistics = $model -> getOrganizationStatistics($locale);
30
		$input = JFactory :: getApplication() -> input;
31
		$this -> itemId = JRequest :: getUInt('Itemid', 0);
32
		$this -> keywords = $this -> getParameter('keyword');
33
		$this -> fields = $this -> getParameter('field');
34
		$this -> constraints = $this -> getParameter('constraint');
35
		$this -> countries = $this -> getParameter('country');
36
		$this -> types = $this -> getParameter('type');
37
		$this -> filters = array();
38
		$country = JRequest :: getString('countryFilter');
39
		if ($country != NULL) {
40
			$this -> filters['countryFilter'] = new JObject();
41
			$this -> filters['countryFilter'] -> name = 'countryFilter';
42
			$this -> filters['countryFilter'] -> value = $country;
43
		}
44
		$type = JRequest :: getString('typeFilter');
45
		if ($type != NULL) {
46
			$this -> filters['typeFilter'] = new JObject();
47
			$this -> filters['typeFilter'] -> name = 'typeFilter';
48
			$this -> filters['typeFilter'] -> value = $type;
49
		}
50
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
51
		$this -> size = JRequest :: getUInt('size', self :: MIN_SIZE);
52
		if ((($this -> keywords != NULL) && ($this -> fields != NULL) && ($this -> constraints != NULL)) || ($this -> countries != NULL) || ($this -> types != NULL)) {
53
			JView :: loadHelper('PiwikHelper');
54
			PiwikHelper :: logPageView('advancedSearchOrganizations', 'keywords=' . urlencode(implode(',', $this -> keywords)) . '&fields=' . urlencode(implode(',', $this -> fields)) . '&constraints=' . urlencode(implode(',', $this -> constraints)) . '&countries=' . urlencode(implode(',', $this -> countries)) . '&types=' . urlencode(implode(',', $this -> types)) . '&country=' . urlencode($country) . '&type=' . urlencode($type) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
55
			$this -> result = $model -> advancedSearchOrganizations($this -> keywords, $this -> fields, $this -> constraints, $this -> countries, $this -> types, $country, $type, $this -> page, $this -> size, $locale);
56
			$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalOrganizations / $this -> size);
57
			if ($this -> totalPages == NULL)
58
				$this -> totalPages = 1;
59
			$this -> pagingStart = $this -> page;
60
			$this -> pagingEnd = $this -> page;
61
			while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
62
				if ($this -> pagingStart > 1)
63
					$this -> pagingStart --;
64
				if ($this -> pagingEnd < $this -> totalPages)
65
					$this -> pagingEnd++;
66
			}			
67
		} else
68
			$this -> result = NULL;
69
		if (count($errors = $this -> get('Errors')) > 0) {
70
			JLog :: add('Error viewing advancedsearchorganizations: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
71
			return FALSE;
72
		}
73
		parent :: display($template);
74
	}
75
		
76
	private function getParameter($name) {
77
		$values = JFactory :: getApplication() -> input -> get($name, NULL, NULL);
78
		if ($values == NULL)
79
			$values = array();
80
		else if (!is_array($values)) {
81
			$value = $values;
82
			$values = array();
83
			$values[] = $value;
84
		}
85
		return $values;
86
	}
87
}
88

    
(2-2/2)