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