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 OpenAireViewAdvancedSearchProjects extends JViewLegacy {
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,true);
33
		$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
		$input = JFactory :: getApplication() -> input;
38
		$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 -> fundingStreamsLevel2 = $this -> getParameter('fundingStreamLevel2');
46
                $this -> startDate = JRequest :: getInt('startDate', -1);
47
		$this -> startFromMonth = JRequest :: getUInt('startFromMonth', self :: DEFAULT_FROM_MONTH);
48
		$this -> startFromYear = JRequest :: getUInt('startFromYear', $this -> minStartYear);
49
		$this -> startToMonth = JRequest :: getUInt('startToMonth', self :: DEFAULT_TO_MONTH);
50
		$this -> startToYear = JRequest :: getUInt('startToYear', $this -> maxStartYear);
51
		$this -> endDate = JRequest :: getInt('endDate', -1);
52
		$this -> endFromMonth = JRequest :: getUInt('endFromMonth', self :: DEFAULT_FROM_MONTH);
53
		$this -> endFromYear = JRequest :: getUInt('endFromYear', $this -> minEndYear);
54
		$this -> endToMonth = JRequest :: getUInt('endToMonth', self :: DEFAULT_TO_MONTH);
55
		$this -> endToYear = JRequest :: getUInt('endToYear', $this -> maxEndYear);
56
		$this -> sc39s = $this -> getParameter('sc39');
57
		$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;});
58
		$this -> filters = array();
59
		$funder = JRequest :: getString('funderFilter');
60
		if ($funder != NULL) {
61
			$this -> filters['funderFilter'] = new JObject();
62
			$this -> filters['funderFilter'] -> name = 'funderFilter';
63
			$this -> filters['funderFilter'] -> value = $funder;
64
		}
65
		$fundingStream = JRequest :: getString('fundingStreamFilter');
66
		if ($fundingStream != NULL) {
67
			$this -> filters['fundingStreamFilter'] = new JObject();
68
			$this -> filters['fundingStreamFilter'] -> name = 'fundingStreamFilter';
69
			$this -> filters['fundingStreamFilter'] -> value = $fundingStream;
70
		}
71
		$scientificArea = JRequest :: getString('fundingStreamLevel1Filter');
72
                if ($scientificArea != NULL) {
73
			$this -> filters['fundingStreamLevel1Filter'] = new JObject();
74
			$this -> filters['fundingStreamLevel1Filter'] -> name = 'fundingStreamLevel1Filter';
75
			$this -> filters['fundingStreamLevel1Filter'] -> value = $scientificArea;
76
		}
77
                $fundingStreamLevel2 = JRequest :: getString('fundingStreamLevel2Filter');
78
		if ($fundingStreamLevel2 != NULL) {
79
			$this -> filters['fundingStreamLevel2Filter'] = new JObject();
80
			$this -> filters['fundingStreamLevel2Filter'] -> name = 'fundingStreamLevel2Filter';
81
			$this -> filters['fundingStreamLevel2Filter'] -> value = $fundingStreamLevel2;
82
		} 
83
		$startYear = intval(JRequest :: getString('startYearFilter'));
84
		if ($startYear != NULL) {
85
			$this -> filters['startYearFilter'] = new JObject();
86
			$this -> filters['startYearFilter'] -> name = 'startYearFilter';
87
			$this -> filters['startYearFilter'] -> value = $startYear;
88
		}
89
		$endYear = intval(JRequest :: getString('endYearFilter'));
90
		if ($endYear != NULL) {
91
			$this -> filters['endYearFilter'] = new JObject();
92
			$this -> filters['endYearFilter'] -> name = 'endYearFilter';
93
			$this -> filters['endYearFilter'] -> value = $endYear;
94
		}
95
		$sc39 = JRequest :: getString('sc39Filter');
96
		switch ($sc39) {
97
		case 'true':
98
			$sc39 = TRUE;
99
			break;
100
		case 'false':
101
			$sc39 = FALSE;
102
			break;
103
		default:
104
			$sc39 = NULL;
105
		}
106
		if ($sc39 !== NULL) {
107
			$this -> filters['sc39Filter'] = new JObject();
108
			$this -> filters['sc39Filter'] -> name = 'sc39Filter';
109
			$this -> filters['sc39Filter'] -> value = $sc39;
110
		}
111
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
112
		$this -> size = JRequest :: getUInt('size', self :: MIN_SIZE);
113
                $this -> size = ($this -> size > self :: MAX_SIZE || $this -> size < 1) ? self :: MIN_SIZE : $this -> size;
114
		if ((($this -> keywords != NULL) && ($this -> fields != NULL) && ($this -> constraints != NULL)) || ($this -> funders != NULL) || ($this -> fundingStreams != NULL) || ($this -> scientificAreas != NULL) || ($this -> fundingStreamsLevel2 != NULL) ||($this -> startDate != -1) || ($this -> endDate != -1) || ($this -> sc39s != NULL)) {
115
			JViewLegacy :: loadHelper('PiwikHelper');
116
			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)) .'&fundingStreamLevel2=' . urlencode(implode(',', $this -> fundingStreamsLevel2)) . '&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($fundingStream) . '&fundingStreamLevel1=' . urlencode($scientificArea) . '&fundingStreamLevel2=' . urlencode($fundingStreamLevel2) . '&startYear=' . urlencode($startYear) . '&endYear=' . urlencode($endYear) . '&sc39=' . urlencode($sc39) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
117
			$this -> result = $model -> advancedSearchProjects($this -> keywords, $this -> fields, $this -> constraints, $this -> funders, $this -> fundingStreams, $this -> scientificAreas,$this -> fundingStreamsLevel2, $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, $fundingStreamLevel2, $startYear, $endYear, $sc39, $this -> page, $this -> size, $locale);
118
			$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalProjects / $this -> size);
119
			if ($this -> totalPages == NULL)
120
				$this -> totalPages = 1;
121
                        $this -> page = ($this -> page > $this -> totalPages)? $this -> totalPages:$this -> page;
122
			$this -> pagingStart = $this -> page;
123
			$this -> pagingEnd = $this -> page;
124
			while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
125
				if ($this -> pagingStart > 1)
126
					$this -> pagingStart --;
127
				if ($this -> pagingEnd < $this -> totalPages)
128
					$this -> pagingEnd++;
129
			}
130
		} else
131
			$this -> result = NULL;
132
		if (count($errors = $this -> get('Errors')) > 0) {
133
			JLog :: add('Error viewing advancedsearchprojects: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
134
			return FALSE;
135
		}
136
		parent :: display($template);
137
	}
138
		
139
	private function getParameter($name) {
140
		$values = JFactory :: getApplication() -> input -> get($name, NULL, NULL);
141
		if ($values == NULL)
142
			$values = array();
143
		else if (!is_array($values)) {
144
			$value = $values;
145
			$values = array();
146
			$values[] = $value;
147
		}
148
		return $values;
149
	}
150
}
151

    
(2-2/2)