public function validate() { $return = true; if ($this->user_id == "") { $this->errors[] = "You must enter a user"; $return = false; } if ($this->discount_code_id == "") { $this->errors[] = "You must enter a discount code"; $return = false; } if ($return) { $dcu = DiscountCodeUser::find("users.id = '{$user_id}' AND discount_codes.id = '{$discount_id}'"); if ($dcu && (!$this->id || $this->id != $dcu->id)) { $this->errors[] = 'User has already been added for this discount'; $return = false; } } if (count($this->errors) > 0) { $return = false; } return $return; }
public function discountcode_users($reload = false) { if ($reload or !$this->discountcode_users_cache) { $id = mysql_real_escape_string($this->id); $this->discountcode_users_cache = DiscountCodeUser::find_all("users.id = '{$id}'"); } return $this->discountcode_users_cache; }