add 'returned' flag in items

This commit is contained in:
j3d1 2019-12-28 04:31:13 +01:00
parent 6bdbd2039b
commit b349690996
4 changed files with 61 additions and 16 deletions

View file

@ -7,6 +7,7 @@ use App\File;
use App\Item;
use App\Event;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class ItemController extends Controller
{
@ -19,18 +20,18 @@ class ItemController extends Controller
public function showByEvent($event)
{
$eid = Event::where('slug','=',$event)->first()->eid;
return response()->json(Item::where('eid','=',$eid)
$q = Item::where('eid','=',$eid)->whereNull('returned_at')
->join('containers','items.cid','=','containers.cid')
->leftJoin('currentfiles','items.iid','=','currentfiles.iid')
->select('items.*','currentfiles.hash as file', 'containers.name as box')
->get());
->select('items.*','currentfiles.hash as file', 'containers.name as box');
return response()->json($q->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)
$q = Item::where('eid','=',$eid)->whereNull('returned_at')
->join('containers','items.cid','=','containers.cid')
->leftJoin('currentfiles','items.iid','=','currentfiles.iid')
->select('items.*','currentfiles.hash as file', 'containers.name as box');
@ -72,17 +73,23 @@ class ItemController extends Controller
{
$eid = Event::where('slug', $event)->first()->eid;
$item = Item::where('eid', $eid)->where('item_uid', $id)->first();
$item->update($request->except(['file','box','dataImage']));
$item->update($request->except(['file', 'box', 'dataImage']));
$pos = strpos( $request->get('dataImage') , "," );
//$head = substr($request->get('dataImage'), 0, $pos);
$image = base64_decode(substr($request->get('dataImage'), $pos+1), true);
if($image) {
$hash = md5(time());
if (!file_exists('staticimages'))
mkdir('staticimages', 0755, true);
file_put_contents('staticimages/'. $hash, $image);
$file = File::create(array('hash' => $hash, 'iid' => $item['iid']));
if($request->get('returned')===true){
$item->update(['returned_at' => DB::raw( 'current_timestamp' )]);
}
if ($request->get('dataImage')) {
$pos = strpos($request->get('dataImage'), ",");
//$head = substr($request->get('dataImage'), 0, $pos);
$image = base64_decode(substr($request->get('dataImage'), $pos + 1), true);
if ($image) {
$hash = md5(time());
if (!file_exists('staticimages'))
mkdir('staticimages', 0755, true);
file_put_contents('staticimages/' . $hash, $image);
$file = File::create(array('hash' => $hash, 'iid' => $item['iid']));
}
}
return response()->json($item, 200);
}