GalleryRepository.php 2.55 KB
Newer Older
1 2 3 4 5
<?php

namespace App\Repositories\Webprofile;

use App\Models\Webprofile\Gallery;
Aan Choesni Herlingga committed
6
use App\Repositories\StorageRepository;
7 8
use DataTables;

Aan Choesni Herlingga committed
9
class GalleryRepository extends StorageRepository
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
{
    protected $model;

    public function __construct(Gallery $model)
    {
        $this->model = $model;
    }

    public function get($with = null, $title = null, $orderBy = null)
    {
        return $this->model
            ->when($with, function ($query) use ($with) {
                return $query->with($with);
            })
            ->when($title, function ($query) use ($title) {
                return $query->where('title', 'ilike', '%' . $title . '%');
            })
            ->when($orderBy, function ($query) use ($orderBy) {
                return $query->orderBy($orderBy[0], $orderBy[1]);
            })
            ->get();
    }

    public function datatable($data)
    {
Aan Choesni Herlingga committed
35 36
        $setting = webprofilesetting();

37 38 39
        return DataTables::of($data)
            ->addIndexColumn()
            ->addColumn('action', function ($row) {
Aan Choesni Herlingga committed
40
                $btn = '<a href="' . url('/webprofile/gallery/' . $row->id . '/edit') . '" data-toggle="tooltip"  data-id="' . $row->id . '" data-original-title="' . trans('label.edit') . '" class="edit btn btn-warning btn-round btn-sm edit">' . trans('label.edit') . '</a>';
41

Aan Choesni Herlingga committed
42
                $btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip"  data-id="' . $row->id . '" data-original-title="' . trans('label.delete') . '" class="btn btn-danger btn-round btn-sm delete">' . trans('label.delete') . '</a>';
43 44 45 46 47

                $btn = $btn . '<br>';

                return $btn;
            })
Aan Choesni Herlingga committed
48 49 50 51 52 53 54 55 56
            ->addColumn('gallery', function ($row) use ($setting) {
                if ($setting['external_storage'] == 1) {
                    $str = '<img src="' . $setting['url_static'] . '/' . $setting['directory'] . '/gallery/' . $row->gallery . '" height="100" width="auto">';
                } else {
                    $str = '<img src="' . url('/storage/gallery/' . $row->gallery) . '" height="100" width="auto">';
                }

                return $str;
            })
57 58 59 60 61 62 63 64
            ->addColumn('status', function ($row) {
                if ($row->is_active == true) {
                    $str = '<div style="color: green;"><i class="fa fa-check"></i></div>';
                } else {
                    $str = '<div style="color: red;"><i class="fa fa-times"></i></div>';
                }
                return $str;
            })
Aan Choesni Herlingga committed
65
            ->rawColumns(['action', 'status', 'gallery'])
66 67 68
            ->make(true);
    }
}