| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App;
- /**
- * Class Customer
- * @property int $id
- * @property int $address_id
- * @property string $name
- * @property string $phone
- * @property string $fax
- * @property string $email
- * @property string $dts_created
- * @property string $dts_updated
- * @property string $dts_deleted
- */
- class Customer extends Model {
- protected static $table = "customer";
- protected static $idField = "id";
- protected static $fillableFields = ["address_id", "name", "phone", "fax", "email", "dts_created", "dts_updated", "dts_deleted"];
- // Static methods
- /**
- * @return Customer[]
- */
- public static function getAll(): array {
- return self::query([], ["sort" => "name"]);
- }
- public static function getOptions(): array {
- $options = [];
- foreach(self::getAll() as $customer) {
- $options[$customer->id] = $customer->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("/customers/%s", $this->getSlug());
- }
- /**
- * @return Location[]
- */
- public function getLocations(): array {
- return Location::query(["customer_id" => $this->id, "dts_deleted" => null]);
- }
- }
|