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

    
(2-2/2)