Page MenuHomePhorge

Package.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

Package.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
/**
* The eloquent definition of a Package.
*
* A package is a set of SKUs that a user can select, so that instead of;
*
* * Create a mailbox entitlement,
* * Create a quota entitlement,
* * Create a groupware entitlement,
* * ...
*
* users can simply select a 'package';
*
* * Kolab package: mailbox + quota + groupware,
* * Free package: mailbox + quota.
*
* Selecting a package will therefore create a set of entitlments from SKUs.
*/
class Package extends Model
{
use HasTranslations;
public $incrementing = false;
protected $keyType = 'string';
public $timestamps = false;
protected $fillable = [
'description',
'discount_rate',
'name',
'title',
];
/** @var array Translatable properties */
public $translatable = [
'name',
'description',
];
/**
* The costs of this package at its pre-defined, existing configuration.
*
* @return int The costs in cents.
*/
public function cost()
{
$costs = 0;
foreach ($this->skus as $sku) {
$units = $sku->pivot->qty - $sku->units_free;
if ($units < 0) {
\Log::debug("Package {$this->id} is misconfigured for more free units than qty.");
$units = 0;
}
$ppu = $sku->cost * ((100 - $this->discount_rate) / 100);
$costs += $units * $ppu;
}
return $costs;
}
public function isDomain()
{
foreach ($this->skus as $sku) {
if ($sku->handler_class::entitleableClass() == \App\Domain::class) {
return true;
}
}
return false;
}
public function skus()
{
return $this->belongsToMany(
'App\Sku',
'package_skus'
)->using('App\PackageSku')->withPivot(
['qty']
);
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 10:24 AM (1 d, 3 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a5/11/38ac6981d71dc1b48f39d36df541
Default Alt Text
Package.php (1 KB)

Event Timeline