/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validation = Validator::make(['subtask_name' => Input::get('subtask_name'), 'subtask_desc' => Input::get('subtask_desc')], ['subtask_name' => 'required|min:4|max:20', 'subtask_desc' => 'min:5|max:40']); if ($validation->fails()) { return 'Validation Error'; } else { $subtask_name = Input::get('subtask_name'); $subtask_desc = Input::get('subtask_desc'); $task_id = Input::get('task_id'); $token = Input::get('token'); try { $subtask = new Subtask(); $subtask->task_id = $task_id; $subtask->subtask_title = $subtask_name; $subtask->subtask_desc = $subtask_desc; $subtask->completed = 0; $subtask->save(); return Redirect::route('dashboard', array($token)); } catch (Exception $e) { echo $e; } } // return Input::all(); }
public function fetchSubtasksForTree($task_id) { $subtask_info = Subtask::where('task_id', '=', $task_id)->get(); return $subtask_info; }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (!Yii::app()->user->checkAccess('Manager') && !Yii::app()->user->checkAccess('Admin')) { throw new CHttpException(403, 'You are not authorized to perform this action.'); } $model = $this->loadModel($id); // Check whether this project owned by login user if ($model->creator_id != Yii::app()->user->id) { throw new CHttpException(403, 'This is not your project!'); } $model->deleted = 1; if ($model->save()) { echo $model->name . ' : ' . $model->deleted . '<br>'; // Delete all its tasks and subtasks $tasks = Task::model()->findAll(array('condition' => 'project_id=' . $id . ' AND deleted=0')); foreach ($tasks as $task) { $subtasks = Subtask::model()->findAll(array('condition' => 'task_id=' . $task->id . ' AND deleted=0')); $task->deleted = 1; $task->save(); echo '-' . $task->title . ' : ' . $task->deleted . '<br>'; foreach ($subtasks as $subtask) { $subtask->deleted = 1; $subtask->save(); echo '--' . $subtask->title . ' : ' . $subtask->deleted . '<br>'; } } } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } }