Completed
Push — development ( 895d6a...1f768f )
by Ashutosh
08:56
created

ExtendedBaseProductController::editProductUpload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Product;
4
5
use App\Http\Controllers\Controller;
6
use App\Model\Common\StatusSetting;
7
use App\Model\Payment\TaxProductRelation;
8
use App\Model\Product\Product;
9
use App\Model\Product\ProductUpload;
10
use GrahamCampbell\Markdown\Facades\Markdown;
11
use Bugsnag;
12
use Illuminate\Http\Request;
13
14
class ExtendedBaseProductController extends Controller
15
{
16
    public function getUpload($id)
17
    {
18
        $new_upload = ProductUpload::where('product_id', '=', $id)
19
        ->select('id', 'product_id', 'title', 'description', 'version', 'file')
20
        ->get();
21
22
        return \DataTables::of($new_upload)
23
        ->addColumn('checkbox', function ($model) {
24
            return "<input type='checkbox' class='upload_checkbox' value=".$model->id.' name=select[] id=checks>';
25
        })
26
27
        ->addColumn('product_id', function ($model) {
28
            return ucfirst($this->product->where('id', $model->product_id)->first()->name);
29
        })
30
31
        ->addColumn('title', function ($model) {
32
            return ucfirst($model->title);
33
        })
34
        ->addColumn('description', function ($model) {
35
            return ucfirst($model->description);
36
        })
37
        ->addColumn('version', function ($model) {
38
            return $model->version;
39
        })
40
41
        ->addColumn('file', function ($model) {
42
            return $model->file;
43
        })
44
        ->addColumn('action', function ($model) {
45
              return '<p><a href='.url('edit-upload/'.$model->id).
46
                                " class='btn btn-sm btn-primary btn-xs'><i class='fa fa-edit'
47
                                 style='color:white;'> </i>&nbsp;&nbsp;Edit</a>&nbsp</p>";
48
        })
49
        ->rawcolumns(['checkbox', 'product_id', 'title', 'description', 'version', 'file', 'action'])
50
        ->make(true);
51
    }
52
53
   /**
54
    * Go to edit Product Upload Page
55
    *
56
    * @date   2019-03-07T13:15:58+0530
57
    *
58
    * @param  int $id   Product Upload id 
59
    *
60
    */
61
    public function editProductUpload($id) 
62
    {
63
        $model = ProductUpload::where('id',$id)->first();
64
        $selectedProduct = $model->product->name;
65
        return view('themes.default1.product.product.edit-upload-option',compact('model','selectedProduct'));
66
    }
67
68
    //Update the File Info
69
    public function uploadUpdate($id, Request $request)
70
    {
71
        $this->validate($request, [
72
        'title' => 'required',
73
        'version'      => 'required',
74
        ]);
75
76
        try {
77
            $file_upload = ProductUpload::find($id);
78
            $file_upload->where('id', $id)->update(['title'=>$request->input('title'), 'description'=>$request->input('description'), 'version'=> $request->input('version')]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 175 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
            $autoUpdateStatus = StatusSetting::pluck('update_settings')->first();
80
            if ($autoUpdateStatus == 1) { //If License Setting Status is on,Add Product to the AutoUpdate Script
81
                $productSku = $file_upload->product->product_sku;
82
                $updateClassObj = new \App\Http\Controllers\AutoUpdate\AutoUpdateController();
83
                $addProductToAutoUpdate = $updateClassObj->editVersion($request->input('version'), $productSku);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $addProductToAutoUpdate is correct as $updateClassObj->editVer...version'), $productSku) targeting App\Http\Controllers\Aut...ntroller::editVersion() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
84
            }
85
            return redirect()->back()->with('success','Product Updated Successfully');
86
        } catch (\Exception $ex) {
87
            app('log')->error($e->getMessage());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $e seems to be never defined.
Loading history...
88
            Bugsnag::notifyException($e);
89
            $message = [$e->getMessage()];
90
            $response = ['success'=>'false', 'message'=>$message];
91
92
            return response()->json(compact('response'), 500);
93
        }
94
    }
95
96
    public function saveTax($taxes, $product_id)
97
    {
98
        if ($taxes) {
99
            TaxProductRelation::where('product_id', $product_id)->delete();
100
            foreach ($taxes as $tax) {
101
                $newTax = new TaxProductRelation();
102
                $newTax->product_id = $product_id;
103
                $newTax->tax_class_id = $tax;
104
                $newTax->save();
105
            }
106
        }
107
    }
108
109
    /**
110
     * Whether the Product Requires the domain to be entered.
111
     *
112
     * @param int $productid
113
     */
114
    public function getProductField(int $productid)
115
    {
116
        try {
117
            $field = '';
118
            $product = Product::find($productid);
119
            if ($product->require_domain == 1) {
120
                $field .= "<div class='col-md-4 form-group'>
121
                        <label class='required'>"./* @scrutinizer ignore-type */
122
                         \Lang::get('message.domain')."</label>
123
                        <input type='text' name='domain' class='form-control' 
124
                        id='domain' placeholder='http://example.com'>
125
                </div>";
126
            }
127
128
            return $field;
129
        } catch (\Exception $ex) {
130
            Bugsnag::notifyException($ex);
131
132
            return $ex->getMessage();
133
        }
134
    }
135
136
    public function adminDownload($id, $invoice = '', $api = false)
137
    {
138
        try {
139
            // $release = $this->getLinkToDownload($role, $invoice, $id);
140
            $release = $this->downloadProductAdmin($id);
141
            $name = Product::where('id', $id)->value('name');
142
            if (is_array($release) && array_key_exists('type', $release)) {
143
                header('Location: '.$release['release']);
144
                exit;
145
            } else {
146
                header('Content-type: Zip');
147
                header('Content-Description: File Transfer');
148
                header('Content-Disposition: attachment; filename = '.$name.'.zip');
149
                header('Content-Length: '.filesize($release));
150
                readfile($release);
151
                ob_end_clean();
152
              
153
            }
154
        } catch (\Exception $e) {
155
            if ($api) {
156
                return response()->json(['error'=>$e->getMessage()]);
157
            }
158
            Bugsnag::notifyException($e);
159
160
            return redirect()->back()->with('fails', $e->getMessage());
161
        }
162
    }
163
164
    /**
165
     * Save Values Related to Cart(eg: whether show Agents or Quantity in Cart etc).
166
     *
167
     * @author Ashutosh Pathak <[email protected]>
168
     *
169
     * @date   2019-01-07T14:34:54+0530
170
     *
171
     * @param Illuminate\Http\Request $input               All the Product Detais Sent from  the form
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Pro...Illuminate\Http\Request was not found. Did you mean Illuminate\Http\Request? If so, make sure to prefix the type with \.
Loading history...
172
     * @param bool                    $can_modify_agent    Whether Agents can be modified by customer
173
     * @param bool                    $can_modify_quantity Whether Product Quantity can be modified by Customers
174
     *
175
     * @return
176
     */
177
    public function saveCartValues($input, bool $can_modify_agent, bool $can_modify_quantity)
178
    {
179
        $this->product->show_agent = $input['show_agent'] == 1 ? 1 : 0; //if Show Agents Selected
180
        $this->product->can_modify_agent = $can_modify_agent;
181
        $this->product->can_modify_quantity = $can_modify_quantity;
182
        $this->product->save();
183
    }
184
185
    /**
186
     * Save Values Related to Cart while Updating Produc(eg: whether show Agents or Quantityof Product in Cart etc).
187
     *
188
     * @author Ashutosh Pathak <[email protected]>
189
     *
190
     * @date   2019-01-07T20:40:20+0530
191
     *
192
     *@param  Illuminate\Http\Request     $input      All the Product Detais Sent from  the form
193
     * @param Illuminate\Http\Request; $request
194
     * @param array                    $product instance of the Product
195
     *
196
     * @return Save The Details
197
     */
198
    public function saveCartDetailsWhileUpdating($input, $request, $product)
199
    {
200
        $product->show_agent = $input['show_agent'] == 1 ? 1 : 0; //if Show Agents Selected
201
        if ($product->show_agent == 1) {
202
            $product->can_modify_quantity = 0;
203
            if ($request->has('can_modify_agent')) {
204
                $product->can_modify_agent = 1;
205
            } else {
206
                $product->can_modify_agent = 0;
207
                $product->can_modify_quantity = 0;
208
            }
209
        } else {
210
            $product->can_modify_agent = 0;
211
            if ($request->has('can_modify_quantity')) {
212
                $product->can_modify_quantity = 1;
213
            } else {
214
                $product->can_modify_agent = 0;
215
                $product->can_modify_quantity = 0;
216
            }
217
        }
218
219
        $product->save();
220
    }
221
}
222