Ejemplo n.º 1
0
 /**
  * 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];
 }
Ejemplo n.º 2
0
 /**
  * @param $username
  * @return bool
  */
 public function deleteUser($username)
 {
     return $this->database->delete("users", array("username" => $username));
 }