Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Move | |
0.00% |
0 / 47 |
|
0.00% |
0 / 6 |
110 | |
0.00% |
0 / 1 |
| dependency | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| resolve | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| resolve_category | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| resolve_sub_categories_lv1 | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| resolve_sub_categories_lv2 | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getData | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Helpers\ChangeManagement\ShortcutCategory; |
| 4 | |
| 5 | use App\Http\Helpers\ChangeManagement\ChangeManagement; |
| 6 | use App\Http\Models\Shortcut; |
| 7 | use App\Http\Models\ShortcutSubCategoryLv1; |
| 8 | use App\Http\Models\ShortcutSubCategoryLv2; |
| 9 | |
| 10 | class Move extends ChangeManagement |
| 11 | { |
| 12 | public function dependency($id) |
| 13 | { |
| 14 | $shortcuts = Shortcut::where('category_id', $id)->count(); |
| 15 | |
| 16 | $hasDependency = false; |
| 17 | |
| 18 | if ($shortcuts > 0) { |
| 19 | $hasDependency = true; |
| 20 | } |
| 21 | |
| 22 | return [ |
| 23 | 'has_dependency' => $hasDependency, |
| 24 | 'dependency' => [ |
| 25 | 'shortcuts' => $shortcuts, |
| 26 | ], |
| 27 | ]; |
| 28 | } |
| 29 | |
| 30 | public function resolve($id) |
| 31 | { |
| 32 | Shortcut::where('category_id', $id)->update([ |
| 33 | 'category_id' => $this->categoryId, |
| 34 | 'sub_categories_lv1_id' => null, |
| 35 | 'sub_categories_lv2_id' => null, |
| 36 | ]); |
| 37 | |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | public function resolve_category($id) |
| 42 | { |
| 43 | $move_to_category_type = $this->move_to_category_type; |
| 44 | |
| 45 | $data = $this->getData($move_to_category_type); |
| 46 | |
| 47 | Shortcut::where('category_id', $id)->update($data); |
| 48 | } |
| 49 | |
| 50 | public function resolve_sub_categories_lv1($id) |
| 51 | { |
| 52 | $move_to_category_type = $this->move_to_category_type; |
| 53 | |
| 54 | Shortcut::where('sub_categories_lv1_id', $id)->update([ |
| 55 | 'category_id' => $this->categoryId, |
| 56 | 'sub_categories_lv1_id' => null, |
| 57 | 'sub_categories_lv2_id' => null, |
| 58 | ]); |
| 59 | } |
| 60 | |
| 61 | public function resolve_sub_categories_lv2($id) |
| 62 | { |
| 63 | $move_to_category_type = $this->move_to_category_type; |
| 64 | |
| 65 | Shortcut::where('sub_categories_lv2_id', $id)->update([ |
| 66 | 'category_id' => $this->categoryId, |
| 67 | 'sub_categories_lv1_id' => null, |
| 68 | 'sub_categories_lv2_id' => null, |
| 69 | ]); |
| 70 | } |
| 71 | |
| 72 | protected function getData($move_to_category_type) |
| 73 | { |
| 74 | $data = []; |
| 75 | |
| 76 | if ($move_to_category_type == 'category') { |
| 77 | $data['category_id'] = $this->categoryId; |
| 78 | $data['sub_categories_lv1_id'] = null; |
| 79 | $data['sub_categories_lv2_id'] = null; |
| 80 | } elseif ($move_to_category_type == 'sub_categories_lv1') { |
| 81 | $sub_categories_lv1_data = ShortcutSubCategoryLv1::find($this->categoryId); |
| 82 | $data['category_id'] = $sub_categories_lv1_data->category_id; |
| 83 | $data['sub_categories_lv1_id'] = $sub_categories_lv1_data->id; |
| 84 | $data['sub_categories_lv2_id'] = null; |
| 85 | } elseif ($move_to_category_type == 'sub_categories_lv2') { |
| 86 | $sub_categories_lv2_data = ShortcutSubCategoryLv2::with('subCategoryLv1')->find($this->categoryId); |
| 87 | $data['category_id'] = $sub_categories_lv2_data->subCategoryLv1->category_id; |
| 88 | $data['sub_categories_lv1_id'] = $sub_categories_lv2_data->subCategoryLv1->id; |
| 89 | $data['sub_categories_lv2_id'] = $sub_categories_lv2_data->id; |
| 90 | } |
| 91 | |
| 92 | return $data; |
| 93 | } |
| 94 | } |