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 OpenAireViewAdvancedSearchDatasets extends JViewLegacy {
10
	const LOG = 'openaire';
11
	const MODEL = 'search';
12
	const TITLE = 'title';
13
	const AUTHOR = 'author';
14
	const PUBLISHER = 'publisher';
15
	const SUBJECT = 'subject';
16
	const ALL = 'all';
17
	const ANY = 'any';
18
	const DEFAULT_PAGE = 1;
19
	const MIN_SIZE = 10;
20
	const MAX_SIZE = 50;
21
	const SIZE_STEP = 10;	
22
	const DEFAULT_FROM_MONTH = 1;
23
	const DEFAULT_TO_MONTH = 12;
24
	const MAX_PAGES = 5;
25
	
26
	public function __construct($configuration = array()) {
27
		parent :: __construct($configuration);
28
	}
29
	
30
	function display($template = NULL) {
31
		$locale = JFactory :: getLanguage() -> getTag();
32
		$model = $this -> getModel(self :: MODEL);
33
		$this -> statistics = $model -> getDatasetStatistics($locale,true);
34
		$this -> minYear = ($this -> statistics['year'] -> data == NULL) ? date('Y') : min(array_keys($this -> statistics['year'] -> data));
35
		$this -> maxYear = ($this -> statistics['year'] -> data == NULL) ? date('Y') : max(array_keys($this -> statistics['year'] -> data));
36
		$input = JFactory :: getApplication() -> input;
37
		$this -> itemId = JRequest :: getUInt('Itemid', 0);
38
		$this -> keywords = $this -> getParameter('keyword');
39
		$this -> fields = $this -> getParameter('field');
40
		$this -> constraints = $this -> getParameter('constraint');
41
		$this -> types = $this -> getParameter('type');
42
		$this -> languages = $this -> getParameter('language');
43
		$this -> funders = $this -> getParameter('funder');
44
		$this -> fundingStreams = $this -> getParameter('fundingStream');
45
		$this -> scientificAreas = $this -> getParameter('scientificArea');
46
                $this -> fundingStreamsLevel2 = $this -> getParameter('fundingStreamLevel2');
47
		$this -> date = JRequest :: getInt('date', -1);
48
		$this -> fromMonth = JRequest :: getUInt('fromMonth', self :: DEFAULT_FROM_MONTH);
49
		$this -> fromYear = JRequest :: getUInt('fromYear', $this -> minYear);
50
		$this -> toMonth = JRequest :: getUInt('toMonth', self :: DEFAULT_TO_MONTH);
51
		$this -> toYear = JRequest :: getUInt('toYear', $this -> maxYear);
52
		$this -> accessModes = $this -> getParameter('accessMode');
53
		$this -> datasources = $this -> getParameter('datasource');
54
		$this -> filters = array();
55
		$type = JRequest :: getString('typeFilter');
56
		if ($type != NULL) {
57
			$this -> filters['typeFilter'] = new JObject();
58
			$this -> filters['typeFilter'] -> name = 'typeFilter';
59
			$this -> filters['typeFilter'] -> value = $type;
60
		}
61
		$language = JRequest :: getString('languageFilter');
62
		if ($language != NULL) {
63
			$this -> filters['languageFilter'] = new JObject();
64
			$this -> filters['languageFilter'] -> name = 'languageFilter';
65
			$this -> filters['languageFilter'] -> value = $language;
66
		}
67
		$funder = JRequest :: getString('funderFilter');
68
		if ($funder != NULL) {
69
			$this -> filters['funderFilter'] = new JObject();
70
			$this -> filters['funderFilter'] -> name = 'funderFilter';
71
			$this -> filters['funderFilter'] -> value = $funder;
72
		}
73
		$fundingStream = JRequest :: getString('fundingStreamFilter');
74
		if ($fundingStream != NULL) {
75
			$this -> filters['fundingStreamFilter'] = new JObject();
76
			$this -> filters['fundingStreamFilter'] -> name = 'fundingStreamFilter';
77
			$this -> filters['fundingStreamFilter'] -> value = $fundingStream;
78
		}
79
		$scientificArea = JRequest :: getString('fundingStreamLevel1Filter');
80
		if ($scientificArea != NULL) {
81
			$this -> filters['fundingStreamLevel1Filter'] = new JObject();
82
			$this -> filters['fundingStreamLevel1Filter'] -> name = 'fundingStreamLevel1Filter';
83
			$this -> filters['fundingStreamLevel1Filter'] -> value = $scientificArea;
84
		}
85
                $fundingStreamLevel2 = JRequest :: getString('fundingStreamLevel2Filter');
86
		if ($fundingStreamLevel2 != NULL) {
87
			$this -> filters['fundingStreamLevel2Filter'] = new JObject();
88
			$this -> filters['fundingStreamLevel2Filter'] -> name = 'fundingStreamLevel2Filter';
89
			$this -> filters['fundingStreamLevel2Filter'] -> value = $fundingStreamLevel2;
90
		} 
91
		$year = JRequest :: getString('yearFilter');
92
		if ($year != NULL) {
93
			$this -> filters['yearFilter'] = new JObject();
94
			$this -> filters['yearFilter'] -> name = 'yearFilter';
95
			$this -> filters['yearFilter'] -> value = $year;
96
		}
97
		$accessMode = JRequest :: getString('accessModeFilter');
98
		if ($accessMode != NULL) {
99
			$this -> filters['accessModeFilter'] = new JObject();
100
			$this -> filters['accessModeFilter'] -> name = 'accessModeFilter';
101
			$this -> filters['accessModeFilter'] -> value = $accessMode;
102
		}
103
		$datasource = JRequest :: getString('datasourceFilter');
104
		if ($datasource != NULL) {
105
			$this -> filters['datasourceFilter'] = new JObject();
106
			$this -> filters['datasourceFilter'] -> name = 'datasourceFilter';
107
			$this -> filters['datasourceFilter'] -> value = $datasource;
108
		}
109
		$this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
110
		$this -> size = JRequest :: getUInt('size', self :: MIN_SIZE);
111
                $this -> size = ($this -> size > self :: MAX_SIZE || $this -> size < 1) ? self :: MIN_SIZE : $this -> size;
112
		if ((($this -> keywords != NULL) && ($this -> fields != NULL) && ($this -> constraints != NULL)) || ($this -> types != NULL) || ($this -> languages != NULL) || ($this -> funders != NULL) || ($this -> fundingStreams != NULL) || ($this -> scientificAreas != NULL)|| ($this -> fundingStreamsLevel2 != NULL) || ($this -> date != -1) || ($this -> accessModes != NULL) || ($this -> datasources != NULL)) {
113
		
114
			JViewLegacy :: loadHelper('PiwikHelper');
115
			PiwikHelper :: logPageView('Advanced Search Datasets');
116
			$this -> result = $model -> advancedSearchDatasets($this -> keywords, $this -> fields, $this -> constraints, $this -> types, $this -> languages, $this -> funders, $this -> fundingStreams, $this -> scientificAreas,$this -> fundingStreamsLevel2, $this -> date, $this -> fromMonth, $this -> fromYear, $this -> toMonth, $this -> toYear, $this -> accessModes, $this -> datasources, $type, $language, $funder, $fundingStream, $scientificArea, $fundingStreamLevel2, $year, $accessMode, $datasource, $this -> page, $this -> size, $locale);
117
 			$this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalDatasets / $this -> size);
118
			if ($this -> totalPages == NULL)
119
				$this -> totalPages = 1;
120
                        $this -> page = ($this -> page > $this -> totalPages)? $this -> totalPages:$this -> page;
121
			$this -> pagingStart = $this -> page;
122
			$this -> pagingEnd = $this -> page;
123
			while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
124
				if ($this -> pagingStart > 1)
125
					$this -> pagingStart --;
126
				if ($this -> pagingEnd < $this -> totalPages)
127
					$this -> pagingEnd++;
128
			}			
129
		} else
130
			$this -> result = NULL;
131
		if (count($errors = $this -> get('Errors')) > 0) {
132
			JLog :: add('Error viewing advancedsearchdatasets: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
133
			return FALSE;
134
		}
135
		parent :: display($template);
136
	}
137
		
138
	private function getParameter($name) {
139
		$values = JFactory :: getApplication() -> input -> get($name, NULL, NULL);
140
		if ($values == NULL)
141
			$values = array();
142
		else if (!is_array($values)) {
143
			$value = $values;
144
			$values = array();
145
			$values[] = $value;
146
		}
147
		return $values;
148
	}
149
}
150

    
(2-2/2)