| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?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());
- }
- /**
- * @param array $nvp
- * @return Location[]
- */
- public function getLocations(array $nvp = []): array {
- $nvp = array_merge($nvp, [
- "customer_id" => $this->id,
- "dts_deleted" => null
- ]);
- return Location::query($nvp, [
- "sort" => "name"
- ]);
- }
- }
|