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

    
(2-2/2)