Beispiel #1
0
 private function getParams(Todo $todo)
 {
     $params = array(':id' => $todo->getId(), ':priority' => $todo->getPriority(), ':created_on' => self::formatDateTime($todo->getCreatedOn()), ':last_modified_on' => self::formatDateTime($todo->getLastModifiedOn()), ':due_on' => self::formatDateTime($todo->getDueOn()), ':title' => $todo->getTitle(), ':description' => $todo->getDescription(), ':comment' => $todo->getComment(), ':status' => $todo->getStatus(), ':deleted' => $todo->getDeleted());
     if ($todo->getId()) {
         // unset created date, this one is never updated
         unset($params[':created_on']);
     }
     return $params;
 }
 /**
  * Metodi päivittää muistutuksen ja sen luokan tiedot uusilla tiedoilla.
  * 
  * @param type $id  muistutuksen id
  */
 public static function update($id)
 {
     $params = $_POST;
     $todoAttributes = array('todoId' => $params['todo_id'], 'title' => $params['title'], 'priority' => $params['priority'], 'created_at' => date("Y-m-d H:i:s"));
     $todo = new Todo($todoAttributes);
     try {
         $categories = $params['categories'];
     } catch (Exception $e) {
         $categoryErrors = array();
         $categoryErrors[] = 'Sinun on valittava vähintään yksi luokka.';
         $categories = Category::all();
         View::make('/reminders/edit_reminder.html', array('categoryErrors' => $categoryErrors, 'todoAttributes' => $todoAttributes, 'todo' => $todo, 'categories' => $categories));
     }
     $todoErrors = $todo->errors();
     if (count($todoErrors) == 0) {
         $todo->update();
         $todoCategory = new TodoCategory(array('todo_id' => $todo->getId()));
         $todoCategory->destroy();
         foreach ($categories as $category) {
             $todoCategory = new TodoCategory(array('todo_id' => $todo->getId(), 'category_id' => $category));
             $todoCategory->save();
         }
         Redirect::to('/reminders', array('message' => 'Muistutusta muokattu onnistuneesti'));
     } else {
         $categories = Category::all();
         View::make('/reminders/edit_reminder.html', array('categories' => $categories, 'todoErrors' => $todoErrors, 'todo' => $todoAttributes, 'category' => $categoryAttributes));
     }
 }
Beispiel #3
0
$errors = array();
$todo = null;
$edit = array_key_exists('id', $_GET);
if ($edit) {
    $todo = Utils::getTodoByGetId();
} else {
    // set defaults
    $todo = new Todo();
    $todo->setPriority(Todo::PRIORITY_MEDIUM);
    $dueOn = new DateTime("+1 day");
    $dueOn->setTime(0, 0, 0);
    $todo->setDueOn($dueOn);
}
if (array_key_exists('cancel', $_POST)) {
    // redirect
    Utils::redirect('detail', array('id' => $todo->getId()));
} elseif (array_key_exists('save', $_POST)) {
    // for security reasons, do not map the whole $_POST['todo']
    $data = array('title' => $_POST['todo']['title'], 'due_on' => $_POST['todo']['due_on_date'] . ' ' . $_POST['todo']['due_on_hour'] . ':' . $_POST['todo']['due_on_minute'] . ':00', 'priority' => $_POST['todo']['priority'], 'description' => $_POST['todo']['description'], 'comment' => $_POST['todo']['comment']);
    // map
    TodoMapper::map($todo, $data);
    // validate
    $errors = TodoValidator::validate($todo);
    // validate
    if (empty($errors)) {
        // save
        $dao = new TodoDao();
        $todo = $dao->save($todo);
        Flash::addFlash('TODO saved successfully.');
        // redirect
        Utils::redirect('detail', array('id' => $todo->getId()));