| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App;
- /**
- * Class Supplier
- * @property int $id
- * @property int $address_id
- * @property string $name
- * @property string $phone
- * @property string $fax
- * @property string $email
- * @property string $sku_prefix
- * @property string $dts_created
- * @property string $dts_updated
- * @property string $dts_deleted
- */
- class Supplier extends Model {
- protected static $table = "supplier";
- protected static $idField = "id";
- protected static $fillableFields = ["address_id", "name", "phone", "fax", "email", "sku_prefix", "dts_created", "dts_updated", "dts_deleted"];
- // Static methods
- /**
- * @return Supplier[]
- */
- public static function getAll(): array {
- return self::query([], ["sort" => "name"]);
- }
- public static function getOptions(): array {
- $options = [];
- foreach(self::getAll() as $supplier) {
- $options[$supplier->id] = $supplier->name;
- }
- return $options;
- }
- // Object methods
- /**
- * @return Address
- * @throws \Exception
- */
- public function getAddress(): Address {
- $address = Address::get($this->address_id);
- return $address ?: new Address();
- }
- public function getSlug(): string {
- return Util::slug("$this->name $this->id");
- }
- public function getUrl(): string {
- return sprintf("/suppliers/%s", $this->getSlug());
- }
- /**
- * @return Product[]
- */
- public function getProducts(): array {
- return Product::query([
- "supplier_id" => $this->id,
- "dts_deleted" => null
- ], ["sort" => "name"]);
- }
- }
|