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 OpenAireViewBrowseProjects 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
		$funder = JRequest :: getString('funder');
22
		if ($funder != NULL) {
23
			$this -> filters['funder'] = new JObject();
24
			$this -> filters['funder'] -> name = 'funder';
25
			$this -> filters['funder'] -> value = $funder;
26
		}
27
		$fundingStream = JRequest :: getString('fundingStream');
28
		if ($fundingStream != NULL) {
29
			$this -> filters['fundingStream'] = new JObject();
30
			$this -> filters['fundingStream'] -> name = 'fundingStream';
31
			$this -> filters['fundingStream'] -> value = $fundingStream;
32
		}
33
		$scientificArea = JRequest :: getString('scientificArea');
34
		if ($scientificArea != NULL) {
35
			$this -> filters['scientificArea'] = new JObject();
36
			$this -> filters['scientificArea'] -> name = 'scientificArea';
37
			$this -> filters['scientificArea'] -> value = $scientificArea;
38
		}
39
		$startYear = JRequest :: getUInt('startYear', NULL);
40
		if ($startYear != NULL) {
41
			$this -> filters['startYear'] = new JObject();
42
			$this -> filters['startYear'] -> name = 'startYear';
43
			$this -> filters['startYear'] -> value = $startYear;
44
		}
45
		$endYear = JRequest :: getUInt('endYear', NULL);
46
		if ($endYear != NULL) {
47
			$this -> filters['endYear'] = new JObject();
48
			$this -> filters['endYear'] -> name = 'endYear';
49
			$this -> filters['endYear'] -> value = $endYear;
50
		}
51
		$sc39 = JRequest :: getString('sc39', NULL);
52
		switch ($sc39) {
53
		case 'true':
54
			$sc39 = TRUE;
55
			break;
56
		case 'false':
57
			$sc39 = FALSE;
58
			break;
59
		default:
60
			$sc39 = NULL;
61
		}
62
		if ($sc39 !== NULL) {
63
			$this -> filters['sc39'] = new JObject();
64
			$this -> filters['sc39'] -> name = 'sc39';
65
			$this -> filters['sc39'] -> value = $sc39;
66
		}
67
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
68
		$this -> size = JRequest :: getUInt('size', self :: DEFAULT_SIZE);
69
		JViewLegacy :: loadHelper('PiwikHelper');
70
		PiwikHelper :: logPageView('browseProjects', 'funder=' . urlencode($funder) . '&fundingStream=' . urlencode($fundingStream) . '&scientificArea=' . urlencode($scientificArea) . '&startYear=' . urlencode($startYear) . '&endYear=' . urlencode($endYear) . '&sc39=' . urlencode($sc39) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale));
71
		$this -> result = $model -> browseProjects($funder, $fundingStream, $scientificArea, $startYear, $endYear, $sc39, $this -> page, $this -> size, $locale);
72
		$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalProjects / $this -> size);
73
		if ($this -> totalPages == NULL)
74
			$this -> totalPages = 1;
75
		$this -> pagingStart = $this -> page;
76
		$this -> pagingEnd = $this -> page;
77
		while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
78
			if ($this -> pagingStart > 1)
79
				$this -> pagingStart--;
80
			if ($this -> pagingEnd < $this -> totalPages)
81
				$this -> pagingEnd++;
82
		}
83
		if (count($errors = $this -> get('Errors')) > 0) {
84
			JLog :: add('Error viewing browseprojects: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
85
			return FALSE;
86
		}
87
		parent :: display($template);
88
	}
89
}
90

    
(2-2/2)