mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 02:39:10 -04:00
78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Item;
|
|
|
|
class Schedule extends Model
|
|
{
|
|
protected $casts = [
|
|
'data' => 'array',
|
|
];
|
|
|
|
public function getInventory($periode)
|
|
{
|
|
$dispo = [];
|
|
$used = [];
|
|
$dispo_item = collect();
|
|
|
|
$string_periode = 'p'.$periode;
|
|
|
|
$inventory = Item::all();
|
|
|
|
foreach ($inventory as $item) {
|
|
array_push($dispo, $item->id);
|
|
}
|
|
|
|
$n1 = 'n1_'.$string_periode.'_item';
|
|
$items_array = explode("-",$this->$n1);
|
|
|
|
foreach ($items_array as $item_array) {
|
|
array_push($used,$item_array);
|
|
}
|
|
|
|
$n2 = 'n2_'.$string_periode.'_item';
|
|
$items_array = explode("-",$this->$n2);
|
|
|
|
foreach ($items_array as $item_array) {
|
|
array_push($used,$item_array);
|
|
}
|
|
|
|
$n3 = 'n3_'.$string_periode.'_item';
|
|
$items_array = explode("-",$this->$n3);
|
|
|
|
foreach ($items_array as $item_array) {
|
|
array_push($used,$item_array);
|
|
}
|
|
|
|
$dispo = array_diff($dispo,$used);
|
|
|
|
foreach ($dispo as $key) {
|
|
$dispo_item->push(Item::find($key));
|
|
}
|
|
|
|
return $dispo_item;
|
|
}
|
|
|
|
public function getUserToNotify($priority = 0)
|
|
{
|
|
$users = \App\User::all();
|
|
|
|
if($priority == 0)
|
|
{
|
|
$userToNotify = collect();
|
|
foreach ($users as $user) {
|
|
if ($user->getPerm('schedule_notify')) {
|
|
$userToNotify->push($user);
|
|
}
|
|
}
|
|
|
|
return $userToNotify;
|
|
} else if ($priority == 1)
|
|
{
|
|
return $users;
|
|
}
|
|
}
|
|
}
|