80 lines
2.7 KiB
PHP
80 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Container;
|
|
use App\File;
|
|
use App\Item;
|
|
use App\Event;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ItemController extends Controller
|
|
{
|
|
|
|
public function showAllItems()
|
|
{
|
|
return response()->json(Item::all());
|
|
}
|
|
|
|
public function showByEvent($event)
|
|
{
|
|
$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')
|
|
->select('items.*','files.hash as file', 'containers.name as box')
|
|
->get());
|
|
}
|
|
|
|
public function searchByEvent($event, $query)
|
|
{
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
$query_tokens = explode(" ",base64_decode ( $query , true));
|
|
$q = Item::where('eid','=',$eid)
|
|
->join('containers','items.cid','=','containers.cid')
|
|
->leftJoin('files','items.iid','=','files.iid')
|
|
->select('items.*','files.hash as file', 'containers.name as box');
|
|
foreach ($query_tokens as $token)
|
|
$g = $q->where('items.description','like','%'.$token.'%');
|
|
return response()->json($q->get());
|
|
}
|
|
|
|
public function showOneItem($event, $id)
|
|
{
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
return response()->json(Item::find($id));
|
|
}
|
|
|
|
public function create($event, Request $request)
|
|
{
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
$uid = Item::withTrashed()->where('eid',$eid)->max('item_uid') + 1;
|
|
$newitem = $request->except(['dataImage']);
|
|
$newitem['eid'] = "".$eid;
|
|
$newitem['item_uid'] = $uid;
|
|
$newitem['wo'] = "";
|
|
$item = Item::create($newitem);
|
|
$image = $request->file('image');
|
|
$hash = md5(time());
|
|
if(!file_exists('staticimages'))
|
|
mkdir('staticimages',0755, true);
|
|
$image->move('staticimages', $hash);
|
|
$file = File::create(array('hash' => $hash, 'iid'=> $item['iid']));
|
|
return response()->json($item, 201);
|
|
}
|
|
|
|
public function update($event, $id, Request $request)
|
|
{
|
|
$eid = Event::where('slug', $event)->first()->eid;
|
|
$item = Item::where('eid', $eid)->where('item_uid', $id)->first();
|
|
$item->update($request->except(['file','box']));
|
|
return response()->json($item, 200);
|
|
}
|
|
|
|
public function delete($event, $id)
|
|
{
|
|
$eid = Event::where('slug','=',$event)->first()->eid;
|
|
Item::where('eid', $eid)->where('item_uid', $id)->first()->delete();
|
|
return response()->json(array("status"=>'Deleted Successfully'), 200);
|
|
}
|
|
}
|