/** * @param User $user * @param null $password * @return User * @throws \Simplon\Mysql\MysqlException */ public function editUser(User $user, $password = NULL) { $data = array("username" => $user->getUsername(), "vorname" => $user->getVorname(), "nachname" => $user->getNachname(), "anschrift" => $user->getAnschrift(), "telefonDurchwahl" => $user->getTelefonDurchwahl(), "telefonPrivat" => $user->getTelefonPrivat(), "telefonMobil" => $user->getTelefonMobil()); //Method Overloading is a bitch in PHP... :/ if (!is_null($password)) { $data["password_hash"] = $password; } $this->database->update("users", array("id" => $user->getId()), $data); return $user; }
/** * handle post after validation if needs * @param $post * @return array|bool */ public function handlePost($post) { if (count($post) < 1) { return false; } $database = new Database(); $invalidFields = []; $fields = []; foreach ($this->getForm()->getFields() as $field) { if ($field->isStorable()) { $field->setValue($post[$field->getName()]); if ($field->getValidation() && Validation::validate($field->getValidation(), $field->getValue())->isValid() != true) { $invalidFields[$field->getName()] = $field->getValue(); } $fields[$field->getName()] = $field->getValue(); } } if (count($invalidFields) > 0 && (!isset($post['delete']) || $post['delete'] != 1)) { return ['status' => false, 'invalidFields' => $invalidFields]; } switch ($this->getMethod()) { case self::_edit: if (isset($post['delete']) && $post['delete'] == 1) { $database->delete($this->getName(), ['ID' => $this->getID()]); $location = $this->getName(); } else { $database->update($this->getName(), $fields, ['ID' => $this->getID()]); $location = $this->getName() . '/' . $this->getMethod() . '/' . $this->getID(); } break; case self::_new: $lastInsertedID = $database->insert($this->getName(), $fields, true); $location = $this->getName() . '/' . self::_edit . '/' . $lastInsertedID; break; } return ['status' => true, 'location' => $location]; }