Completed
Push — develop ( 39d506...957668 )
by Abdelrahman
11:48
created

AttributesDataTable::getColumns()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 2
eloc 13
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Attributes\DataTables\Adminarea;
6
7
use Rinvex\Attributes\Models\Attribute;
8
use Cortex\Foundation\DataTables\AbstractDataTable;
9
10
class AttributesDataTable extends AbstractDataTable
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected $model = Attribute::class;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $builderParameters = [
21
        'drawCallback' => 'function (settings) {
22
            var lastGroup = null;
23
            var api = this.api();
24
            var colspan = api.columns(\':visible\').count();
25
            var rows = api.rows({page:\'current\'}).nodes();
26
27
            api.column(\'group:name\', {page:\'current\'} ).data().each(function (rowGroup, rowIndex) {
28
                if (lastGroup !== rowGroup) {
29
                    $(rows).eq(rowIndex).before(
30
                        \'<tr class="attribute-group"><td colspan="\'+colspan+\'"><strong>\'+(rowGroup ? rowGroup : "No Group")+\'</strong></td></tr>\'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 151 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
31
                    );
32
 
33
                    lastGroup = rowGroup;
34
                }
35
            });
36
        }',
37
    ];
38
39
    /**
40
     * Get the query object to be processed by dataTables.
41
     *
42
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Database\Que...tabase\Eloquent\Builder.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
43
     */
44
    public function query()
45
    {
46
        $locale = app()->getLocale();
47
        $query = app($this->model)->query()->orderBy('group', 'ASC')->orderBy('sort_order', 'ASC')->orderBy("name->\${$locale}", 'ASC');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
48
49
        return $this->applyScopes($query);
50
    }
51
52
    /**
53
     * Display ajax response.
54
     *
55
     * @return \Illuminate\Http\JsonResponse
56
     */
57
    public function ajax()
58
    {
59
        return datatables($this->query())
60
            ->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1')
61
            ->make(true);
62
    }
63
64
    /**
65
     * Get columns.
66
     *
67
     * @return array
68
     */
69
    protected function getColumns(): array
70
    {
71
        $link = config('cortex.foundation.route.locale_prefix')
72
            ? '"<a href=\""+routes.route(\'adminarea.attributes.edit\', {attribute: full.slug, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"'
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 158 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
73
            : '"<a href=\""+routes.route(\'adminarea.attributes.edit\', {attribute: full.slug})+"\">"+data+"</a>"';
74
75
        return [
76
            'name' => ['title' => trans('cortex/attributes::common.name'), 'render' => $link, 'responsivePriority' => 0],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
77
            'slug' => ['title' => trans('cortex/attributes::common.slug')],
78
            'type' => ['title' => trans('cortex/attributes::common.type'), 'render' => 'Lang.trans(\'cortex/attributes::common.\'+data)'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
79
            'group' => ['title' => trans('cortex/attributes::common.group'), 'visible' => false],
80
            'is_collection' => ['title' => trans('cortex/attributes::common.collection')],
81
            'is_required' => ['title' => trans('cortex/attributes::common.required')],
82
            'created_at' => ['title' => trans('cortex/attributes::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
83
            'updated_at' => ['title' => trans('cortex/attributes::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
84
        ];
85
    }
86
}
87