mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 10:49:10 -04:00
65 lines
1.3 KiB
PHP
65 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use mysql_xdevapi\Collection;
|
|
|
|
class Item extends Model
|
|
{
|
|
public static function explodeItems($items)
|
|
{
|
|
$array_items = explode("-",$items);
|
|
$col_items = collect();
|
|
|
|
foreach ($array_items as $item) {
|
|
$col_items->push(Item::find($item));
|
|
}
|
|
$col_items->forget(0);
|
|
return $col_items;
|
|
}
|
|
|
|
protected $casts = [
|
|
'metadata' => 'array',
|
|
];
|
|
|
|
public function bookings()
|
|
{
|
|
return $this->hasMany('App\Booking');
|
|
}
|
|
|
|
public function category()
|
|
{
|
|
if (\App\ItemCategory::find($this->category_id) == null)
|
|
{
|
|
$this->category_id = -1;
|
|
$this->save();
|
|
$c = new \App\ItemCategory();
|
|
$c->name = "[Categorie Supprimé]";
|
|
$c->is_training = 0;
|
|
$c->is_op_appro = 0;
|
|
|
|
return $c;
|
|
}
|
|
return \App\ItemCategory::find($this->category_id);
|
|
}
|
|
|
|
public function available()
|
|
{
|
|
|
|
return $this->quantity - $this->booked();
|
|
}
|
|
|
|
public function booked()
|
|
{
|
|
$nbBooked = 0;
|
|
|
|
foreach ($this->bookings() as $b)
|
|
{
|
|
$nbBooked = $nbBooked + $b->amount;
|
|
}
|
|
|
|
return $nbBooked;
|
|
}
|
|
}
|