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 OpenAireViewClaimInline extends JView {
10
	const CLAIM_MODEL = 'claim';
11
    const SEARCH_MODEL = 'search';
12
    const SUBMIT = 'submit';
13
    const MAX_TITLE = 32;
14
    const LOG = 'openaire';
15

    
16
    function display($template = NULL) {
17
        $this -> complete = false;
18
        $this->itemId = JRequest :: getUInt('Itemid', 0);
19
        $this -> publicationId = JRequest :: getString('activePublicationId');
20
        $user = JFactory :: getUser();
21
        if (JFactory :: getUser()->guest) {
22
            JFactory :: getApplication()->redirect(JRoute :: _(JURI :: base() . 'index.php?option=com_users&view=login&tmpl=modal&activePublicationId=' . $this -> publicationId . 'Itemid=' . $this->itemId . '&return=' . base64_encode(JRoute :: _('index.php?option=com_openaire&view=claiminline&tmpl=modal&Itemid=' . $this->itemId, FALSE)), FALSE));
23
            return TRUE;
24
        }
25

    
26

    
27
        $claimModel = $this->getModel(self :: CLAIM_MODEL);
28
        $searchModel = $this->getModel(self :: SEARCH_MODEL);
29
        $locale = JFactory :: getLanguage()->getTag();
30
        $projectId = JRequest :: getString('projectId');
31
        
32
        $this->funder = JRequest :: getString('funder');
33
        $this -> fields_layout = JRequest :: getString('fields_layout', 'horizontal');
34
        $statistics = $searchModel->getProjectStatistics($locale);
35
        $this->funders = ($statistics == NULL) ? NULL : $statistics['funder']->data;
36
        $this->contexts = $claimModel->getContexts();
37

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

    
40
        /*if (($this->funder == NULL) && ($this->funders != NULL)) {
41
            $funders = array_values($this->funders);
42
            $this->funder = array_shift($funders)->id;
43
        }*/
44
        switch (JRequest :: getString('action')) {
45
            case self :: SUBMIT:
46
               $publication = $searchModel->getPublication($this -> publicationId, $locale);
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, OpenAireModelClaim::CLAIMINLINE. $this -> publicationId);
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
                       
70
                        if ($concept != NULL) {
71
                            $concept -> id = $conceptId;
72
                            $claimModel->addSelectedConcept($concept, OpenAireModelClaim::CLAIMINLINE. $this -> publicationId);
73
                        }
74
                    }
75
                }
76
               $claimModel->claimSelectedPublications($user, OpenAireModelClaim::CLAIMINLINE, $publication, $this -> publicationId);
77

    
78
               $this -> complete = true;
79
               parent :: display($template);
80
               return true;
81
        }
82
        $this->selectedProjects = $claimModel->getSelectedProjects(OpenAireModelClaim::CLAIMINLINE . $this -> publicationId);
83

    
84
        $this->selectedConcepts = $claimModel->getSelectedConcepts(OpenAireModelClaim::CLAIMINLINE . $this -> publicationId);
85
        JLog :: add("Retrieved contexts " . print_r($claimModel->getContexts(), TRUE), JLog :: DEBUG, self :: LOG);
86

    
87
        if (count($errors = $this->get('Errors')) > 0) {
88
            JLog :: add('Error viewing claiminline: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
89
            return FALSE;
90
        }
91
        parent :: display($template);
92
    }
93

    
94
}
95

    
(2-2/2)