Passed
Push — main ( 03ed8c...5e2119 )
by PRATIK
05:01 queued 11s
created

BlockVc   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A updatedActiveblocks() 0 22 5
A render() 0 5 1
A updateBlockOrder() 0 6 2
A mount() 0 12 4
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Block;
4
5
use Adminetic\Website\Models\Admin\Block;
6
use Illuminate\Support\Facades\Cache;
7
use Livewire\Component;
0 ignored issues
show
Bug introduced by
The type Livewire\Component was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class BlockVc extends Component
10
{
11
    public $activeblocks = [];
12
13
    public function mount()
14
    {
15
        $activeblocks = [];
16
        $block_groups = Block::where('active', 1)->get()->groupBy(['theme', 'type']);
17
        foreach ($block_groups as $theme => $types) {
18
            foreach ($types as $type => $blocks) {
19
                foreach ($blocks as $block) {
20
                    $activeblocks[$theme][$type] = $block->id;
21
                }
22
            }
23
        }
24
        $this->activeblocks = $activeblocks;
25
    }
26
27
    public function updateBlockOrder($lists)
28
    {
29
        foreach ($lists as $list) {
30
            Block::find($list['value'])->update(['position' => $list['order']]);
31
        }
32
        $this->emit('reorderingComplete');
33
    }
34
35
    public function updatedActiveblocks()
36
    {
37
        $block_ids = array();
38
        foreach ($this->activeblocks as $types) {
39
            foreach ($types as $type => $block_id) {
40
                $block_ids[] = $block_id;
41
            }
42
        }
43
44
        if (isset($block_ids)) {
45
            foreach ($block_ids as $block_id) {
46
                $block = Block::find($block_id);
47
                $block->update(['active' => 1]);
48
                $blocks = Block::where([
49
                    ['id', '<>', $block->id],
50
                    ['type', '=', $block->type],
51
                    ['theme', '=', $block->theme],
52
                ])->pluck('id')->toArray();
53
54
                Block::whereIn('id', $blocks)->update(['active' => 0]);
55
            }
56
            $this->emit('blockVcComplete');
57
        }
58
    }
59
60
    public function render()
61
    {
62
        $blocks = Block::all()->groupBy(['theme', 'type']);
63
64
        return view('website::livewire.admin.block.block-vc', compact('blocks'));
65
    }
66
}
67