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

View file

@ -15,7 +15,7 @@ class Item extends Model
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'iid', 'item_uid', 'description', 'wann', 'wo', 'eid', 'cid' 'iid', 'item_uid', 'description', 'wann', 'wo', 'eid', 'cid', 'returned_at'
]; ];
@ -26,6 +26,9 @@ class Item extends Model
* *
* @var array * @var array
*/ */
protected $hidden = ['created_at','updated_at', 'deleted_at', 'eid', 'iid']; protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid', 'wann', 'wo'];
public static function restored($callback)
{
}
} }

View file

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddItemReturnedAtMember extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
Schema::table('items', function (Blueprint $table) {
$table->timestamp('returned_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn('returned_at');
});
}
}

View file

@ -12,6 +12,8 @@ $thumb = getcwd() . $_GET["id"];
$img = str_replace("thumbnails", "staticimages", $thumb); $img = str_replace("thumbnails", "staticimages", $thumb);
if (is_file($img)) { if (is_file($img)) {
try { try {
if(!file_exists("thumbnails"))
mkdir("thumbnails");
$imagick = new Imagick($img); $imagick = new Imagick($img);
$imagick->setImageFormat('jpeg'); $imagick->setImageFormat('jpeg');
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG); $imagick->setImageCompression(Imagick::COMPRESSION_JPEG);