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 OpenAireViewClaim1 extends JViewLegacy {
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,true);
36
        $this->funders = ($statistics == NULL) ? NULL : $statistics['funder']->data;
37
         usort($this->funders, function ($funder1, $funder2) { return strcmp($funder1->name , $funder2-> name); });
38
        $this->contexts = $claimModel->getContexts();
39

    
40
        //echo('Contexts: <pre>' . htmlspecialchars(print_r($claimModel -> getContexts(), TRUE)) . "</pre>");
41

    
42
        /*if (($this->funder == NULL) && ($this->funders != NULL)) {
43
            $funders = array_values($this->funders);
44
            $this->funder = array_shift($funders)->id;
45
        }*/
46
        switch (JRequest :: getString('action')) {
47
            case self :: SUBMIT:
48
               $projectIds = JRequest :: getString('projects', NULL);                              
49
               $conceptIds = JFactory::getApplication()->input->get('concepts',NULL,'array');               
50
                if ($projectIds !== NULL){
51
                    $projectIds = explode(",", $projectIds);
52
                    $claimModel->emptySelectedProjects();
53
                    foreach ($projectIds as $projectId) {
54
                        $project = $searchModel->getProject($projectId, $locale);
55
                        if ($project != NULL) {
56
                            $project->id = $projectId;
57
                            $claimModel->addSelectedProject($project);
58
                        }
59
                    }
60
                }
61
                
62
                if ($conceptIds !== NULL) {
63
                    //var_dump($conceptIds);
64
                    //exit;
65
                    
66
                   // $conceptIds = explode(",", $conceptIds);
67
                    $claimModel->emptySelectedConcepts();
68
                    foreach ($conceptIds as $i => $conceptId) {
69
                        $concept = $claimModel->getConcept($conceptId);
70
                        if ($concept != NULL) {
71
                            $concept -> id = $conceptId;
72
                            $claimModel->addSelectedConcept($concept);
73
                        }
74
                    }
75
                }
76
                JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim2'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
77

    
78
                return TRUE;
79
            case self :: ADD_PROJECT:
80
                $project = $searchModel->getProject($projectId, $locale);
81
                if ($project != NULL) {
82
                    $project->id = $projectId;
83
                    $claimModel->addSelectedProject($project);
84
                }
85
                JFactory :: getApplication()->redirect(JRoute :: _(JUri :: base() . 'index.php?option=com_openaire&view=claim1&Itemid=' . $this->itemId . '&funder=' . $this->funder, FALSE));
86
                return TRUE;
87
            case self :: REMOVE_PROJECT:
88
                $claimModel->removeSelectedProject($projectId);
89
                JFactory :: getApplication()->redirect(JRoute :: _(JUri :: base() . 'index.php?option=com_openaire&view=claim1&Itemid=' . $this->itemId . '&funder=' . $this->funder, FALSE));
90
                return TRUE;
91
            case self :: ADD_CONCEPT:                               
92
                $conceptsIds = JFactory :: getApplication()->input->get('concept', array(),'array');
93
                $subconceptsIds = JFactory :: getApplication()->input->get('subconcept', array(),'array');
94

    
95
                foreach ($conceptsIds as $i => $conceptId) {
96

    
97
                    if ($subconceptsIds[$i] == -1)
98
                        $concept = $claimModel->getConcept($conceptId);
99
                    else
100
                        continue;
101
                    if ($concept != NULL) {
102
                        $concept->id = $conceptId;
103
                        $claimModel->addSelectedConcept($concept);
104
                    }
105
                }
106
                foreach ($subconceptsIds as $i => $subconceptId) {
107
                    if ($subconceptId == -1)
108
                        continue;
109
                    $subconcept = $claimModel->getConcept($subconceptId);
110
                    if ($subconcept != NULL) {
111
                        $subconcept->id = $subconceptId;
112
                        $claimModel->addSelectedConcept($subconcept);
113
                    }
114
                }
115
                JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
116
                return TRUE;
117
            case self :: REMOVE_CONCEPT:
118
                $conceptId = JRequest :: getString('conceptId');
119
                $claimModel->removeSelectedConcept($conceptId);
120
                JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));
121
                return TRUE;
122
	case self :: STARTOVER:
123
                 $claimModel->emptySelectedProjects();
124
                 $claimModel->emptySelectedConcepts();
125
                 $claimModel->emptySelectedPublications();              
126
                 JFactory :: getApplication()->redirect(JRoute :: _('index.php?option=com_openaire&view=claim1'.(($this->itemId!==null)?'&Itemid=' . $this->itemId:''), FALSE));  
127
                return TRUE;
128
        }
129
        $this->selectedProjects = $claimModel->getSelectedProjects();
130

    
131
        $this->selectedConcepts = $claimModel->getSelectedConcepts();
132
        //JLog :: add("Retrieved contexts " . print_r($claimModel->getContexts(), TRUE), JLog :: DEBUG, self :: LOG);
133
        JLog :: add("Retrieved contexts " , JLog :: DEBUG, self :: LOG);
134

    
135
        if (count($errors = $this->get('Errors')) > 0) {
136
            JLog :: add('Error viewing claim1: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
137
            return FALSE;
138
        }
139
        parent :: display($template);
140
    }
141

    
142
}
143

    
(2-2/2)