Passed
Push — master ( 6ef073...e381e3 )
by Julito
17:00
created

IndexController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 171
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A editWelcomeAction() 0 5 1
A indexAction() 0 60 2
A editInscriptionAction() 0 7 1
A toggleStudentViewAction() 0 14 4
A welcomeAction() 0 18 2
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Controller;
5
6
//use Chamilo\CoreBundle\Admin\CourseAdmin;
7
use Chamilo\CoreBundle\Entity\ExtraField;
8
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
9
use Chamilo\CoreBundle\Framework\PageController;
10
use Chamilo\PageBundle\Entity\Block;
11
use Chamilo\UserBundle\Entity\User;
12
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
13
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
15
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
16
use Sonata\PageBundle\Entity\PageManager;
17
use Sonata\PageBundle\Model\Page;
18
use Sylius\Component\Attribute\AttributeType\TextAttributeType;
19
use Sylius\Component\Attribute\Model\AttributeValueInterface;
20
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
21
use Symfony\Component\HttpFoundation\Request;
22
use Symfony\Component\HttpFoundation\Response;
23
24
/**
25
 * Class IndexController
26
 * author Julio Montoya <[email protected]>.
27
 *
28
 * @package Chamilo\CoreBundle\Controller
29
 */
30
class IndexController extends BaseController
31
{
32
    /**
33
     * The Chamilo index home page.
34
     *
35
     * @Route("/edit_welcome", name="edit_welcome")
36
     * @Method({"GET|POST"})
37
     * @Security("has_role('ROLE_ADMIN')")
38
     *
39
     * @return Response
40
     */
41
    public function editWelcomeAction()
42
    {
43
        return $this->forward(
44
            'Chamilo\PageBundle\Controller\PageController:createPage',
45
            array('pageSlug' => 'welcome')
46
        );
47
    }
48
49
    /**
50
     * The Chamilo index home page.
51
     *
52
     * @Route("/edit_inscription", name="edit_inscription")
53
     * @Method({"GET|POST"})
54
     * @Security("has_role('ROLE_ADMIN')")
55
     *
56
     * @return Response
57
     */
58
    public function editInscriptionAction()
59
    {
60
        $redirect = $this->generateUrl('legacy_main', ['name' => 'admin/configure_inscription.php']);
61
62
        return $this->forward(
63
            'Chamilo\PageBundle\Controller\PageController:createPage',
64
            array('pageSlug' => 'inscription', 'redirect' => $redirect)
65
        );
66
67
    }
68
69
    /**
70
     * The Chamilo index home page.
71
     *
72
     * @Route("/welcome", name="welcome")
73
     * @Method({"GET"})
74
     *
75
     * @return Response
76
     */
77
    public function welcomeAction()
78
    {
79
        $siteSelector = $this->get('sonata.page.site.selector');
80
        $site = $siteSelector->retrieve();
81
        $page = null;
82
        if ($site) {
83
            $pageManager = $this->get('sonata.page.manager.page');
84
            // Parents only of homepage
85
            $criteria = ['site' => $site, 'enabled' => true, 'parent' => 1, 'slug' => 'welcome'];
86
            /** @var Page $page */
87
            $page = $pageManager->findOneBy($criteria);
88
        }
89
90
        return $this->render(
91
            '@ChamiloCore/Index/welcome.html.twig',
92
            [
93
                'page' => $page,
94
                'content' => 'welcome',
95
            ]
96
        );
97
    }
98
99
    /**
100
     * The Chamilo index home page.
101
     *
102
     * @Route("/", name="home")
103
     * @Method({"GET", "POST"})
104
     *
105
     * @param string $type   courses|sessions|mycoursecategories
106
     * @param string $filter for the userportal courses page. Only works when setting 'history'
107
     * @param int    $page
108
     *
109
     * @return Response
110
     */
111
    public function indexAction(Request $request)
112
    {
113
        /** @var \PageController $pageController */
114
        //$pageController = $this->get('page_controller');
115
        $pageController = new PageController();
116
117
        //$sessionHandler = $request->getSession();
118
        //$sessionHandler->remove('coursesAlreadyVisited');
119
120
        $user = $this->getUser();
121
        $userId = 0;
122
        if ($user) {
123
            $userId = $this->getUser()->getId();
124
        }
125
        $announcementsBlock = $pageController->getAnnouncements($userId);
126
127
        /** @var User $user */
128
        //$userManager = $this->container->get('fos_user.user_manager');
129
        //$user = $userManager->find(1);
130
131
        //$attribute = $this->container->get('doctrine')->getRepository('ChamiloCoreBundle:ExtraField')->find(1);
132
        /*
133
                $attribute = new ExtraField();
134
                $attribute->setName('size');
135
                $attribute->setVariable('size');
136
                $attribute->setType(TextAttributeType::TYPE);
137
                $attribute->setStorageType(AttributeValueInterface::STORAGE_TEXT);
138
                $this->getDoctrine()->getManager()->persist($attribute);
139
                $this->getDoctrine()->getManager()->flush();
140
141
                $attributeColor = new ExtraField();
142
                $attributeColor->setName('color');
143
                $attributeColor->setVariable('color');
144
                $attributeColor->setType(TextAttributeType::TYPE);
145
                $attributeColor->setStorageType(AttributeValueInterface::STORAGE_TEXT);
146
                $this->getDoctrine()->getManager()->persist($attributeColor);
147
                $this->getDoctrine()->getManager()->flush();
148
149
                $color = new ExtraFieldValues();
150
                $color->setComment('lol');
151
                $color->setAttribute($attributeColor);
152
                $color->setValue('blue');
153
154
                $user->addAttribute($color);
155
156
                $smallSize = new ExtraFieldValues();
157
                $smallSize->setComment('lol');
158
                $smallSize->setAttribute($attribute);
159
                $smallSize->setValue('S');
160
161
                $user->addAttribute($smallSize);
162
                $userManager->updateUser($user);
163
        */
164
        //$this->get('session')->remove('id_session');
165
166
        return $this->render(
167
            '@ChamiloCore/Index/index.html.twig',
168
            [
169
                'content' => '',
170
                'announcements_block' => $announcementsBlock,
171
                //'home_page_block' => $pageController->returnHomePage()
172
            ]
173
        );
174
    }
175
176
    /**
177
     * Toggle the student view action.
178
     *
179
     * @Route("/toggle_student_view")
180
     * @Security("has_role('ROLE_TEACHER')")
181
     * @Method({"GET"})
182
     *
183
     * @param Request $request
184
     *
185
     * @return Response
186
     */
187
    public function toggleStudentViewAction(Request $request)
188
    {
189
        if (!api_is_allowed_to_edit(false, false, false, false)) {
190
            return '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the documented return type Symfony\Component\HttpFoundation\Response.
Loading history...
191
        }
192
        $studentView = $request->getSession()->get('studentview');
193
        if (empty($studentView) || $studentView == 'studentview') {
194
            $request->getSession()->set('studentview', 'teacherview');
195
196
            return 'teacherview';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'teacherview' returns the type string which is incompatible with the documented return type Symfony\Component\HttpFoundation\Response.
Loading history...
197
        } else {
198
            $request->getSession()->set('studentview', 'studentview');
199
200
            return 'studentview';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'studentview' returns the type string which is incompatible with the documented return type Symfony\Component\HttpFoundation\Response.
Loading history...
201
        }
202
    }
203
}
204