AdminConfigurationFieldController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 31
c 1
b 0
f 0
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigurationFields() 0 12 2
A generateConfigurationFieldHtml() 0 10 2
A setNewConfiguration() 0 19 1
1
<?php
2
3
4
namespace Mongi\Mongicommerce\Http\Controllers\admin;
5
6
7
use Illuminate\Http\Request;
8
use Mongi\Mongicommerce\Http\Controllers\Controller;
9
use Mongi\Mongicommerce\Models\ConfigurationField;
10
use Mongi\Mongicommerce\Models\ConfigurationFieldValue;
0 ignored issues
show
Bug introduced by
The type Mongi\Mongicommerce\Models\ConfigurationFieldValue 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...
11
use Mongi\Mongicommerce\Models\Detail;
12
13
class AdminConfigurationFieldController extends Controller
14
{
15
    public function setNewConfiguration(Request $r){
16
17
        $r->validate([
18
            'name' => 'required',
19
            'type' => 'required',
20
            'category' => 'required'
21
        ]);
22
23
        $name = $r->get('name');
24
        $type = $r->get('type');
25
        $category_id = $r->get('category');
26
27
        $configuration = new ConfigurationField();
28
        $configuration->category_id = $category_id;
29
        $configuration->type = $type;
30
        $configuration->name = $name;
31
        $configuration->save();
32
33
        return response()->json(true);
34
    }
35
36
    public function getConfigurationFields(Request $r){
37
        $category_id = $r->get('category_id');
38
        $configurationFields = ConfigurationField::where('category_id',$category_id)->get();
39
        $d = [];
40
        foreach ($configurationFields as $field){
41
            $d[] = [
42
                'name' => $field->name,
43
                'type' => $field->type,
44
                'html' => $this->generateConfigurationFieldHtml($field)
45
            ];
46
        }
47
        return response()->json($d);
48
49
    }
50
51
    public function generateConfigurationFieldHtml($field){
52
        $type = $field->type;
53
        $html = '';
54
        if($type === 'textarea'){
55
            $html = '';
56
            $html .= '<textarea data-configuration_id="'.$field->id .'" class="form-control mongiconfigurationfield"></textarea>';
57
        }else{
58
            $html .= '<input type="'.$type.'" data-configuration_id="'.$field->id .'" class="form-control mongiconfigurationfield">';
59
        }
60
        return $html;
61
    }
62
}
63