File: /var/www/vhost/disk-apps/demo.sports-crowd.com/app/Http/Controllers/RadioEmbedController.php
<?php
namespace App\Http\Controllers;
use App\RadioEmbed;
use Illuminate\Http\Request;
use DB;
use Datatables;
class RadioEmbedController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('radio_embed.radio');
}
public function indexAdd()
{
return view('radio_embed.addRadio');
}
public function indexEdit($id)
{
$radio = RadioEmbed::find($id);
return view('radio_embed.editRadio')
->with('radio_embed', $radio);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$radio = new RadioEmbed();
$radio->title = $request["title"];
$radio->link = $request["link"];
$radio->active = true;
$radio->save();
if ($radio) {
return array('r' => true, 'd' => array('id' => $radio->id), 'm' => trans('messages.screen_radio_tag14'));
} else {
return array('r' => false, 'd' => null, 'm' => trans('messages.screen_radio_tag15'));
}
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request)
{
$radio = RadioEmbed::find($request["id"]);
$radio->title = $request["title"];
$radio->link = $request["link"];
$radio->update();
if ($radio) {
return array('r' => true, 'd' => array('id' => $radio->id), 'm' => trans('messages.screen_radio_tag16'));
} else {
return array('r' => false, 'd' => null, 'm' => trans('messages.screen_radio_tag17'));
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function activateRadio(Request $request)
{
$id = $request['id'];
$state = $request['state'];
$radio = RadioEmbed::find($id);
$radio->active = $state;
$radio->update();
if ($radio) {
return array('r' => true, 'd' => null, 'm' => trans('messages.screen_radio_tag18'));
} else {
return array('r' => false, 'd' => null, 'm' => trans('messages.screen_radio_tag19'));
}
}
public function tableFilter()
{
$obj = $obj = DB::table('radio_embeds')
->select('radio_embeds.id', 'radio_embeds.title', 'radio_embeds.link', 'radio_embeds.active');
return Datatables::of($obj)
->editColumn('link', function ($obj) {
return '
<div>
<iframe src="' . $obj->link . '" frameborder="0" allowfullscreen></iframe>
</div>
';
})
->addColumn('actions', function ($obj) {
return '
<i class="fa fa-pencil iconMini" onClick="clickEditRadio(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom" title="Editar" style="cursor:pointer;"></i>
<i class="fa fa-trash iconMini" onClick="clickDeleteRadio(' . $obj->id . ')" data-id="' . $obj->id . '" data-toggle="tooltip" data-placement="bottom" title="Eliminar" style="cursor:pointer;"></i>
';
})
->editColumn('active', function ($obj) {
if ($obj->active == 0) {
return '<div class="switch"><label><div class="checkbox checbox-switch switch-success"> <label> No <input type="checkbox" onChange="chkRadio(' . $obj->id . ')" data-id="' . $obj->id . '" id="Checkactive' . $obj->id . '" name="Checkactivo" /> <span></span>Si </label></div> </label> </div>';
} else {
return '<div class="switch"><label> <div class="checkbox checbox-switch switch-success"> <label> No <input type="checkbox" onChange="chkRadio(' . $obj->id . ')" data-id="' . $obj->id . '" id="Checkactive' . $obj->id . '" name="Checkactivo" checked="" />
<span></span> Si </label> </div> </label> </div>';
}
})
->rawColumns(['active', 'actions', 'link'])
->make(true);
}
public function delete(Request $request)
{
$radio = RadioEmbed::find($request['id']);
$radio->delete();
if ($radio) {
return array('r' => true, 'd' => null, 'm' => trans('messages.screen_radio_tag20'));
} else {
return array('r' => false, 'd' => null, 'm' => trans('messages.screen_radio_tag21'));
}
}
}