AgendaRepository.php 2.76 KB
Newer Older
Bagus Pambudi committed
1 2 3 4 5 6 7 8 9 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 35 36 37
<?php

namespace App\Repositories\Webprofile;

use App\Models\Webprofile\Agenda;
use App\Repositories\Repository;
use DataTables;

class AgendaRepository extends Repository
{
    protected $model;

    public function __construct(Agenda $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)
    {
        return DataTables::of($data)
            ->addIndexColumn()
            ->addColumn('action', function ($row) {
38 39
                $btn = '<a href="' . url('/webprofile/agendas/' . $row->id . '/edit') . '" data-toggle="tooltip"  data-id="' . $row->id . '" data-original-title="' . trans('label.editsemuabahasa') . '" class="edit btn btn-warning btn-round btn-sm edit">' . trans('label.editsemuabahasa') . '</a>';

40
                $btn = $btn . ' <a href="'.url('/webprofile/agendas/'.$row->id.'/editperbahasa').'" data-toggle="tooltip"  data-id="'.$row->id.'" data-original-title="'.trans('label.edittiapbahasa').'" class="edit btn btn-warning btn-round btn-sm edit">'.trans('label.edittiapbahasa').'</a>';
Bagus Pambudi committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

                $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>';

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

                return $btn;
            })
            ->addColumn('date', function ($row) {
                $str = Date('d-m-Y', strtotime($row->event_date));

                return $str;
            })
            ->addColumn('status', function ($row) {
                if ($row->info_status == 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;
            })
            ->addColumn('title', function ($row) {
                $str = $row->title . '<br>';
                if ($row->rEn) {
                    $str .= '<i style="color: blue;">' . $row->rEn->title . '</i>';
                }

                return $str;
            })
            ->rawColumns(['action', 'status', 'date', 'title'])
            ->make(true);
    }
}