91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
|
|
|
use Cms\Classes\Controller;
|
|
use BackendMenu;
|
|
use DB;
|
|
use Config;
|
|
use Illuminate\Http\Request;
|
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Tps\Reklama\Models\Reklama;
|
|
use Tps\Reklama\Models\Statistika;
|
|
use Carbon\Carbon;
|
|
|
|
class AdvertisementsController extends Controller
|
|
{
|
|
protected $Advertisement;
|
|
|
|
protected $helpers;
|
|
|
|
public function __construct(Reklama $Advertisement, Helpers $helpers)
|
|
{
|
|
parent::__construct();
|
|
$this->Reklama = $Advertisement;
|
|
$this->helpers = $helpers;
|
|
}
|
|
|
|
public function index(){
|
|
|
|
|
|
$path = Config::get('app.cdn').Config::get('cms.storage.media.path');
|
|
|
|
$dataInc = $this->Reklama
|
|
->where('active',1)
|
|
->orderBy('order_app', 'ASC')
|
|
->paginate(5);
|
|
|
|
$this->incrementView($dataInc);
|
|
|
|
//categories list
|
|
$data = $this->Reklama->select('id','title', 'url', DB::raw("IF(media_mobile<>'',concat('$path',media_mobile),media_mobile) as media_mobile"))
|
|
->where('active',1)
|
|
->orderBy('order_app', 'ASC')
|
|
->paginate(5)
|
|
->toArray();
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
}
|
|
|
|
|
|
public function getByGroup(Request $request){
|
|
|
|
$data = $request->all();
|
|
|
|
|
|
$path = Config::get('app.cdn').Config::get('cms.storage.media.path');
|
|
|
|
|
|
$dataInc = $this->Reklama->select('id','title', 'url', 'enable_stats', DB::raw("IF(media<>'',concat('$path',media),media) as media"))
|
|
->where('active',1)
|
|
->where('group_id', $data["group_id"])
|
|
->paginate(15);
|
|
|
|
$this->incrementView($dataInc);
|
|
|
|
//categories list
|
|
$data = $this->Reklama->select('id','title', 'url', 'enable_stats', DB::raw("IF(media<>'',concat('$path',media),media) as media"))
|
|
->where('active',1)
|
|
->where('group_id', $data["group_id"])
|
|
->paginate(15)
|
|
->toArray();
|
|
|
|
|
|
|
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
|
}
|
|
|
|
|
|
public function incrementView($data){
|
|
|
|
foreach ($data as $adv){
|
|
if($adv->enable_stats){
|
|
$statistika = Statistika::firstOrCreate(['item_id' => $adv->id,'date' => Carbon::today()]);
|
|
$statistika->increment('view');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|