Completed
Push — master ( 4284f6...258d83 )
by
unknown
09:47
created

AccountController::viewAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\AccountBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
9
10
use Oro\Bundle\SecurityBundle\Annotation\Acl;
11
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
12
use Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager;
13
14
use OroCRM\Bundle\AccountBundle\Entity\Account;
15
use OroCRM\Bundle\ChannelBundle\Entity\Channel;
16
17
class AccountController extends Controller
18
{
19
    /**
20
     * @Route("/view/{id}", name="orocrm_account_view", requirements={"id"="\d+"})
21
     * @Acl(
22
     *      id="orocrm_account_view",
23
     *      type="entity",
24
     *      permission="VIEW",
25
     *      class="OroCRMAccountBundle:Account"
26
     * )
27
     * @Template()
28
     */
29
    public function viewAction(Account $account)
30
    {
31
        $channels = $this->getDoctrine()
32
            ->getRepository('OroCRMChannelBundle:Channel')
33
            ->findBy(['status' => Channel::STATUS_ACTIVE], ['channelType' => 'ASC', 'name' => 'ASC']);
34
35
        return array('entity' => $account, 'channels' => $channels);
36
    }
37
38
    /**
39
     * Create account form
40
     *
41
     * @Route("/create", name="orocrm_account_create")
42
     * @Acl(
43
     *      id="orocrm_account_create",
44
     *      type="entity",
45
     *      permission="CREATE",
46
     *      class="OroCRMAccountBundle:Account"
47
     * )
48
     * @Template("OroCRMAccountBundle:Account:update.html.twig")
49
     */
50
    public function createAction()
51
    {
52
        return $this->update();
53
    }
54
55
    /**
56
     * Edit user form
57
     *
58
     * @Route("/update/{id}", name="orocrm_account_update", requirements={"id"="\d+"})
59
     * @Acl(
60
     *      id="orocrm_account_update",
61
     *      type="entity",
62
     *      permission="EDIT",
63
     *      class="OroCRMAccountBundle:Account"
64
     * )
65
     * @Template()
66
     */
67
    public function updateAction(Account $entity)
68
    {
69
        return $this->update($entity);
70
    }
71
72
    /**
73
     * @Route(
74
     *      "/{_format}",
75
     *      name="orocrm_account_index",
76
     *      requirements={"_format"="html|json"},
77
     *      defaults={"_format" = "html"}
78
     * )
79
     * @AclAncestor("orocrm_account_view")
80
     * @Template
81
     */
82
    public function indexAction()
83
    {
84
        return [
85
            'entity_class' => $this->container->getParameter('orocrm_account.account.entity.class')
86
        ];
87
    }
88
89
    /**
90
     * @return ApiEntityManager
91
     */
92
    protected function getManager()
93
    {
94
        return $this->get('orocrm_account.account.manager.api');
95
    }
96
97
    /**
98
     * @param Account $entity
99
     * @return array
100
     */
101
    protected function update(Account $entity = null)
102
    {
103
        if (!$entity) {
104
            $entity = $this->getManager()->createEntity();
105
        }
106
107
        return $this->get('oro_form.model.update_handler')->update(
108
            $entity,
109
            $this->get('orocrm_account.form.account'),
110
            $this->get('translator')->trans('orocrm.account.controller.account.saved.message'),
111
            $this->get('orocrm_account.form.handler.account')
112
        );
113
    }
114
115
    /**
116
     * @Route(
117
     *      "/widget/contacts/{id}",
118
     *      name="orocrm_account_widget_contacts_info",
119
     *      requirements={"id"="\d+"},
120
     *      defaults={"id"=0}
121
     * )
122
     * @AclAncestor("orocrm_contact_view")
123
     * @Template()
124
     */
125
    public function contactsInfoAction(Account $account = null)
126
    {
127
        return [
128
            'account' => $account
129
        ];
130
    }
131
132
    /**
133
     * @Route("/widget/info/{id}", name="orocrm_account_widget_info", requirements={"id"="\d+"})
134
     * @AclAncestor("orocrm_account_view")
135
     * @Template()
136
     */
137
    public function infoAction(Account $account)
138
    {
139
        return [
140
            'account' => $account
141
        ];
142
    }
143
}
144