XdccController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Xdaysaysay\AdminBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Xdaysaysay\AdminBundle\FormTrait\FormTrait;
9
use Xdaysaysay\CoreBundle\Entity\Xdcc;
10
11
/**
12
 * Class XdccController
13
 * @package Xdaysaysay\AdminBundle\Controller
14
 */
15
class XdccController extends Controller
16
{
17
    use FormTrait;
18
19
    /**
20
     * XdccController constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->entityClassName = 'Xdaysaysay\CoreBundle\Entity\Xdcc';
25
        $this->repositoryName = 'XdaysaysayCoreBundle:Xdcc';
26
        $this->twigFormDirectory = 'XdaysaysayAdminBundle:Xdcc';
27
        $this->formRoute = 'xdcc';
28
        $this->translation = 'xdcc';
29
        $this->formType = 'Xdaysaysay\AdminBundle\Form\Type\XdccType';
30
    }
31
32
33
    /**
34
     * @param Request $request
35
     *
36
     * @return \Symfony\Component\HttpFoundation\JsonResponse
37
     */
38
    public function datatableDataAction(Request $request)
39
    {
40
        $params = $request->query->all();
41
42
        $draw = $params['draw'];
43
        $limit = $params['length'];
44
        $offset = $params['start'];
45
        $orderBy = [$params['columns'][$params['order'][0]['column']]['name'], $params['order'][0]['dir']];
46
        $criteria = explode(' ', $params['search']['value']);
47
48
        $columnSearch = [];
49
        foreach ($params['columns'] as $column) {
50
            if (!empty($column['search']['value'])) {
51
                $columnSearch[$column['name']] = $column['search'];
52
            }
53
        }
54
55
        $em = $this->getDoctrine()->getManager();
56
57
        $items = $em->getRepository('XdaysaysayCoreBundle:Xdcc')->findLike($criteria, $orderBy, $limit, $offset, false, $columnSearch);
58
59
        $datas = [];
60
        $translator = $this->get('translator');
61
        foreach ($items as $item) {
62
            $teams = $item->getTeams();
63
            $teamFinalNames = [];
64
            foreach($teams as $team) {
65
                $teamFinalNames[] = $team->getName();
66
            }
67
68
            $xdccNames = $item->getXdccnames();
69
            $xdccFinalNames = [];
70
            foreach($xdccNames as $xdccName) {
71
                $xdccFinalNames[] = $xdccName->getName();
72
            }
73
74
            $datas[] = [
75
                $item->getId(),
76
                implode('<br>', $teamFinalNames),
77
                $item->getServer()->getName(),
78
                implode('<br>', $xdccFinalNames),
79
                count($item->getPacks()),
80
                $item->getVisible() ? $translator->trans('admin.common.yes', [], 'admin') : $translator->trans('admin.common.no', [], 'admin'),
81
                '<a href="'.$this->generateUrl('xdaysaysay_admin_xdcc_edit', ['id' => $item->getId()]).'" class="btn btn-primary">'.$translator->trans('admin.common.action.edit', [], 'admin').'</a>
82
                 <a href="'.$this->generateUrl('xdaysaysay_admin_xdcc_delete_confirm', ['id' => $item->getId()]).'" class="btn btn-danger">'.$translator->trans('admin.common.action.delete', [], 'admin').'</a>',
83
            ];
84
        }
85
86
        $totalFiltered = $em->getRepository('XdaysaysayCoreBundle:Xdcc')->findLike($criteria, $orderBy, $limit, $offset, true, $columnSearch);
87
88
        $total = $em->getRepository('XdaysaysayCoreBundle:Xdcc')->countAll();
89
90
        return new JsonResponse(['data' => $datas, "draw" => $draw, "recordsTotal" => $total, "recordsFiltered" => $totalFiltered]);
91
    }
92
}