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/"); } }
function edit_POST($w) { $p = $w->pathMatch("id"); $task = !empty($p["id"]) ? $w->Task->getTask($p["id"]) : new Task($w); $taskdata = null; if (!empty($p["id"])) { $taskdata = $w->Task->getTaskData($p['id']); } $task->fill($_POST['edit']); $task->assignee_id = intval($_POST['edit']['assignee_id']); if (empty($task->dt_due)) { $task->dt_due = $w->Task->getNextMonth(); } $task->insertOrUpdate(); // Tell the template what the task id is (this post action is being called via ajax) $w->setLayout(null); $w->out($task->id); // Get existing task_data objects for this task and update them $existing_task_data = $w->Task->getTaskData($task->id); if (!empty($existing_task_data)) { foreach ($existing_task_data as $e_task_data) { foreach ($_POST["extra"] as $key => $data) { if ($key == \CSRF::getTokenId()) { unset($_POST["extra"][\CSRF::getTokenID()]); continue; } if ($e_task_data->data_key == $key) { $e_task_data->value = $data; $e_task_data->update(); unset($_POST["extra"][$key]); continue; } // If we get here then remove the existing data? // $e_task_data->delete(); } } } // Insert data that didn't exist above as new task_data objects if (!empty($_POST["extra"])) { foreach ($_POST["extra"] as $key => $data) { $tdata = new TaskData($w); $tdata->task_id = $task->id; $tdata->data_key = $key; $tdata->value = $data; $tdata->insert(); } } }
/** * * Set an extra data value field * * @param unknown_type $key * @param unknown_type $value */ function setDataValue($key, $value) { if ($this->id) { $c = $this->Task->getObject("TaskData", array("task_id" => $this->id, "data_key" => $key)); if ($c) { $c->value = $value; $c->update(); } else { $c = new TaskData($this->w); $c->data_key = $key; $c->value = $value; $c->task_id = $this->id; $c->insert(); } } }