2018-06-05 11:13:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-12-24 01:14:01 +00:00
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Collection;
|
2021-12-20 03:25:43 +00:00
|
|
|
use Leenooks\Traits\ScopeActive;
|
2018-06-05 11:13:57 +00:00
|
|
|
|
2022-04-02 07:06:34 +00:00
|
|
|
use App\Models\Supplier\{Broadband,Domain,Email,Ethernet,Generic,Host,HSPA,Voip};
|
2021-12-24 01:14:01 +00:00
|
|
|
|
2018-06-05 11:13:57 +00:00
|
|
|
class Supplier extends Model
|
|
|
|
{
|
2021-12-20 03:25:43 +00:00
|
|
|
use ScopeActive;
|
|
|
|
|
|
|
|
public $timestamps = FALSE;
|
|
|
|
|
2021-12-24 01:14:01 +00:00
|
|
|
/* The offerings we provide */
|
|
|
|
public const offering_types = [
|
|
|
|
'broadband' => [
|
|
|
|
'name' => 'Broadband',
|
|
|
|
'class' => Broadband::class,
|
|
|
|
],
|
|
|
|
'hspa' => [
|
|
|
|
'name' => 'Mobile Broadband',
|
|
|
|
'class' => HSPA::class,
|
|
|
|
],
|
|
|
|
'ethernet' => [
|
|
|
|
'name' => 'Ethernet Broadband',
|
|
|
|
'class' => Ethernet::class,
|
|
|
|
],
|
|
|
|
'domainname' => [
|
|
|
|
'name' => 'Domain Name',
|
2022-02-01 05:40:46 +00:00
|
|
|
'class' => Domain::class,
|
2021-12-24 01:14:01 +00:00
|
|
|
],
|
2022-04-02 07:06:34 +00:00
|
|
|
'email' => [
|
|
|
|
'name' => 'Email Hosting',
|
|
|
|
'class' => Email::class,
|
|
|
|
],
|
2021-12-24 01:14:01 +00:00
|
|
|
'generic' => [
|
|
|
|
'name' => 'Generic',
|
2022-02-01 05:40:46 +00:00
|
|
|
'class' => Generic::class,
|
2021-12-24 01:14:01 +00:00
|
|
|
],
|
|
|
|
'hosting' => [
|
|
|
|
'name' => 'Hosting',
|
2022-02-01 05:40:46 +00:00
|
|
|
'class' => Host::class,
|
2021-12-24 01:14:01 +00:00
|
|
|
],
|
|
|
|
'voip' => [
|
|
|
|
'name' => 'VOIP Telephone',
|
2022-02-01 05:40:46 +00:00
|
|
|
'class' => Voip::class,
|
2021-12-24 01:14:01 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2021-12-20 03:25:43 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
public function detail()
|
|
|
|
{
|
|
|
|
return $this->hasOne(SupplierDetail::class);
|
|
|
|
}
|
2021-12-24 01:14:01 +00:00
|
|
|
|
|
|
|
/* METHODS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the offerings that this supplier provides
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function offeringTypes(): Collection
|
|
|
|
{
|
|
|
|
$result = collect();
|
|
|
|
|
|
|
|
// See if we have any configurations
|
|
|
|
foreach (self::offering_types as $key => $type) {
|
2022-02-01 05:40:46 +00:00
|
|
|
if (! ($class=Arr::get($type,'class')))
|
2021-12-24 01:14:01 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Arr::get($this->detail->connections,$key)) {
|
|
|
|
$result->put($key,(object)[
|
|
|
|
'type' => Arr::get($type,'name'),
|
|
|
|
'items' => (new $class)->where('supplier_detail_id',$this->detail->id),
|
|
|
|
]);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we have any products defined
|
|
|
|
$o = new $class;
|
|
|
|
$o->where('supplier_detail_id',$this->detail->id);
|
|
|
|
|
|
|
|
if ($o->count())
|
|
|
|
$result->put($key,(object)[
|
|
|
|
'type' => Arr::get($type,'name'),
|
|
|
|
'items' => (new $class)->where('supplier_detail_id',$this->detail->id),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2021-12-20 03:25:43 +00:00
|
|
|
}
|