(int)$this->id, 'customer_number' => (int)$this->customer_number->value(), 'price' => (int)$this->price->value(), 'description' => (string)$this->description->value(), 'created_at' => (string)$this->created_at->value(), 'updated_at' => (string)$this->updated_at->value(), ]; } /** * @throws Exception If the creation of the object fails */ public function add(int $customer_number, int $price, string $description = ''): void { global $db, $response; $tmp_id = self::add_object([ 'customer_number' => (int)$customer_number, 'price' => (int)$price, 'description' => (string)$description, ]); self::select((int)$tmp_id); self::objectChanged(); } public function objectChanged(): void { // Since the customer_vehicles object is not cached, there is no need to invalidate the cache } public function structure(): void { $this->setTable('customer_fixed_pricing'); } public function getObjectProperties(): void { $this->customer_number = new object_property($this->table, $this->id, 'customer_number', 'int', true); $this->price = new object_property($this->table, $this->id, 'price', 'int', true); $this->description = new object_property($this->table, $this->id, 'description', 'string', true); $this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', true); $this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'timestamp', true); } /** * Get the customer_fixed_pricing object by customer number * @param int $customer_number * @return bool Returns true if the customer_fixed_pricing object exists, false otherwise. */ public function doesUserHaveFixedPricing(int $customer_number): bool { return $this->getIdByCustomerNumber($customer_number) !== null; } /** * Get the ID of the customer_fixed_pricing object by customer number * @param int $customer_number * @return int|null Returns the ID of the customer_fixed_pricing object, if it exists. Returns null, if it does not exist. */ public function getIdByCustomerNumber(int $customer_number): ?int { $matches = self::getFieldsWhere([ 'customer_number' => (int)$customer_number, ], [ 'id' ]); if (count($matches) > 0) { // There is a match, so return the ID return (int)$matches[0]['id']; } else { // There's no match, so return null return null; } } /** * Get the customer_fixed_pricing object by customer number * @param int $customer_number * @return customer_fixed_pricing_o|null Returns the customer_fixed_pricing object, if it exists. Returns null, if it does not exist. * @throws Exception If the user does not have fixed pricing, or if the object is not selected successfully. * @see doesUserHaveFixedPricing() * @see getIdByCustomerNumber() */ public function selectByCustomerNumber(int $customer_number): ?customer_fixed_pricing_o { $this->select($this->getIdByCustomerNumber($customer_number)); if ($this->exists()) { return $this; } else { throw new Exception('Unable to select fixed pricing item by customer_number, no item found'); } } }