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 OpenAireViewBrowsePublications 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
		set_time_limit(100);
18
		$model = $this -> getModel(self :: MODEL);
19
		$locale = JFactory :: getLanguage() -> getTag();
20
		$this -> itemId = JRequest :: getUInt('Itemid', 0);
21
		$this -> filters = array();
22
		$type = JRequest :: getString('type');
23
		if ($type != NULL) {
24
			$this -> filters['type'] = new JObject();
25
			$this -> filters['type'] -> name = 'type';
26
			$this -> filters['type'] -> value = $type;
27
		}
28
		$language = JRequest :: getString('languageFilter', null, 'GET');
29
		if ($language != NULL) {
30
			$this -> filters['languageFilter'] = new JObject();
31
			$this -> filters['languageFilter'] -> name = 'languageFilter';
32
			$this -> filters['languageFilter'] -> value = $language;
33
		}
34
		$funder = JRequest :: getString('funder');
35
		if ($funder != NULL) {
36
			$this -> filters['funder'] = new JObject();
37
			$this -> filters['funder'] -> name = 'funder';
38
			$this -> filters['funder'] -> value = $funder;
39
		}
40
		$fundingStream = JRequest :: getString('fundingStream');
41
		if ($fundingStream != NULL) {
42
			$this -> filters['fundingStream'] = new JObject();
43
			$this -> filters['fundingStream'] -> name = 'fundingStream';
44
			$this -> filters['fundingStream'] -> value = $fundingStream;
45
		}
46
		$fundingStreamLevel1 = JRequest :: getString('fundingStreamLevel1');
47
		if ($fundingStreamLevel1 != NULL) {
48
			$this -> filters['fundingStreamLevel1'] = new JObject();
49
			$this -> filters['fundingStreamLevel1'] -> name = 'fundingStreamLevel1';
50
			$this -> filters['fundingStreamLevel1'] -> value = $fundingStreamLevel1;
51
		}
52
                $fundingStreamLevel2 = JRequest :: getString('fundingStreamLevel2');
53
		if ($fundingStreamLevel2 != NULL) {
54
			$this -> filters['fundingStreamLevel2'] = new JObject();
55
			$this -> filters['fundingStreamLevel2'] -> name = 'fundingStreamLevel2';
56
			$this -> filters['fundingStreamLevel2'] -> value = $fundingStreamLevel2;
57
		}                
58
		$year = intval(JRequest :: getUInt('year', NULL));
59
		if ($year != NULL) {
60
			$this -> filters['year'] = new JObject();
61
			$this -> filters['year'] -> name = 'year';
62
			$this -> filters['year'] -> value = $year;
63
		}
64
		$accessMode = JRequest :: getString('accessMode');
65
		if ($accessMode != NULL) {
66
			$this -> filters['accessMode'] = new JObject();
67
			$this -> filters['accessMode'] -> name = 'accessMode';
68
			$this -> filters['accessMode'] -> value = $accessMode;
69
		}
70
		$datasource = JRequest :: getString('datasource');
71
		if ($datasource != NULL) {
72
			$this -> filters['datasource'] = new JObject();
73
			$this -> filters['datasource'] -> name = 'datasource';
74
			$this -> filters['datasource'] -> value = $datasource;
75
		}
76
		$community = JRequest :: getString('community');
77
		if ($community != NULL) {
78
			$this -> filters['community'] = new JObject();
79
			$this -> filters['community'] -> name = 'community';
80
			$this -> filters['community'] -> value = $community;
81
		}
82
		$this -> project = JRequest :: getString('project');
83
		if ($this -> project != NULL) {
84
			$this -> filters['project'] = new JObject();
85
			$this -> filters['project'] -> name = 'project';
86
			$this -> filters['project'] -> value = $this -> project;
87
		} 
88
                $this -> page = JRequest :: getUInt('page', self :: DEFAULT_PAGE);
89
		$this -> size = JRequest :: getUInt('size', self :: DEFAULT_SIZE);
90
		$this -> author = JRequest :: getString('author');
91
		JViewLegacy :: loadHelper('PiwikHelper');
92
		PiwikHelper :: logPageView('browsePublications', 'type=' . urlencode($type) . '&language=' . urlencode($language) . '&funder=' . urlencode($funder) . '&fundingStream=' . urlencode($fundingStream)  . '&scientificArea=' . urlencode($fundingStreamLevel1) . '&year=' . urlencode($year) . '&accessMode=' . urlencode($accessMode) . '&datasource=' . urlencode($community) . '&community=' . urlencode($datasource) . '&page=' . urlencode($this -> page) . '&size=' . urlencode($this -> size) . '&locale=' . urlencode($locale) . '&project=' . urlencode($this -> project) . '&author=' . urlencode($this -> author));
93
 		$this -> result = $model -> browsePublications($type, $language, $funder, $fundingStream, $fundingStreamLevel1, $fundingStreamLevel2, $year, $accessMode, $datasource, $community, $this -> page, $this -> size, $locale, $this -> project, $this -> author,TRUE); 		                
94
                $this -> totalPages = ($this -> result == NULL) ? NULL : ceil($this -> result -> totalPublications / $this -> size);
95
                if ($this -> totalPages == NULL)
96
			$this -> totalPages = 1;
97
                $this -> page = ($this -> page > $this -> totalPages)? $this -> totalPages:$this -> page;
98
		$this -> pagingStart = $this -> page;
99
		$this -> pagingEnd = $this -> page;
100
		while (($this -> pagingEnd - $this -> pagingStart < self :: MAX_PAGES - 1) && (($this -> pagingStart != 1) || ($this -> pagingEnd != $this -> totalPages))) {
101
			if ($this -> pagingStart > 1)
102
				$this -> pagingStart--;
103
			if ($this -> pagingEnd < $this -> totalPages)
104
				$this -> pagingEnd++;
105
		}
106
		if (count($errors = $this -> get('Errors')) > 0) {
107
			JLog :: add('Error viewing browsepublications: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
108
			return FALSE;
109
		}
110
		parent :: display($template);
111
	}
112
}
113

    
(2-2/2)