function update($id, $data) { if ($item = $this->findOne($id)) { $data = $this->db->filter($data); $this->validBit->setSource($data); $this->validBit->check('username', 'required|alphanum'); $this->validBit->check('password', 'required|string'); $this->validBit->check('email', 'required|email'); if ($this->validBit->isValid() !== true) { return $this->validBit->getStatus(); } else { if ($item->username !== $data["username"]) { $this->validBit->check("username", 'unique:users.username'); } if ($item->email !== $data["email"]) { $this->validBit->check("email", 'unique:users.email'); } } if ($this->validBit->isValid() !== true) { return $this->validBit->getStatus(); } $data['username'] = $data['username']; $data['email'] = $data['email']; $data['password'] = sha1($data['password']); $data['visible'] = ValidBit::ifSet($data, 'visible', 0); if (parent::_update($id, $data)) { $this->validBit->setStatus(200, 'data updated'); } else { $this->validBit->setStatus(500, 'something went wrong'); } return $this->validBit->getStatus(); } else { return array("code" => 404, "msgs" => array("Invalid ID")); } }
function update($id, $data) { $data = $this->db->filter($data); $v = new ValidBit(); $v->setSource($data); $v->check('title', 'required|string'); $v->check('body', 'required|string'); if ($v->isValid() !== true) { return $v->getStatus(); } $data = array("title" => $data['title'], "body" => $data['body'], "visible" => ValidBit::ifSet($data, 'visible', 0)); if (parent::_update($id, $data)) { $v->setStatus(200, 'data updated'); } else { $v->setStatus(500, 'something went wrong'); } return $v->getStatus(); }