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');
@ -74,6 +75,11 @@ class ItemController extends Controller
$item = Item::where('eid', $eid)->where('item_uid', $id)->first();
$item->update($request->except(['file', 'box', '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);
$image = base64_decode(substr($request->get('dataImage'), $pos + 1), true);
@ -84,6 +90,7 @@ class ItemController extends Controller
file_put_contents('staticimages/' . $hash, $image);
$file = File::create(array('hash' => $hash, 'iid' => $item['iid']));
}
}
return response()->json($item, 200);
}

View file

@ -15,7 +15,7 @@ class Item extends Model
* @var array
*/
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
*/
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);
if (is_file($img)) {
try {
if(!file_exists("thumbnails"))
mkdir("thumbnails");
$imagick = new Imagick($img);
$imagick->setImageFormat('jpeg');
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);