/** removes an item from the DB */
 public function checkbox()
 {
     $todo = Todo::find($this->params['id']);
     $todo->done = $todo->done ? 0 : 1;
     $todo->save();
     $this->redirect_to('all');
 }
Exemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $todo = Todo::find($id);
     $todo->done = Request::input('done');
     $todo->save();
     return $todo;
 }
Exemplo n.º 3
0
 public function indexAction()
 {
     $todos = Todo::find(array(array()));
     foreach ($todos as $todo) {
         //$todo->delete();
     }
     $this->view->todos = Todo::find();
 }
Exemplo n.º 4
0
 public function action_create($todo_id = false)
 {
     if ($todo_id == false) {
         die("error");
     }
     $report = new Report();
     $todo = Todo::find($todo_id);
     return View::make('report.create')->with('report', $report)->with('todo', $todo);
 }
 public function getDone($id)
 {
     if (Request::ajax()) {
         $task = Todo::find($id);
         $task->status = (int) $task->status == 1 ? 0 : 1;
         $task->save();
         return 'OK';
     }
 }
 /**
  * update todo
  */
 public function put()
 {
     $data = json_decode($this->app->request()->getBody());
     $todo = Todo::find((int) $data->id);
     $todo->title = (string) $data->title;
     $todo->done = (bool) $data->done;
     $todo->save();
     echo $todo->to_json();
 }
Exemplo n.º 7
0
 public function delete_index($id = null)
 {
     $todo = Todo::find($id);
     if ($todo->user_id != Auth::user()->id) {
         return Response::json('You are not the owner of this todo', 404);
     }
     if (is_null($todo)) {
         return Response::json('Todo not found', 404);
     }
     $deletedtodo = $todo;
     $todo->delete();
     return Response::eloquent($deletedtodo);
 }
Exemplo n.º 8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $todo = Todo::find(1);
     $todo->delete();
     return Redirect::route('users.show');
 }
Exemplo n.º 9
0
    if ($todoModel->hasAcces($user['id'])) {
        $todo = $todoModel->find($id);
        return $app['twig']->render('todo.html', ['todo' => $todo]);
    } else {
        $app['session']->getFlashBag()->add('message', array('type' => "danger", 'content' => "Access denied"));
        return $app->redirect('/todos');
    }
})->value('id', null);
$app->get('/todo/{id}/json', function ($id) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    $todoModel = new Todo($app);
    $todoModel->id = $id;
    if ($todoModel->hasAcces($user['id'])) {
        $todo = $todoModel->find($id);
    } else {
        $todo = "access denied";
    }
    return $app->json($todo, 200);
})->value('id', null);
$app->post('/todo/add', function (Request $request) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    $todoModel = new Todo($app);
    $todoModel->user_id = $user['id'];
    $todoModel->description = $request->get('description');
    if (!empty($todoModel->description)) {
        $todoModel->Save();
        $app['session']->getFlashBag()->add('message', array('type' => "success", 'content' => "your todo has been added"));
Exemplo n.º 10
0
 public function action_read($id)
 {
     // this is our single view
     $todo = Todo::find($id)->with('reports');
     return View::make('todo.view')->with('todo', $todo);
 }
Exemplo n.º 11
0
ActiveRecord\Config::initialize(function ($cfg) {
    $cfg->set_connections(array('development' => 'mysql://root:@localhost/todos'));
});
$app = new Slim();
function reqBody()
{
    global $app;
    return json_decode($app->request()->getBody(), true);
}
$app->get('/json', function () {
    echo json_encode(array_map(function ($todo) {
        return $todo->attributes();
    }, Todo::all()));
});
$app->post('/json', function () {
    $todo = new Todo(reqBody());
    $todo->save();
});
$app->get('/json/:id', function ($id) {
    echo Todo::find($id)->to_json();
});
$app->put('/json/:id', function ($id) {
    Todo::find($id)->update_attributes(reqBody());
});
$app->delete('/json/:id', function ($id) {
    Todo::find($id)->delete();
});
$app->get('/', function () {
    echo file_get_contents('index.html');
});
$app->run();
Exemplo n.º 12
0
 public static function find_not_done()
 {
     return Todo::find('all', array('condition' => 'done=0'));
 }
Exemplo n.º 13
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $this->todo->find($id)->delete();
     return Redirect::route('user.todos.index');
 }
Exemplo n.º 14
0
 /**
  * Show the form for editing the specified todo.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $todo = Todo::find($id);
     return View::make('todos.edit', compact('todo'));
 }
 /**
  * docs function
  */
 public function index()
 {
     $todos = Todo::find('all');
     $this->app->render('todo/index.php');
 }
Exemplo n.º 16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $todo = Todo::find($id);
     $todo->delete();
     $arr = ['flash' => ['type' => 'success', 'msg' => '待辦事項已刪除!']];
     return Response::json($arr);
 }
Exemplo n.º 17
0
 /**
  * Todoを削除する。
  *
  * @param  integer  $id  TodoのID
  * @return void
  */
 public function delete($id)
 {
     // Todoモデルを取得する
     $todo = Todo::find($id);
     // データを削除する(SQL発行)
     $todo->delete();
     // リストページにリダイレクトする
     return Redirect::route('todos.index');
 }