Completed
Push — development ( 3e307e...0dc251 )
by Ashutosh
11:44
created

ExtendedBaseProductController::getUpload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 36
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\Product;
4
5
use Illuminate\Http\Request;
6
use App\Model\Product\Product;
7
use App\Model\Product\ProductUpload;
8
use App\Http\Controllers\Controller;
9
use App\Model\Payment\TaxProductRelation;
10
11
class ExtendedBaseProductController extends Controller
12
{
13
14
    public function getUpload($id)
15
    {
16
        $new_upload = ProductUpload::where('product_id', '=', $id)
17
        ->select('id', 'product_id', 'title', 'description', 'version', 'file')
18
        ->get();
19
20
        return \DataTables::of($new_upload)
21
    ->addColumn('checkbox', function ($model) {
22
        return "<input type='checkbox' class='upload_checkbox' value=".$model->id.' name=select[] id=checks>';
23
    })
24
25
    ->addColumn('product_id', function ($model) {
26
        return ucfirst($this->product->where('id', $model->product_id)->first()->name);
27
    })
28
29
    ->addColumn('title', function ($model) {
30
        return ucfirst($model->title);
31
    })
32
    ->addColumn('description', function ($model) {
33
        return ucfirst($model->description);
34
    })
35
    ->addColumn('version', function ($model) {
36
        return $model->version;
37
    })
38
39
    ->addColumn('file', function ($model) {
40
        return $model->file;
41
    })
42
    ->addColumn('action', function ($model) {
43
        return '<a href='.('#edit-upload-option/'.$model->id).' 
44
         class=" btn btn-sm btn-primary " data-title="'.$model->title.'"
45
          data-description="'.$model->description.'" data-version="'
46
          .$model->version.'" data-id="'.$model->id.'" onclick="openEditPopup(this)" >Edit</a>';
47
    })
48
    ->rawcolumns(['checkbox', 'product_id', 'title', 'description', 'version', 'file', 'action'])
49
    ->make(true);
50
    }
51
52
     //Update the File Info
53
    public function uploadUpdate($id, Request $request)
54
    {
55
        $file_upload = ProductUpload::find($id);
56
57
        $file_upload->title = $request->input('title');
58
        $file_upload->description = $request->input('description');
59
        $file_upload->version = $request->input('version');
60
        if ($request->file) {
61
            $file = $request->file('file')->getClientOriginalName();
62
63
            $destination = storage_path().'/products';
64
            $request->file('file')->move($destination, $file);
65
            $file_upload->file = $file;
66
        }
67
        $file_upload->save();
68
69
        return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
70
    }
71
72
73
    public function saveTax($taxes, $product_id)
74
    {
75
        if ($taxes) {
76
            TaxProductRelation::where('product_id', $product_id)->delete();
77
            foreach ($taxes as $tax) {
78
                $newTax = new TaxProductRelation();
79
                $newTax->product_id = $product_id;
80
                $newTax->tax_class_id = $tax;
81
                $newTax->save();
82
            }
83
        }
84
85
        return $newTax;
86
    }
87
88
89
    public function getProductField($productid)
90
    {
91
        try {
92
            $field = '';
93
            $product = Product::find($productid);
94
            if ($product) {
95
                if ($product->require_domain == 1) {
96
                    $field .= "<div class='col-md-4 form-group'>
97
                        <label class='required'>"./* @scrutinizer ignore-type */
98
                         \Lang::get('message.domain')."</label>
99
                        <input type='text' name='domain' class='form-control' 
100
                        id='domain' placeholder='http://example.com'>
101
                </div>";
102
                }
103
            }
104
105
            return $field;
106
        } catch (\Exception $ex) {
107
            Bugsnag::notifyException($ex);
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Product\Bugsnag was not found. Did you mean Bugsnag? If so, make sure to prefix the type with \.
Loading history...
108
109
            return $ex->getMessage();
110
        }
111
    }
112
113
}
114