Test Failed
Push — master ( 1129de...bac6db )
by Gianluca
06:48
created
src/Libraries/Template.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@  discard block
 block discarded – undo
15 15
 
16 16
 class Template
17 17
 {
18
-    public static function getStructureCategories(){
18
+    public static function getStructureCategories() {
19 19
 
20 20
         $categories = Category::with('children')->whereNull('parent_id')->get();
21 21
         $tree = [];
22
-        foreach($categories as $category){
22
+        foreach ($categories as $category) {
23 23
             $tree[] = [
24 24
                 'id' => $category->id,
25 25
                 'text' => $category->name,
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
         return $tree;
31 31
     }
32 32
 
33
-    private static function recursiveChildren($childrens){
33
+    private static function recursiveChildren($childrens) {
34 34
         $childs = [];
35
-        foreach ($childrens as $children){
35
+        foreach ($childrens as $children) {
36 36
             $childs[] = [
37 37
                 'id' => $children->id,
38 38
                 'text' => $children->name,
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
     }
45 45
 
46 46
     public static function  getCategoryTree($parent_id = null, $spacing = '', $tree_array = array()) {
47
-        $categories = Category::select('id', 'name', 'parent_id')->where('parent_id' ,'=', $parent_id)->orderBy('parent_id')->get();
48
-        foreach ($categories as $item){
49
-            $tree_array[] = ['id' => $item->id, 'name' =>$spacing . $item->name] ;
50
-            $tree_array = self::getCategoryTree($item->id, $spacing . '- ', $tree_array);
47
+        $categories = Category::select('id', 'name', 'parent_id')->where('parent_id', '=', $parent_id)->orderBy('parent_id')->get();
48
+        foreach ($categories as $item) {
49
+            $tree_array[] = ['id' => $item->id, 'name' =>$spacing.$item->name];
50
+            $tree_array = self::getCategoryTree($item->id, $spacing.'- ', $tree_array);
51 51
         }
52 52
         return $tree_array;
53 53
     }
@@ -56,34 +56,34 @@  discard block
 block discarded – undo
56 56
      * @param Int $id
57 57
      * @return Product
58 58
      */
59
-    public static function getProducts($id = null){
60
-        if($id === null){
59
+    public static function getProducts($id = null) {
60
+        if ($id === null) {
61 61
             $products = Product::all();
62
-        }else{
63
-            $products = Category::where('id',$id)->orWhere('parent_id',$id)->first()->products;
62
+        } else {
63
+            $products = Category::where('id', $id)->orWhere('parent_id', $id)->first()->products;
64 64
         }
65 65
         return $products;
66 66
     }
67 67
 
68
-    public static function getDetailsFields(Product $product,$product_item_id){
68
+    public static function getDetailsFields(Product $product, $product_item_id) {
69 69
         $element = '<div class="row col">';
70 70
 
71
-        foreach($product->details->groupBy('product_detail_id') as $key => $details){
71
+        foreach ($product->details->groupBy('product_detail_id') as $key => $details) {
72 72
 
73
-            $element.= self::generateDetailHtml(Detail::find($key),$details->groupBy('product_detail_value_id'),$product->id,$product_item_id);
73
+            $element .= self::generateDetailHtml(Detail::find($key), $details->groupBy('product_detail_value_id'), $product->id, $product_item_id);
74 74
         }
75
-        $element.= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>';
75
+        $element .= '<p class="show_error_product" style="color: red; display: none;">Prodotto non disponibile</p>';
76 76
         $element .= '</div>';
77 77
         return $element;
78 78
     }
79 79
 
80
-    public static function generateHtmlField($type,$value,$label){
81
-        if($type !== 'textarea'){
80
+    public static function generateHtmlField($type, $value, $label) {
81
+        if ($type !== 'textarea') {
82 82
             $html = '';
83 83
             $html .= "<label>{$label}</label>";
84 84
             $html .= "<input disabled class='form-control' type='{$type}' value='{$value}'>";
85 85
             return $html;
86
-        }else{
86
+        } else {
87 87
             $html = '';
88 88
             $html .= "<label>{$label}</label>";
89 89
             $html .= "<textarea disabled class='form-control'>{$value}</textarea>";
@@ -91,40 +91,40 @@  discard block
 block discarded – undo
91 91
         }
92 92
     }
93 93
 
94
-    public static function getConfigurationFields($product_item_id){
95
-        $configurationFields = ProductConfigurationField::where('product_item_id',$product_item_id)->get();
94
+    public static function getConfigurationFields($product_item_id) {
95
+        $configurationFields = ProductConfigurationField::where('product_item_id', $product_item_id)->get();
96 96
         $element = '<div class="col row">';
97
-        foreach ($configurationFields as $field){
98
-                $element .= self::generateHtmlField($field->field->type,$field->value,$field->field->name);
97
+        foreach ($configurationFields as $field) {
98
+                $element .= self::generateHtmlField($field->field->type, $field->value, $field->field->name);
99 99
 
100 100
             }
101 101
             $element .= '</div>';
102 102
         return $element;
103 103
     }
104 104
 
105
-    public static function buttonCart($product_item_id){
105
+    public static function buttonCart($product_item_id) {
106 106
         return "<button onclick='addToCart(this)' data-product_item_id='{$product_item_id}' class='btn btn-primary mt-3'>Salva nel carrello</button>";
107 107
     }
108 108
 
109
-    public static function generateDetailHtml($detail,$values,$product_id,$product_item_id){
109
+    public static function generateDetailHtml($detail, $values, $product_id, $product_item_id) {
110 110
 
111 111
         $type = $detail->type;
112 112
         $html = '';
113
-        if($type === 'select'){
113
+        if ($type === 'select') {
114 114
             $html = '<label>'.$detail->name.'</label>';
115
-            $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id .'" class="form-control mongifield_into_product">';
115
+            $html .= '<select onchange="getVariationProduct()" data-product_id="'.$product_id.'" data-detail_id="'.$detail->id.'" class="form-control mongifield_into_product">';
116 116
             $selected = '';
117 117
 
118
-            $details = ProductItemDetail::where('product_item_id',$product_item_id)->get();
118
+            $details = ProductItemDetail::where('product_item_id', $product_item_id)->get();
119 119
             $filter = [];
120
-            foreach ($details as $_detail){
120
+            foreach ($details as $_detail) {
121 121
                 $filter[$_detail->product_detail_id] = $_detail->product_detail_value_id;
122 122
             }
123
-            foreach ($values as $detail_value_id =>$value){
124
-                if(isset($filter[$detail->id])){
125
-                    if($filter[$detail->id] == $detail_value_id){
123
+            foreach ($values as $detail_value_id =>$value) {
124
+                if (isset($filter[$detail->id])) {
125
+                    if ($filter[$detail->id] == $detail_value_id) {
126 126
                         $selected = 'selected';
127
-                    }else{
127
+                    } else {
128 128
                         $selected = '';
129 129
                     }
130 130
                 }
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
         return $html;
138 138
     }
139 139
 
140
-    public static function MoveSessionToCart($user_id){
140
+    public static function MoveSessionToCart($user_id) {
141 141
         $user = User::find($user_id);
142 142
         $elements_in_cart = session('cart');
143
-        if(!empty($elements_in_cart)){
144
-            if(Cart::where('user_id',$user->id)->count() <= 0){
145
-                foreach($elements_in_cart as $product_id => $count){
143
+        if (!empty($elements_in_cart)) {
144
+            if (Cart::where('user_id', $user->id)->count() <= 0) {
145
+                foreach ($elements_in_cart as $product_id => $count) {
146 146
                     $cart = new Cart();
147 147
                     $cart->user_id = $user->id;
148 148
                     $cart->product_item_id = $product_id;
Please login to merge, or discard this patch.