Esempio n. 1
0
 /**
  * Delete the to-do item
  *
  * @return bool
  *
  * @see ElggEntity::delete()
  */
 public function delete($recursive = true)
 {
     // notify about delete
     $acting_user = elgg_get_logged_in_user_entity();
     $subject = elgg_echo('todos:notify:todoitem:delete:subject', array($this->title));
     $message = elgg_echo('todos:notify:todoitem:delete:message', array($acting_user->name, $this->title));
     $this->notifyUsers($subject, $message);
     return parent::delete();
 }
Esempio n. 2
0
include 'templates/includes.php';
?>
        <?php 
// Declare the post variables we will be looking for
$args = array("_id" => FILTER_SANITIZE_STRING, "description" => FILTER_SANITIZE_STRING);
// Get our post variables using the arguments above (this method is much safer than $_POST)
$post_vars = filter_input_array(INPUT_POST, $args, false);
// Get the action veriable from our post data
$action = filter_input(INPUT_POST, "action", FILTER_SANITIZE_STRING);
// Create our Todo object. If the _id sent in the post data isn't set then the Todo is blank
$todo = new Todo($post_vars["_id"]);
$foodMenu = new FoodItem($post_vars["_id"]);
// Typical switch statement calling our functions from the Todo object
switch ($action) {
    case "remove":
        $todo->delete();
        break;
    case "add":
        $foodMenu->addToMenu();
        break;
    case "edit":
        $todo->setDescription($post_vars["description"]);
        $todo->store();
        break;
    case "done":
        $todo->done();
        $todo->store();
        break;
}
// This creates a cursor of all the Todo items in our database
$todoCursor = new TodoCursor();
Esempio n. 3
0
    if (!empty($todoModel->description)) {
        $todoModel->Save();
        $app['session']->getFlashBag()->add('message', array('type' => "success", 'content' => "your todo has been added"));
    } else {
        $app['session']->getFlashBag()->add('message', array('type' => "danger", 'content' => "your todo hasn't been added"));
    }
    return $app->redirect('/todos');
});
$app->match('/todo/delete/{id}', 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'])) {
        if ($todoModel->delete()) {
            $app['session']->getFlashBag()->add('message', array('type' => "sucess", 'content' => "your todo has been deleted"));
        } else {
            $app['session']->getFlashBag()->add('message', array('type' => "danger", 'content' => "your todo hasn't been deleted"));
        }
    } else {
        $app['session']->getFlashBag()->add('message', array('type' => "danger", 'content' => "Access denied"));
    }
    return $app->redirect('/todos');
});
$app->match('/todo/edit/{id}', function ($id) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    $todoModel = new Todo($app, $id);
    if ($todoModel->hasAcces($user['id'])) {
Esempio n. 4
0
<?php

require_once "api/database.php";
require_once "api/todo.php";
$todo = new Todo();
switch ($_SERVER['REQUEST_METHOD']) {
    case 'GET':
        $params = str_replace('/', '', $_SERVER['QUERY_STRING']);
        parse_str($params, $params);
        $todo->read($params);
        break;
    case 'PUT':
        parse_str(file_get_contents('php://input'), $p_data);
        $object = json_decode(stripslashes($p_data['model']), true);
        $todo->update($object);
        break;
    case 'POST':
        $object = json_decode(stripslashes($_POST['model']), true);
        $todo->create($object);
        break;
    case 'DELETE':
        $id = (int) str_replace('/', '', $_SERVER['QUERY_STRING']);
        $todo->delete($id);
        break;
}
    }
    return $app->redirect('/todo');
});
$app->post('/todo/update/{id}', function (Request $request, $id) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    if ($id) {
        $int_id = (int) $id;
        $completed = $request->request->get('completed');
        if ($completed === 'c') {
            // Make sure we added user_id to query so users can only change their own
            $sql = 'UPDATE todos SET status = "c" WHERE id = ? AND user_id = ?';
            // Protect against SQL injection
            $app['db']->executeUpdate($sql, [$int_id, $user['id']]);
        }
        return $app->redirect("/todo/{$int_id}");
    }
    return $app->redirect('/todo');
})->value('id', null);
$app->match('/todo/delete/{id}', function ($id) use($app) {
    if (null === ($user = $app['session']->get('user'))) {
        return $app->redirect('/login');
    }
    $todo = new Todo($app);
    $operation_status = $todo->delete(['id' => $id, 'user_id' => $user['id']]);
    if ($operation_status) {
        $app['session']->getFlashBag()->add('success_confirmation', 'Successfully deleted todo');
    }
    return $app->redirect('/todo');
});
Esempio n. 6
0
//submit/update an item
if (isset($_POST) && isset($_POST['title'])) {
    if ($_POST['title']) {
        $title = strip_tags(stripslashes($_POST['title']));
        if (isset($_POST['id'])) {
            Todo::update($_POST['id'], $title);
        } else {
            Todo::create($title);
        }
    }
    refresh();
}
//delete an item
if (isset($_GET['delete']) && isset($_GET['id'])) {
    if (filter_var($_GET['id'], FILTER_VALIDATE_INT)) {
        Todo::delete($_GET['id']);
        refresh();
    }
}
//view a single item
if (isset($_GET['id'])) {
    $id = stripslashes(strip_tags($_GET['id']));
    if (filter_var($id, FILTER_VALIDATE_INT)) {
        try {
            $item = Todo::read($id);
        } catch (Exception $e) {
        }
    }
}
//changes to update mode
if (isset($_GET['update']) && isset($_GET['item_id'])) {
 public function destroy(Organization $org, Todo $todo)
 {
     $todo->delete();
     return Response::json(null, 204);
 }
 /** removes an item from the DB */
 public function delete()
 {
     $todo = new Todo(array('id' => $this->params['id']));
     $todo->delete();
     $this->redirect_to('all');
 }
Esempio n. 9
0
 public function deleteTodo(Todo $todo)
 {
     $todo->delete();
     return Redirect::route('todo.list')->with('success', Lang::choice('messages.Todos', 1) . ' ' . trans('messages.is deleted'));
 }