CategoryController.php 4.17 KB
Newer Older
speedprogs_de's avatar
speedprogs_de committed
1
<?php
2
3
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
31
32
33
34
35
36
37
38
39
40
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
75
76
77
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************
 *  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!
 ******************************************************************/

/**
 * Controller for the category object
 */
class Tx_TerFe2_Controller_CategoryController extends Tx_TerFe2_Controller_AbstractController
{

    /**
     * @var Tx_TerFe2_Domain_Repository_CategoryRepository
     */
    protected $categoryRepository;

    /**
     * @var Tx_TerFe2_Domain_Repository_ExtensionRepository
     */
    protected $extensionRepository;


    /**
     * Initializes the controller
     *
     * @return void
     */
    protected function initializeController()
    {
        $this->categoryRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_CategoryRepository');
        $this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionRepository');
    }


    /**
     * List action, displays all categories
     *
     * @return void
     */
    public function listAction()
    {
        $this->view->assign('categories', $this->categoryRepository->findAll());
    }


    /**
     * Action that displays a single category
     *
     * @param Tx_TerFe2_Domain_Model_Category $category The category to display
     * @return void
     */
    public function showAction(Tx_TerFe2_Domain_Model_Category $category)
    {
        $this->view->assign('category', $category);
        $categoryExtensions = $this->extensionRepository->findByCategory($category);
        $this->view->assign('categoryExtensions', $categoryExtensions);
    }


    /**
     * Displays a form for creating a new category
     *
     * @param Tx_TerFe2_Domain_Model_Category $newCategory New category object
     * @return void
     * @dontvalidate $newCategory
     */
    public function newAction(Tx_TerFe2_Domain_Model_Category $newCategory = NULL)
    {
        $this->view->assign('newCategory', $newCategory);
    }


    /**
     * Creates a new category
     *
     * @param Tx_TerFe2_Domain_Model_Category $newCategory New category object
     * @return void
     */
    public function createAction(Tx_TerFe2_Domain_Model_Category $newCategory)
    {
        $this->categoryRepository->add($newCategory);
        $this->redirectWithMessage($this->translate('msg.category_created'), 'list');
    }


    /**
     * Displays a form to edit an existing category
     *
     * @param Tx_TerFe2_Domain_Model_Category $category The category to display
     * @return void
     * @dontvalidate $category
     */
    public function editAction(Tx_TerFe2_Domain_Model_Category $category)
    {
        $this->view->assign('category', $category);
    }


    /**
     * Updates an existing category
     *
     * @param Tx_TerFe2_Domain_Model_Category $category Category to update
     * @return void
     */
    public function updateAction(Tx_TerFe2_Domain_Model_Category $category)
    {
        $this->categoryRepository->update($category);
        $this->redirectWithMessage($this->translate('msg.category_updated'), 'list');
    }


    /**
     * Deletes an existing category
     *
     * @param Tx_TerFe2_Domain_Model_Category $category The category to delete
     * @return void
     */
    public function deleteAction(Tx_TerFe2_Domain_Model_Category $category)
    {
        $this->categoryRepository->remove($category);
        $this->redirectWithMessage($this->translate('msg.category_deleted'), 'list');
    }

}

speedprogs_de's avatar
speedprogs_de committed
146
?>