MyProfileController.php 2.27 KB
Newer Older
1
<?php
2
declare(strict_types = 1);
3
4
5

namespace T3o\T3omy\Controller;

Stefan Busemann's avatar
Stefan Busemann committed
6
use T3o\T3omy\Domain\Model\MyProfile;
7
use T3o\T3omy\Domain\Repository\MyProfileRepository;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;

/**
 * Class UserController
 */
class MyProfileController extends ActionController
{
    /**
     * @var MyProfileRepository
     */
    public $myProfileRepository;

    /**
     * @var persistenceManager
     */
    public $persistenceManager;

    /**
     * @param MyProfileRepository $myProfileRepository
     */
    public function injectUserProfileRepository(MyProfileRepository $myProfileRepository)
    {
        $this->myProfileRepository = $myProfileRepository;
    }

    /**
     * @param PersistenceManager $persistenceManager
     */
    public function injectPersistenceManager(PersistenceManager $persistenceManager)
    {
        $this->persistenceManager = $persistenceManager;
    }

42
43
44
    /**
     * @param MyProfile|null $user
     */
45
46
    public function showAction(MyProfile $user = null)
    {
Stefan Busemann's avatar
Stefan Busemann committed
47
48
49
50
        if ($user === null) {
            $user = $this->myProfileRepository->findByUid(
                $GLOBALS['TSFE']->fe_user->user['uid']
            );
51

Stefan Busemann's avatar
Stefan Busemann committed
52
53
54
55
            if ($user === null) {
                $this->addFlashMessage(
                    'Something went wrong. We were not able to find your profile found!',
                    'Profile can not be shown',
56
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
Stefan Busemann's avatar
Stefan Busemann committed
57
58
59
                );
            }
        }
60
        $this->view->assign('user', $user);
61
62
    }

63
64
65
    /**
     * @param MyProfile $user
     */
66
67
    public function editAction(MyProfile $user)
    {
68
        $this->view->assign('user', $user);
69
70
    }

71
72
    /**
     * @param MyProfile $user
73
74
75
76
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
77
     */
78
79
    public function updateAction(MyProfile $user)
    {
80
81
82
        $this->myProfileRepository->update($user);
        $this->persistenceManager->persistAll();
        $this->redirect('show');
83
84
    }
}