AbstractTerBasedController.php 3.58 KB
Newer Older
1
<?php
2
3
namespace T3o\TerFe2\Controller;

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*******************************************************************
 *  Copyright notice
 *
 *  (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ******************************************************************/

/**
 * Abstract controller
 */
31
abstract class AbstractTerBasedController extends \T3o\TerFe2\Controller\AbstractController
32
33
34
35
36
37
38
39
{

    /**
     * @var array
     */
    protected $frontendUser = array();

    /**
40
     * @var \T3o\TerFe2\Service\Ter
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
     */
    protected $terConnection;

    /**
     * @var array
     */
    protected $terSettings = array();

    /**
     * @var array
     */
    protected $terAccount = array();


    /**
     * Initialize action
     *
     * @return void
     */
    public function initializeAction()
    {
        parent::initializeAction();
        $this->frontendUser = (!empty($GLOBALS['TSFE']->fe_user->user) ? $GLOBALS['TSFE']->fe_user->user : array());
        $this->terSettings = (!empty($this->settings['terConnection']) ? $this->settings['terConnection'] : array());
        $this->terAccount = $this->getTerAccount();
        $this->terConnection = $this->getTerConnection();
    }


    /**
     * Initializes the view, add login state to template variables
     *
     * @return void
     */
75
    public function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view)
76
    {
77
        $this->view = $view;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
        $this->view->assign('loggedIn', FALSE);
        if (!empty($this->frontendUser)) {
            $this->view->assign('loggedIn', TRUE);
            $this->view->assign('userName', $this->frontendUser['username']);
            $this->view->assign('userId', $this->frontendUser['uid']);
        }
    }


    /**
     * Returns the account data from current frontend user
     *
     * @return array Frontend user account data
     */
    protected function getTerAccount()
    {
        $username = $this->frontendUser['username'];
        $password = $this->frontendUser['password'];
        if (!empty($this->terSettings['username']) && !empty($this->terSettings['password'])) {
            $username = $this->terSettings['username'];
            $password = $this->terSettings['password'];
        }
        return array(
            'username' => $username,
            'password' => $password,
        );
    }


    /**
     * Create a connection to the TER server
     *
110
     * @return \T3o\TerFe2\Service\Ter The TER connection
111
112
113
114
115
     */
    protected function getTerConnection()
    {
        // Check the wsdl uri
        if (empty($this->terSettings['wsdl'])) {
116
            throw new \Exception('No wsdl set to connect to TER server');
117
118
119
120
        }

        // Create connection
        $wsdl = $this->terSettings['wsdl'];
121
        return $this->objectManager->get(\T3o\TerFe2\Service\Ter::class, $wsdl, $this->terAccount['username'], $this->terAccount['password']);
122
123
124
    }

}