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 OpenAireViewClaim2raw extends JViewLegacy{
|
10
|
|
11
|
const CLAIM_MODEL = 'claim';
|
12
|
const SEARCH_MODEL = 'search';
|
13
|
const OPENAIRE = 'openaire';
|
14
|
const DOI = 'doi';
|
15
|
const ORCID = 'orcid';
|
16
|
const DATACITE = 'datacite';
|
17
|
const PAGE = 1;
|
18
|
const SIZE = 10;
|
19
|
const MAX_PAGES = 5;
|
20
|
const ADD_PUBLICATION = 'addPublication';
|
21
|
const REMOVE_PUBLICATION = 'removePublication';
|
22
|
const REMOVE_PROJECT = 'removeProject';
|
23
|
const REMOVE_CONCEPT = 'removeConcept';
|
24
|
const MAX_TITLE = 32;
|
25
|
const LOG = 'openaire';
|
26
|
|
27
|
function display($template = NULL) {
|
28
|
$this->itemId = JRequest :: getUInt('Itemid', NULL);
|
29
|
/* if (JFactory :: getUser() -> guest) {
|
30
|
//JFactory :: getApplication() -> redirect(JRoute :: _('index.php?option=com_users&view=login&Itemid=' . $this -> itemId . '&return=' . base64_encode(JRoute :: _('index.php?option=com_openaire&view=claim1&Itemid=' . $this -> itemId, FALSE)), FALSE));
|
31
|
return TRUE;
|
32
|
} */
|
33
|
|
34
|
$claimModel = $this->getModel(self :: CLAIM_MODEL);
|
35
|
$claimSearchModel = $this->getModel('claimsearch');
|
36
|
$searchModel = $this->getModel(self :: SEARCH_MODEL);
|
37
|
$application = JFactory :: getApplication();
|
38
|
$this->source = JRequest :: getString('source', self :: OPENAIRE);
|
39
|
$this->keyword = JRequest :: getString('keyword');
|
40
|
$this->type = JRequest :: getString('keyword');
|
41
|
$this->claiminline = JRequest :: getString('claiminline', 'false');
|
42
|
$this->targetType = JRequest :: getString('targetType', 'both');
|
43
|
$this->activeId = JRequest :: getString('activeId');
|
44
|
$this->sourceType = JRequest :: getString('sourceType');
|
45
|
$this->page = JRequest :: getUInt('page', self :: PAGE);
|
46
|
$this->size = JRequest :: getUInt('size', self :: SIZE);
|
47
|
$this->showCartTooltip = JRequest :: getString('showCartTooltip');
|
48
|
$this->showCartTooltip = ($this->showCartTooltip == 'true');
|
49
|
$locale = JFactory :: getLanguage()->getTag();
|
50
|
$publicationId = JRequest :: getString('publicationId');
|
51
|
$publicationSource = JRequest :: getString('publicationSource');
|
52
|
$projectId = JRequest :: getString('projectId');
|
53
|
$conceptId = JRequest :: getString('conceptId');
|
54
|
|
55
|
|
56
|
$this->formatCart = JRequest :: getString('formatCart', 'false');
|
57
|
|
58
|
if ($this->keyword != NULL) {
|
59
|
$this->results = new JObject();
|
60
|
$this->pagesFormat = new JObject();
|
61
|
switch ($this->source) {
|
62
|
case self :: OPENAIRE:
|
63
|
$this->results = $searchModel->searchPublications($this->keyword, FALSE, FALSE, FALSE, FALSE, NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, $this->page, $this->size, $locale,NULL,FALSE);
|
64
|
$this->pagesFormat = format_pages($this->results, $this->size, $this->page, self :: MAX_PAGES);
|
65
|
break;
|
66
|
case self :: DOI:
|
67
|
$this->results = $claimSearchModel->searchDOI($this->keyword, $this->page, $this->size);
|
68
|
$this->pagesFormat = format_pages($this->results, $this->size, $this->page, self :: MAX_PAGES);
|
69
|
break;
|
70
|
case self :: ORCID:
|
71
|
$this->results = $claimSearchModel->searchORCID($this->keyword, $this->page, $this->size);
|
72
|
$this->pagesFormat = format_pages($this->results, $this->size, $this->page, self :: MAX_PAGES);
|
73
|
break;
|
74
|
case self :: DATACITE:
|
75
|
$this->results = $claimSearchModel->searchDataCite($this->keyword, $this->page, $this->size);
|
76
|
$this->pagesFormat = format_pages($this->results, $this->size, $this->page, self :: MAX_PAGES);
|
77
|
break;
|
78
|
}
|
79
|
}
|
80
|
switch (JRequest :: getString('action')) {
|
81
|
case self :: ADD_PUBLICATION:
|
82
|
if (($publicationId != NULL) && ($this->results != NULL)) {
|
83
|
|
84
|
if (isset($this->results->totalPublications) && ($this->results->totalPublications != 0)) {
|
85
|
foreach ($this->results->publications as $publication) {
|
86
|
if ($publication->id == $publicationId) {
|
87
|
$publication->claim_type = "publication";
|
88
|
$publication->source = $this->source;
|
89
|
$claimModel->addSelectedPublication($publication, ($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
90
|
$this->formatCart = 'true';
|
91
|
}
|
92
|
}
|
93
|
} else if (isset($this->results->totalDatasets) && ($this->results->totalDatasets != 0)) {
|
94
|
foreach ($this->results->datasets as $dataset) {
|
95
|
if ($dataset->id == $publicationId) {
|
96
|
$dataset->claim_type = "dataset";
|
97
|
$dataset->source = $this->source;
|
98
|
$claimModel->addSelectedPublication($dataset, ($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
99
|
$this->formatCart = 'true';
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
}
|
104
|
|
105
|
|
106
|
break;
|
107
|
case self :: REMOVE_PUBLICATION:
|
108
|
$claimModel->removeSelectedPublication($publicationSource, $publicationId, ($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
109
|
$this->formatCart = 'true';
|
110
|
break;
|
111
|
case self :: REMOVE_PROJECT:
|
112
|
$claimModel->removeSelectedProject($projectId, ($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
113
|
$this->formatCart = 'true';
|
114
|
break;
|
115
|
|
116
|
case self :: REMOVE_CONCEPT:
|
117
|
$claimModel->removeSelectedConcept($conceptId, ($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
118
|
$this->formatCart = 'true';
|
119
|
break;
|
120
|
}
|
121
|
|
122
|
|
123
|
if ($this->formatCart === 'true') {
|
124
|
$this->selectedProjects = $claimModel->getSelectedProjects(($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
125
|
$this->selectedConcepts = $claimModel->getSelectedConcepts(($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
126
|
$this->selectedPublications = $claimModel->getSelectedPublications(($this->claiminline === 'true' ? OpenAireModelClaim::CLAIMINLINE2.$this->activeId : OpenAireModelClaim::CLAIM));
|
127
|
}
|
128
|
if (count($errors = $this->get('Errors')) > 0) {
|
129
|
JLog :: add('Error viewing claim2: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
|
130
|
return FALSE;
|
131
|
}
|
132
|
parent :: display($template);
|
133
|
}
|
134
|
|
135
|
}
|
136
|
|
137
|
function format_pages($results, $size, $page, $maxPages) {
|
138
|
|
139
|
$pages = new JObject();
|
140
|
$pages->page = $page;
|
141
|
$pages->totalPages = ($results == NULL) ? NULL :
|
142
|
ceil((isset($results->publications) ?
|
143
|
$results->totalPublications : $results->totalDatasets) / $size);
|
144
|
if ($pages->totalPages == NULL)
|
145
|
$pages->totalPages = 1;
|
146
|
$pages->pagingStart = $page;
|
147
|
$pages->pagingEnd = $page;
|
148
|
while (($pages->pagingEnd - $pages->pagingStart < $maxPages - 1) && (($pages->pagingStart != 1) || ($pages->pagingEnd != $pages->totalPages))) {
|
149
|
if ($pages->pagingStart > 1)
|
150
|
$pages->pagingStart --;
|
151
|
if ($pages->pagingEnd < $pages->totalPages)
|
152
|
$pages->pagingEnd++;
|
153
|
}
|
154
|
return $pages;
|
155
|
}
|