Passed
Push — master ( aada92...32790d )
by Julito
13:34
created

IndexController::editWelcomeAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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("/", name="home")
36
     * @Method({"GET", "POST"})
37
     *
38
     * @param string $type   courses|sessions|mycoursecategories
39
     * @param string $filter for the userportal courses page. Only works when setting 'history'
40
     * @param int    $page
41
     *
42
     * @return Response
43
     */
44
    public function indexAction(Request $request): Response
45
    {
46
        /** @var \PageController $pageController */
47
        //$pageController = $this->get('page_controller');
48
        $pageController = new PageController();
49
50
        //$sessionHandler = $request->getSession();
51
        //$sessionHandler->remove('coursesAlreadyVisited');
52
53
        $user = $this->getUser();
54
        $userId = 0;
55
        if ($user) {
56
            $userId = $this->getUser()->getId();
57
        }
58
        $announcementsBlock = $pageController->getAnnouncements($userId);
59
60
        /** @var User $user */
61
        //$userManager = $this->container->get('fos_user.user_manager');
62
        //$user = $userManager->find(1);
63
64
        //$attribute = $this->container->get('doctrine')->getRepository('ChamiloCoreBundle:ExtraField')->find(1);
65
        /*
66
                $attribute = new ExtraField();
67
                $attribute->setName('size');
68
                $attribute->setVariable('size');
69
                $attribute->setType(TextAttributeType::TYPE);
70
                $attribute->setStorageType(AttributeValueInterface::STORAGE_TEXT);
71
                $this->getDoctrine()->getManager()->persist($attribute);
72
                $this->getDoctrine()->getManager()->flush();
73
74
                $attributeColor = new ExtraField();
75
                $attributeColor->setName('color');
76
                $attributeColor->setVariable('color');
77
                $attributeColor->setType(TextAttributeType::TYPE);
78
                $attributeColor->setStorageType(AttributeValueInterface::STORAGE_TEXT);
79
                $this->getDoctrine()->getManager()->persist($attributeColor);
80
                $this->getDoctrine()->getManager()->flush();
81
82
                $color = new ExtraFieldValues();
83
                $color->setComment('lol');
84
                $color->setAttribute($attributeColor);
85
                $color->setValue('blue');
86
87
                $user->addAttribute($color);
88
89
                $smallSize = new ExtraFieldValues();
90
                $smallSize->setComment('lol');
91
                $smallSize->setAttribute($attribute);
92
                $smallSize->setValue('S');
93
94
                $user->addAttribute($smallSize);
95
                $userManager->updateUser($user);
96
        */
97
        //$this->get('session')->remove('id_session');
98
99
        return $this->render(
100
            '@ChamiloCore/Index/index.html.twig',
101
            [
102
                'content' => '',
103
                'announcements_block' => $announcementsBlock,
104
                //'home_page_block' => $pageController->returnHomePage()
105
            ]
106
        );
107
    }
108
109
    /**
110
     * Toggle the student view action.
111
     *
112
     * @Route("/toggle_student_view")
113
     * @Security("has_role('ROLE_TEACHER')")
114
     * @Method({"GET"})
115
     *
116
     * @param Request $request
117
     *
118
     * @return Response
119
     */
120
    public function toggleStudentViewAction(Request $request): Response
121
    {
122
        if (!api_is_allowed_to_edit(false, false, false, false)) {
123
            return '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
124
        }
125
        $studentView = $request->getSession()->get('studentview');
126
        if (empty($studentView) || $studentView === 'studentview') {
127
            $request->getSession()->set('studentview', 'teacherview');
128
129
            return 'teacherview';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'teacherview' returns the type string which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
130
        } else {
131
            $request->getSession()->set('studentview', 'studentview');
132
133
            return 'studentview';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'studentview' returns the type string which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
134
        }
135
    }
136
}
137