/** * Runs extra setup code when creating a new model * * @return void */ public function setup() { $this->addRule('ip', function ($data) { if (isset($data['ip']) && !Validate::ip($data['ip'])) { return Lang::txt('Invalid IP address'); } return false; }); }
/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->response_id = intval($this->response_id); if (!$this->response_id) { $this->setError(Lang::txt('Missing response ID')); } $this->helpful = strtolower(trim($this->helpful)); if (!$this->helpful) { $this->setError(Lang::txt('Missing vote')); } if (!in_array($this->helpful, array(1, 'yes', 'like', 'up', -1, 'no', 'dislike', 'down'))) { $this->setError(Lang::txt('Invalid vote')); } if (!Validate::ip($this->ip)) { $this->setError(Lang::txt('Invalid IP address')); } if ($this->getError()) { return false; } return true; }
/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->question_id = intval($this->question_id); if (!$this->question_id) { $this->setError(Lang::txt('Missing question ID')); } $this->voter = intval($this->voter); if (!$this->voter) { $this->voter = User::get('id'); } if (!$this->expires) { $this->expires = Date::of(time() + 7 * 24 * 60 * 60)->toSql(); // in a week } if (!Validate::ip($this->ip)) { $this->setError(Lang::txt('Invalid IP address')); } if ($this->getError()) { return false; } return true; }
/** * Validate data * * @return boolean True if data is valid */ public function check() { $this->referenceid = intval($this->referenceid); if (!$this->referenceid) { $this->setError(Lang::txt('Missing reference ID')); } $this->category = trim($this->category); if (!$this->category) { $this->setError(Lang::txt('Missing category')); } if (!$this->id) { $this->voted = $this->voted ? $this->voted : Date::toSql(); $this->voter = $this->voter ? $this->voter : User::get('id'); } if (!Validate::ip($this->ip)) { $this->setError(Lang::txt('Invalid IP address')); } if ($this->getError()) { return false; } return true; }