diff options
Diffstat (limited to 'classes/Offer.php')
-rw-r--r-- | classes/Offer.php | 56 |
1 files changed, 12 insertions, 44 deletions
diff --git a/classes/Offer.php b/classes/Offer.php index a4d6b7f..8da2095 100644 --- a/classes/Offer.php +++ b/classes/Offer.php @@ -79,12 +79,7 @@ class Offer extends Model{ * @return int[] The ids */ public function getAssignmentIds() { - $ids = array(); - $assignments = $this->pdo->query("SELECT `id` FROM `".Constants::db_prefix."assignment` WHERE `offerId`={$this->id}")->fetchAll(PDO::FETCH_ASSOC); - foreach ($assignments as $assignment) { - $ids[] = $assignment['id']; - } - return $ids; + return Assignment::searchIds($this->pdo, ['`offerId`=?'], [$this->id]); } /** @@ -97,12 +92,7 @@ class Offer extends Model{ * @return assignment[] An array indexed by id of instances of the assignment class */ public function getAssignments() { - $ids = $this->getAssignmentIds(); - $assignments = array(); - foreach ($ids as $id) { - $assignments[$id] = new Assignment($this->pdo, $id); - } - return $assignments; + return Assignment::search($this->pdo, ['`offerId`=?'], [$this->id]); } /** @@ -115,12 +105,7 @@ class Offer extends Model{ * @return int[] The ids */ public function getDiscountIds() { - $ids = array(); - $discounts = $this->pdo->query("SELECT `id` FROM `".Constants::db_prefix."discount` WHERE `offerId`={$this->id}")->fetchAll(PDO::FETCH_ASSOC); - foreach ($discounts as $discount) { - $ids[] = $discount['id']; - } - return $ids; + return Discount::searchIds($this->pdo, ['`offerId`=?'], [$this->id]); } /** @@ -133,12 +118,7 @@ class Offer extends Model{ * @return discount[] An array indexed by id of instances of the discount class */ public function getDiscounts() { - $ids = $this->getDiscountIds(); - $discounts = array(); - foreach ($ids as $id) { - $discounts[$id] = new Discount($this->pdo, $id); - } - return $discounts; + return Discount::search($this->pdo, ['`offerId`=?'], [$this->id]); } /** @@ -162,12 +142,12 @@ class Offer extends Model{ * @return int|null The id, or null if no payment exists */ public function getPaymentId() { - $ids = array(); - $payments = $this->pdo->query("SELECT `id` FROM `".Constants::db_prefix."payment` WHERE `offerId`={$this->id}")->fetchAll(PDO::FETCH_ASSOC); - foreach ($payments as $payment) { - return $payment['id']; + $ids = Payment::searchIds($this->pdo, ['`offerId`=?'], [$this->id]); + if (count($ids) == 0) { + return null; + } else { + return $ids[0]; } - return null; } /** @@ -181,11 +161,7 @@ class Offer extends Model{ */ public function getPayment() { $id = $this->getPaymentId(); - if (is_null($id)) { - return null; - } else { - return new Payment($this->pdo, $id); - } + return is_null($id) ? null : new Payment($this->pdo, $id); } /** @@ -195,11 +171,7 @@ class Offer extends Model{ */ public function getPaymentReceived() { $payment = $this->getPayment(); - if (is_null($payment)) { - return null; - } else { - return $payment->date; - } + return is_null($payment) ? null : $payment->date; } /** @@ -210,11 +182,7 @@ class Offer extends Model{ * @return file|null The file, or null if it doesn't exist */ public function getInvoiceFile() { - if ($this->invoice_fileId != null) { - return new File($this->pdo, $this->invoice_fileId); - } else { - return null; - } + return is_null($this->invoice_fileId) ? null : new File($this->pdo, $this->invoice_fileId); } /** |