/** * Metodi tallentaa muistutuksen ja sen luokan tietokantaan, sekä ilmoittaa * mahdollisista virheistä. */ public static function store() { $params = $_POST; $todoAttributes = array('title' => $params['title'], 'priority' => $params['priority'], 'created_at' => date("Y-m-d H:i:s")); try { $categories = $params['categories']; } catch (Exception $e) { $categoryErrors = array(); $categoryErrors[] = 'Sinun on valittava vähintään yksi luokka.'; $categories = Category::all(); View::make('/reminders/add_reminder.html', array('categoryErrors' => $categoryErrors, 'todoAttributes' => $todoAttributes, 'categories' => $categories)); } $todo = new Todo($todoAttributes); $todoErrors = $todo->errors(); if (count($todoErrors) == 0) { $todo->save(); foreach ($categories as $category) { $todoCategory = new TodoCategory(array('todo_id' => $todo->getId(), 'category_id' => $category)); $todoCategory->save(); } Redirect::to('/reminders', array('message' => 'Muistutus lisätty onnistuneesti.')); } else { $categories = Category::all(); View::make('/reminders/add_reminder.html', array('todoErrors' => $todoErrors, 'todoAttributes' => $todoAttributes, 'categories' => $categories)); } }
/** Process the edit form */ public function update() { $todo = new Todo(array('id' => $this->params['id'])); $todo->description = $this->params['description']; $todo->done = $this->params['done']; $todo->save(); $this->redirect_to('all'); }
public function postAdd() { if (Request::ajax()) { $todo = new Todo(); $todo->title = Input::get('title'); $todo->save(); return View::make('ajaxData')->with('todo', $todo); } }
public function addAction() { $task = new Todo(); $task->title = $this->request->getPost('title'); $task->description = $this->request->getPost('description'); $task->user_id = getUserId(); $task->save(); $this->dispatcher->forward(['action' => 'index']); }
/** * Saves object-specific attributes. * * @return bool * * @see ElggObject::save() */ public function save() { $res = parent::save(); if (!$res) { return $res; } $this->updateTodoItemAccess(); return $res; }
/** * add new todo */ public function post() { $todo = new Todo(); $data = json_decode($this->app->request()->getBody()); $todo->title = (string) $data->title; $todo->done = (bool) $data->done; $todo->save(); echo $todo->to_json(); }
/** * Saves object-specific attributes. * * @internal Object attributes are saved in the objects_entity table. * * @return bool */ public function save() { // Save ElggEntity attributes if (!parent::save()) { return false; } $parent_list = $this->getContainerEntity(); $parent_list->validateListCompleteness(); return true; }
/** * 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()); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $data = Input::get(); $todo = new Todo(); $todo->content = $data['content']; $todo->save(); $arr = ['todo' => $todo, 'flash' => ['type' => 'success', 'msg' => '新增成功!']]; return Response::json($arr); }
public function actionCreate() { $model = new Todo(); if ($data = Yii::app()->getRequest()->getPost('Todo')) { $model->setAttributes($data); if ($model->save()) { Yii::app()->user->setFlash(YFlashMessages::SUCCESS_MESSAGE, 'Задача успешно добавлена'); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create'])); } } $this->render('create', ['model' => $model]); }
/** * レコード編集 */ public function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('不正なIDです', true)); $this->redirect(array('action' => 'index')); } // 値一覧のセット $this->set('valueLists', $this->Todo->valueLists); if (!empty($this->data)) { if (empty($this->data['Todo']['id'])) { $this->data['Todo']['id'] = $id; } if ($this->Todo->save($this->data)) { $this->Session->setFlash(__('TODOを保存しました', true)); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('TODOの保存に失敗しました', true)); } } if (empty($this->data)) { $this->data = $this->Todo->read(null, $id); } }
public function post_index() { $validator = Validator::make(get_object_vars(Input::json()), $this->rules); if ($validator->fails()) { return Response::json($validator->errors->all(), 400); } else { $newtodo = Input::json(); $todo = new Todo(); $todo->user_id = Auth::user()->id; $todo->title = $newtodo->title; $todo->completed = $newtodo->completed; $todo->save(); return Response::eloquent($todo); } }
public function action_do_create() { $project = Project::find(Input::get('project_id')); $new = array('title' => Input::get('title'), 'description' => Input::get('description'), 'customer_id' => $project->customer_id, 'project_id' => $project->id, 'organization_id' => Auth::user()->organization->id); $v = Todo::validate($new); if ($v->fails()) { // redirect back to the form with // errors, input and our currently // logged in user return Redirect::to_route('create_todo', $project->id)->with_errors($v)->with_input(); } // create the new post $o = new Todo($new); $o->save(); // redirect to viewing our new post return Redirect::to_route('read_customer', $project->customer_id); }
public function actionUpdate() { $postdata = file_get_contents("php://input"); $post = CJSON::decode($postdata); if (isset($post['id'])) { $model = Todo::model()->findByPk($post['id']); if ($post['note'] == '') { $model->delete(); echo "{}"; return true; } } else { $model = new Todo(); } $model->attributes = $post; $model->user_id = Yii::app()->user->id; $model->save(); echo json_encode($model->attributes); }
public function updateTodo(Todo $todo) { $inputs = ['content' => Input::get('content'), 'deadline' => Input::get('deadline'), 'priority' => Input::get('priority'), 'status' => Input::get('status'), 'user_id' => Input::get('uid'), 'author_id' => Input::get('author_uid')]; $valid = Validator::make($inputs, Todo::$rules); if ($valid->passes()) { $todo->content = $inputs['content']; $todo->deadline = $inputs['deadline']; $todo->priority = $inputs['priority']; $todo->status = $inputs['status']; $todo->user_id = $inputs['user_id']; $todo->author_id = $inputs['author_id']; if (count($todo->getDirty()) > 0) { $todo->sendNotification(self::NOTIFICATION_UPDATE_TASK); $todo->save(); return Redirect::route('todo.list')->with('success', Lang::choice('messages.Todos', 1) . ' ' . trans('messages.is updated')); } else { return Redirect::back()->with('success', trans('messages.Nothing to update')); } } else { return Redirect::back()->withErrors($valid)->withInput(); } }
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();
$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'])) { $todoModel->completed = true; $todoModel->save(); $app['session']->getFlashBag()->add('message', array('type' => "success", 'content' => "your todo has been modified")); } else { $app['session']->getFlashBag()->add('message', array('type' => "danger", 'content' => "Access denied")); } return $app->redirect('/todos'); });
/** * Add a new todo * * @param int $user_id * @param int $issue_id * @return array */ public static function add_todo($issue_id = 0) { $user_id = Auth::user()->id; // Ensure user is assigned to issue. $issue = Project\Issue::load_issue($issue_id); if (empty($issue) || $issue->assigned_to !== $user_id) { return array('success' => FALSE, 'errors' => __('tinyissue.todos_err_add')); } // Ensure issue is not already a task. $count = Todo::where('issue_id', '=', $issue_id)->where('user_id', '=', $user_id)->count(); if ($count > 0) { return array('success' => FALSE, 'errors' => __('tinyissue.todos_err_already')); } $todo = new Todo(); $todo->user_id = $user_id; $todo->issue_id = $issue_id; $todo->status = 1; $todo->save(); return array('success' => TRUE); }