function createtask_POST(Web &$w) { $w->Task->navigation($w, "Create Task"); // unserialise input from step I and store in array: arr_req $arr_req = unserialize($w->request('formone')); // set relevant dt variables with: Today. $arr_req['dt_assigned'] = Date('c'); $arr_req['dt_first_assigned'] = Date('c'); // insert Task into database $task = new Task($w); $task->fill($arr_req); $task->insert(); // if insert is successful, store additional fields as task data // we do not want to store data from step I, the task_id (as a key=>value pair) nor the FLOW_SID if ($task->id) { foreach ($_POST as $name => $value) { if ($name != "formone" && $name != "FLOW_SID" && $name != "task_id" && $name !== CSRF::getTokenID()) { $tdata = new TaskData($w); $arr = array("task_id" => $task->id, "key" => $name, "value" => $value); $tdata->fill($arr); $tdata->insert(); unset($arr); } } // return to task dashboard $w->msg("Task " . $task->title . " added", "/task/viewtask/" . $task->id); } else { // if task insert was unsuccessful, say as much $w->msg("The Task could not be created. Please inform the IT Group", "/task/index/"); } }
/** * Update the specified resource in storage. * PUT /tasks/{id} * * @param Project $project, Task $task * @return Response */ public function update(Project $project, Task $task) { $input = array_except(Input::all(), '_method'); $task->fill($input); if ($task->updateUniques()) { return Redirect::route('projects.tasks.show', [$project->slug, $task->slug])->with('message', 'Task updated.'); } else { return Redirect::route('projects.tasks.edit', [$project->slug, array_get($task->getOriginal(), 'slug')])->withInput()->withErrors($task->errors()); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $task = new Task(); $task->unguard(); $task->fill(Input::only(['name', 'user_id', 'description', 'status'])); $task->deadline = new DateTime(Input::get('deadline')); if ($task->validate()) { $task->save(); } else { return View::make('tasks.edit', ['task' => $task])->withErrors($task->validator()); } return Redirect::to(route('tasks.index'))->with('message', ['content' => 'Taak met succes aangemaakt!', 'class' => 'success']); }
<?php # new_task.php # 1. logic $project = new Project(); $project->load(['slug' => Route::param('slug')]); if (Input::posted()) { $task = new Task(); $task->fill(Input::all()); $task->user_id = Auth::user_id(); $task->project_id = $project->id; if (Input::get('name') != "" || Input::get('description') != "") { $task->save(); } } URL::redirect('/' . $project->slug);