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 OpenAireViewClaim1 extends JView {
|
10
|
const CLAIM_MODEL = 'claim';
|
11
|
const SEARCH_MODEL = 'search';
|
12
|
const SUBMIT = 'submit';
|
13
|
const STARTOVER = 'startOver';
|
14
|
const ADD_PROJECT = 'addProject';
|
15
|
const REMOVE_PROJECT = 'removeProject';
|
16
|
const ADD_CONCEPT = 'addConcept';
|
17
|
const REMOVE_CONCEPT = 'removeConcept';
|
18
|
const MAX_TITLE = 32;
|
19
|
const LOG = 'openaire';
|
20
|
|
21
|
function display($template = NULL) {
|
22
|
$this->itemId = JRequest :: getUInt('Itemid', NULL);
|
23
|
if (JFactory :: getUser()->guest) {
|
24
|
|
25
|
$redirect='index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:'').''.(JRequest :: getString('projectId')!=null)?'&projectId'.JRequest :: getString('projectId'):''.(JRequest :: getString('action')!=null)?'&action'.JRequest :: getString('action'):'';
|
26
|
JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_users&view=login'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''). '&return=' . base64_encode(JRoute :: _($redirect, FALSE)), FALSE));
|
27
|
return TRUE;
|
28
|
}
|
29
|
$claimModel = $this->getModel(self :: CLAIM_MODEL);
|
30
|
$searchModel = $this->getModel(self :: SEARCH_MODEL);
|
31
|
$locale = JFactory :: getLanguage()->getTag();
|
32
|
$projectId = JRequest :: getString('projectId');
|
33
|
$this->funder = JRequest :: getString('funder');
|
34
|
$this -> fields_layout = JRequest :: getString('fields_layout', 'horizontal');
|
35
|
$statistics = $searchModel->getProjectStatistics($locale);
|
36
|
$this->funders = ($statistics == NULL) ? NULL : $statistics['funder']->data;
|
37
|
$this->contexts = $claimModel->getContexts();
|
38
|
|
39
|
//echo('Contexts: <pre>' . htmlspecialchars(print_r($claimModel -> getContexts(), TRUE)) . "</pre>");
|
40
|
|
41
|
/*if (($this->funder == NULL) && ($this->funders != NULL)) {
|
42
|
$funders = array_values($this->funders);
|
43
|
$this->funder = array_shift($funders)->id;
|
44
|
}*/
|
45
|
switch (JRequest :: getString('action')) {
|
46
|
case self :: SUBMIT:
|
47
|
$projectIds = JRequest :: getVar('projects', FALSE);
|
48
|
$conceptIds = JRequest :: getVar('concepts', FALSE);
|
49
|
|
50
|
|
51
|
if ($projectIds !== FALSE){
|
52
|
$projectIds = explode(",", $projectIds);
|
53
|
$claimModel->emptySelectedProjects();
|
54
|
foreach ($projectIds as $projectId) {
|
55
|
$project = $searchModel->getProject($projectId, $locale);
|
56
|
if ($project != NULL) {
|
57
|
$project->id = $projectId;
|
58
|
$claimModel->addSelectedProject($project);
|
59
|
}
|
60
|
}
|
61
|
}
|
62
|
|
63
|
if ($conceptIds !== FALSE) {
|
64
|
//var_dump($conceptIds);
|
65
|
//exit;
|
66
|
$claimModel->emptySelectedConcepts();
|
67
|
foreach ($conceptIds as $i => $conceptId) {
|
68
|
$concept = $claimModel->getConcept($conceptId);
|
69
|
if ($concept != NULL) {
|
70
|
$concept -> id = $conceptId;
|
71
|
$claimModel->addSelectedConcept($concept);
|
72
|
}
|
73
|
}
|
74
|
}
|
75
|
JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim2'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
|
76
|
|
77
|
return TRUE;
|
78
|
case self :: ADD_PROJECT:
|
79
|
$project = $searchModel->getProject($projectId, $locale);
|
80
|
if ($project != NULL) {
|
81
|
$project->id = $projectId;
|
82
|
$claimModel->addSelectedProject($project);
|
83
|
}
|
84
|
JFactory :: getApplication()->redirect(JRoute :: _(JURI :: base() . 'index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:'') . '&funder=' . $this->funder, FALSE));
|
85
|
return TRUE;
|
86
|
case self :: REMOVE_PROJECT:
|
87
|
$claimModel->removeSelectedProject($projectId);
|
88
|
JFactory :: getApplication()->redirect(JRoute :: _(JURI :: base() . 'index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''). '&funder=' . $this->funder, FALSE));
|
89
|
return TRUE;
|
90
|
case self :: ADD_CONCEPT:
|
91
|
$conceptsIds = JRequest :: getVar('concept', array());
|
92
|
$subconceptsIds = JRequest :: getVar('subconcept', array());
|
93
|
|
94
|
foreach ($conceptsIds as $i => $conceptId) {
|
95
|
|
96
|
if ($subconceptsIds[$i] == -1)
|
97
|
$concept = $claimModel->getConcept($conceptId);
|
98
|
else
|
99
|
continue;
|
100
|
if ($concept != NULL) {
|
101
|
$concept->id = $conceptId;
|
102
|
$claimModel->addSelectedConcept($concept);
|
103
|
}
|
104
|
}
|
105
|
foreach ($subconceptsIds as $i => $subconceptId) {
|
106
|
if ($subconceptId == -1)
|
107
|
continue;
|
108
|
$subconcept = $claimModel->getConcept($subconceptId);
|
109
|
if ($subconcept != NULL) {
|
110
|
$subconcept->id = $subconceptId;
|
111
|
$claimModel->addSelectedConcept($subconcept);
|
112
|
}
|
113
|
}
|
114
|
JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
|
115
|
return TRUE;
|
116
|
case self :: REMOVE_CONCEPT:
|
117
|
$conceptId = JRequest :: getString('conceptId');
|
118
|
$claimModel->removeSelectedConcept($conceptId);
|
119
|
JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
|
120
|
return TRUE;
|
121
|
case self :: STARTOVER:
|
122
|
$claimModel->emptySelectedProjects();
|
123
|
$claimModel->emptySelectedConcepts();
|
124
|
$claimModel->emptySelectedPublications();
|
125
|
JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
|
126
|
return TRUE;
|
127
|
}
|
128
|
$this->selectedProjects = $claimModel->getSelectedProjects();
|
129
|
|
130
|
$this->selectedConcepts = $claimModel->getSelectedConcepts();
|
131
|
//JLog :: add("Retrieved contexts " . print_r($claimModel->getContexts(), TRUE), JLog :: DEBUG, self :: LOG);
|
132
|
JLog :: add("Retrieved contexts " , JLog :: DEBUG, self :: LOG);
|
133
|
|
134
|
if (count($errors = $this->get('Errors')) > 0) {
|
135
|
JLog :: add('Error viewing claim1: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
|
136
|
return FALSE;
|
137
|
}
|
138
|
parent :: display($template);
|
139
|
}
|
140
|
|
141
|
}
|
142
|
|