/**
  * 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));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $todo = new Todo($input);
     if ($todo->save()) {
         return Redirect::route('users.show')->with('message', 'task created.');
     } else {
         return Redirect::route('todo.create')->withInput()->withErrors($todo->errors());
     }
 }