AutopostRepository.php 2.9 KB
Newer Older
1 2 3 4 5 6
<?php

namespace App\Repositories\Webprofile;

use App\Models\Webprofile\Autopost;
use App\Repositories\Repository;
7
use DataTables;
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 38 39 40 41 42 43 44 45

class AutopostRepository extends Repository
{
    protected $model;

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

    public function get($with = null, $name = null, $orderBy = null)
    {
        return $this->model
            ->when($with, function ($query) use ($with) {
                return $query->with($with);
            })
            ->when($name, function ($query) use ($name) {
                return $query->where('name', 'ilike', '%'.$name.'%');
            })
            ->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) {
                $btn = '<a href="'.url('/webprofile/autopost/'.$row->id.'/edit').'" data-toggle="tooltip"  data-id="'.$row->id.'" data-original-title="Edit" class="edit btn btn-warning btn-round btn-sm edit">Edit</a>';

                $btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip"  data-id="'.$row->id.'" data-original-title="Delete" class="btn btn-danger btn-round btn-sm delete">Delete</a>';

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

                return $btn;
            })
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
            ->addColumn('description', function ($row) {
                if ($row->type == 'facebook') {
                    $str = 'FACEBOOK ID => '.$row->key_1.'<br>';
                    $str .= 'FACEBOOK SECRET => '.$row->key_2.'<br>';
                    $str .= 'FACEBOOK GRAPH VERSION => '.$row->key_3.'<br>';
                    $str .= 'FACEBOOK ACCESS TOKEN => '.$row->key_4;
                } elseif ($row->type == 'twitter') {
                    $str = 'TWITTER KEY => '.$row->key_1.'<br>';
                    $str .= 'TWITTER SECRET KEY => '.$row->key_2.'<br>';
                    $str .= 'TWITTER TOKEN => '.$row->key_3.'<br>';
                    $str .= 'TWITTER TOKEN SECRET => '.$row->key_4.'<br>';
                    $str .= 'TWITTER BEARER KEY => '.$row->key_5;
                } elseif ($row->type == 'telegram') {
                    $str = 'API TOKEN => '.$row->key_1.'<br>';
                    $str .= 'BOT USERNAME => '.$row->key_2.'<br>';
                    $str .= 'CHANNEL USERNAME => '.$row->key_3.'<br>';
                    $str .= 'CHANNEL SIGNATURE => '.$row->key_4.'<br>';
                    $str .= 'PROXY => '.$row->key_5;
64 65 66
                } elseif ($row->type == 'alia') {
                    $str = 'URL => '.$row->key_1.'<br>';
                    $str .= 'POSTS => '.$row->key_2.'<br>';
67 68 69 70
                }

                return $str;
            })
71
            ->rawColumns(['action', 'description'])
72 73 74
            ->make(true);
    }
}