Project

General

Profile

1 17569 thanos.pap
<?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 OpenAireViewAdvancedSearchProjects extends JView {
10
	const LOG = 'openaire';
11
	const MODEL = 'search';
12
	const ACRONYM = 'acronym';
13
	const TITLE = 'title';
14
	const KEYWORDS = 'keywords';
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 DEFAULT_FROM_MONTH = 1;
22
	const DEFAULT_TO_MONTH = 12;
23
	const MAX_PAGES = 5;
24
25
	public function __construct($configuration = array()) {
26
		parent :: __construct($configuration);
27
	}
28
29
	function display($template = NULL) {
30
		$locale = JFactory :: getLanguage() -> getTag();
31
		$model = $this -> getModel(self :: MODEL);
32
		$this -> statistics = $model -> getProjectStatistics($locale);
33 18541 thanos.pap
		$this -> minStartYear = ($this -> statistics['startYear'] -> data == NULL) ? date('Y') : min(array_keys($this -> statistics['startYear'] -> data));
34
		$this -> maxStartYear = ($this -> statistics['startYear'] -> data == NULL) ? date('Y') : max(array_keys($this -> statistics['startYear'] -> data));
35
		$this -> minEndYear = ($this -> statistics['endYear'] -> data == NULL) ? date('Y') : min(array_keys($this -> statistics['endYear'] -> data));
36
		$this -> maxEndYear = ($this -> statistics['endYear'] -> data == NULL) ? date('Y') : max(array_keys($this -> statistics['endYear'] -> data));
37 24347 thanos.pap
		$input = JFactory :: getApplication() -> input;
38 17569 thanos.pap
		$this -> itemId = JRequest :: getUInt('Itemid', 0);
39
		$this -> keywords = $this -> getParameter('keyword');
40
		$this -> fields = $this -> getParameter('field');
41
		$this -> constraints = $this -> getParameter('constraint');
42
		$this -> funders = $this -> getParameter('funder');
43
		$this -> fundingStreams = $this -> getParameter('fundingStream');
44
		$this -> scientificAreas = $this -> getParameter('scientificArea');
45
		$this -> startDate = JRequest :: getInt('startDate', -1);
46
		$this -> startFromMonth = JRequest :: getUInt('startFromMonth', self :: DEFAULT_FROM_MONTH);
47
		$this -> startFromYear = JRequest :: getUInt('startFromYear', $this -> minStartYear);
48
		$this -> startToMonth = JRequest :: getUInt('startToMonth', self :: DEFAULT_TO_MONTH);
49
		$this -> startToYear = JRequest :: getUInt('startToYear', $this -> maxStartYear);
50
		$this -> endDate = JRequest :: getInt('endDate', -1);
51
		$this -> endFromMonth = JRequest :: getUInt('endFromMonth', self :: DEFAULT_FROM_MONTH);
52
		$this -> endFromYear = JRequest :: getUInt('endFromYear', $this -> minEndYear);
53
		$this -> endToMonth = JRequest :: getUInt('endToMonth', self :: DEFAULT_TO_MONTH);
54
		$this -> endToYear = JRequest :: getUInt('endToYear', $this -> maxEndYear);
55
		$this -> sc39s = $this -> getParameter('sc39');
56
		$this -> sc39s = array_filter(array_map(function ($sc39) {switch ($sc39) {case 'true': return TRUE; case 'false': return FALSE; default: return NULL;}}, $this -> sc39s), function ($sc39) {return $sc39 !== NULL;});
57 18541 thanos.pap
		$this -> filters = array();
58
		$funder = JRequest :: getString('funderFilter');
59
		if ($funder != NULL) {
60
			$this -> filters['funderFilter'] = new JObject();
61
			$this -> filters['funderFilter'] -> name = 'funderFilter';
62
			$this -> filters['funderFilter'] -> value = $funder;
63
		}
64
		$fundingStream = JRequest :: getString('fundingStreamFilter');
65
		if ($fundingStream != NULL) {
66
			$this -> filters['fundingStreamFilter'] = new JObject();
67
			$this -> filters['fundingStreamFilter'] -> name = 'fundingStreamFilter';
68
			$this -> filters['fundingStreamFilter'] -> value = $fundingStream;
69
		}
70
		$scientificArea = JRequest :: getString('scientificAreaFilter');
71
		if ($scientificArea != NULL) {
72
			$this -> filters['scientificAreaFilter'] = new JObject();
73
			$this -> filters['scientificAreaFilter'] -> name = 'scientificAreaFilter';
74
			$this -> filters['scientificAreaFilter'] -> value = $scientificArea;
75
		}
76
		$startYear = intval(JRequest :: getString('startYearFilter'));
77
		if ($startYear != NULL) {
78
			$this -> filters['startYearFilter'] = new JObject();
79
			$this -> filters['startYearFilter'] -> name = 'startYearFilter';
80
			$this -> filters['startYearFilter'] -> value = $startYear;
81
		}
82
		$endYear = intval(JRequest :: getString('endYearFilter'));
83
		if ($endYear != NULL) {
84
			$this -> filters['endYearFilter'] = new JObject();
85
			$this -> filters['endYearFilter'] -> name = 'endYearFilter';
86
			$this -> filters['endYearFilter'] -> value = $endYear;
87
		}
88
		$sc39 = JRequest :: getString('sc39Filter');
89
		switch ($sc39) {
90 17569 thanos.pap
		case 'true':
91 18541 thanos.pap
			$sc39 = TRUE;
92 17569 thanos.pap
			break;
93
		case 'false':
94 18541 thanos.pap
			$sc39 = FALSE;
95 17569 thanos.pap
			break;
96
		default:
97 18541 thanos.pap
			$sc39 = NULL;
98 17569 thanos.pap
		}
99 18541 thanos.pap
		if ($sc39 !== NULL) {
100
			$this -> filters['sc39Filter'] = new JObject();
101
			$this -> filters['sc39Filter'] -> name = 'sc39Filter';
102
			$this -> filters['sc39Filter'] -> value = $sc39;
103
		}
104 17569 thanos.pap
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
105
		$this -> size = JRequest :: getUInt('size', self :: MIN_SIZE);
106 18321 thanos.pap
		if ((($this -> keywords != NULL) && ($this -> fields != NULL) && ($this -> constraints != NULL)) || ($this -> funders != NULL) || ($this -> fundingStreams != NULL) || ($this -> scientificAreas != NULL) || ($this -> startDate != -1) || ($this -> endDate != -1) || ($this -> sc39s != NULL)) {
107 25013 thanos.pap
			JView :: loadHelper('PiwikHelper');
108
			PiwikHelper :: logPageView('advancedSearchProjects', 'keywords=' . urlencode(implode(',', $this -> keywords)) . '&fields=' . urlencode(implode(',', $this -> fields)) . '&constraints=' . urlencode(implode(',', $this -> constraints)) . '&funders=' . urlencode(implode(',', $this -> funders)) . '&fundingStreams=' . urlencode(implode(',', $this -> fundingStreams)) . '&scientificAreas=' . urlencode(implode(',', $this -> scientificAreas)) . '&startDate=' . urlencode($this -> startDate) . '&startFromMonth=' . urlencode($this -> startFromMonth) . '&startFromYear=' . urlencode($this -> startFromYear) . '&startToMonth=' . urlencode($this -> startToMonth) . '&startToYear=' . urlencode($this -> startToYear) . '&endDate=' . urlencode($this -> endDate) . '&endFromMonth=' . urlencode($this -> endFromMonth) . '&endFromYear=' . urlencode($this -> endFromYear) . '&endToMonth=' . urlencode($this -> endToMonth) . '&endToYear=' . urlencode($this -> endToYear) . '&sc39s=' . urlencode(implode(',', $this -> sc39s)) . '&funder=' . urlencode($funder) . '&fundingStream=' . urlencode($thisfundingStream) . '&scientificArea=' . urlencode($scientificArea) . '&startYear=' . urlencode($startYear) . '&endYear=' . urlencode($endYear) . '&sc39=' . urlencode($sc39) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
109 18541 thanos.pap
			$this -> result = $model -> advancedSearchProjects($this -> keywords, $this -> fields, $this -> constraints, $this -> funders, $this -> fundingStreams, $this -> scientificAreas, $this -> startDate, $this -> startFromMonth, $this -> startFromYear, $this -> startToMonth, $this -> startToYear, $this -> endDate, $this -> endFromMonth, $this -> endFromYear, $this -> endToMonth, $this -> endToYear, $this -> sc39s, $funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $this -> page, $this -> size, $locale);
110 17569 thanos.pap
			$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalProjects / $this -> size);
111
			if ($this -> totalPages == NULL)
112
				$this -> totalPages = 1;
113
			$this -> pagingStart = $this -> page;
114
			$this -> pagingEnd = $this -> page;
115
			while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
116
				if ($this -> pagingStart > 1)
117
					$this -> pagingStart --;
118
				if ($this -> pagingEnd < $this -> totalPages)
119
					$this -> pagingEnd++;
120 18541 thanos.pap
			}
121 24347 thanos.pap
		} else
122
			$this -> result = NULL;
123 17569 thanos.pap
		if (count($errors = $this -> get('Errors')) > 0) {
124
			JLog :: add('Error viewing advancedsearchprojects: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
125
			return FALSE;
126
		}
127
		parent :: display($template);
128
	}
129
130
	private function getParameter($name) {
131 24347 thanos.pap
		$values = JFactory :: getApplication() -> input -> get($name, NULL, NULL);
132
		if ($values == NULL)
133
			$values = array();
134
		else if (!is_array($values)) {
135
			$value = $values;
136
			$values = array();
137
			$values[] = $value;
138
		}
139
		return $values;
140 17569 thanos.pap
	}
141
}