2019-11-15 21:26:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2019-12-21 18:08:40 +00:00
|
|
|
use App\Container;
|
|
|
|
use App\File;
|
2019-11-15 21:26:54 +00:00
|
|
|
use App\Item;
|
2019-12-02 17:41:40 +00:00
|
|
|
use App\Event;
|
2019-11-15 21:26:54 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class ItemController extends Controller
|
|
|
|
{
|
|
|
|
|
2019-11-30 12:47:54 +00:00
|
|
|
public function showAllItems()
|
2019-11-15 21:26:54 +00:00
|
|
|
{
|
|
|
|
return response()->json(Item::all());
|
|
|
|
}
|
|
|
|
|
2019-12-01 17:30:25 +00:00
|
|
|
public function showByEvent($event)
|
2019-11-30 12:47:54 +00:00
|
|
|
{
|
2019-12-02 17:41:40 +00:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-12-05 12:05:44 +00:00
|
|
|
return response()->json(Item::where('eid','=',$eid)
|
2019-12-05 12:09:25 +00:00
|
|
|
->join('containers','items.cid','=','containers.cid')
|
2019-12-05 12:07:03 +00:00
|
|
|
->leftJoin('files','items.iid','=','files.iid')
|
2019-12-15 19:34:47 +00:00
|
|
|
->select('items.*','files.hash as file', 'containers.name as box')
|
2019-12-05 12:05:44 +00:00
|
|
|
->get());
|
2019-11-30 12:47:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 17:30:25 +00:00
|
|
|
public function searchByEvent($event, $query)
|
|
|
|
{
|
2019-12-11 20:36:43 +00:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
|
|
return response()->json(Item::where('eid','=',$eid)
|
|
|
|
->join('containers','items.cid','=','containers.cid')
|
|
|
|
->leftJoin('files','items.iid','=','files.iid')
|
2019-12-15 19:34:47 +00:00
|
|
|
->select('items.*','files.hash as file', 'containers.name as box')
|
|
|
|
->where('items.description', 'like' , '%'.base64_decode ( $query , true).'%')
|
2019-12-11 20:36:43 +00:00
|
|
|
->get());
|
2019-12-01 17:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showOneItem($event, $id)
|
2019-11-15 21:26:54 +00:00
|
|
|
{
|
2019-12-17 00:33:40 +00:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-11-15 21:26:54 +00:00
|
|
|
return response()->json(Item::find($id));
|
|
|
|
}
|
|
|
|
|
2019-12-01 17:30:25 +00:00
|
|
|
public function create($event, Request $request)
|
2019-11-30 12:47:54 +00:00
|
|
|
{
|
2019-12-17 00:33:40 +00:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-12-23 21:17:21 +00:00
|
|
|
$uid = Item::withTrashed()->where('eid',$eid)->max('item_uid') + 1;
|
2019-12-21 18:08:40 +00:00
|
|
|
$newitem = $request->except(['dataImage']);
|
|
|
|
$newitem['eid'] = "".$eid;
|
2019-12-22 21:07:48 +00:00
|
|
|
$newitem['item_uid'] = $uid;
|
2019-12-21 18:08:40 +00:00
|
|
|
$newitem['wo'] = "";
|
|
|
|
$item = Item::create($newitem);
|
2019-12-23 11:19:45 +00:00
|
|
|
$image = $request->file('image');
|
2019-12-21 18:08:40 +00:00
|
|
|
$hash = md5(time());
|
2019-12-23 11:19:45 +00:00
|
|
|
if(!file_exists('staticimages'))
|
|
|
|
mkdir('staticimages',0755, true);
|
|
|
|
$image->move('staticimages', $hash);
|
2019-12-21 18:08:40 +00:00
|
|
|
$file = File::create(array('hash' => $hash, 'iid'=> $item['iid']));
|
2019-11-15 21:26:54 +00:00
|
|
|
return response()->json($item, 201);
|
|
|
|
}
|
|
|
|
|
2019-12-01 17:30:25 +00:00
|
|
|
public function update($event, $id, Request $request)
|
2019-11-15 21:26:54 +00:00
|
|
|
{
|
2019-12-19 15:22:57 +00:00
|
|
|
$eid = Event::where('slug', $event)->first()->eid;
|
|
|
|
$item = Item::where('eid', $eid)->where('item_uid', $id)->first();
|
|
|
|
$item->update($request->except(['file','box']));
|
2019-12-15 17:15:41 +00:00
|
|
|
return response()->json($item, 200);
|
2019-11-15 21:26:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 17:30:25 +00:00
|
|
|
public function delete($event, $id)
|
2019-11-15 21:26:54 +00:00
|
|
|
{
|
2019-12-17 00:33:40 +00:00
|
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
2019-12-19 21:15:42 +00:00
|
|
|
Item::where('eid', $eid)->where('item_uid', $id)->first()->delete();
|
2019-12-21 18:08:40 +00:00
|
|
|
return response()->json(array("status"=>'Deleted Successfully'), 200);
|
2019-11-15 21:26:54 +00:00
|
|
|
}
|
2019-11-30 12:47:54 +00:00
|
|
|
}
|