/**
  * Displays a single Task model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $searchModel = new TaskDetailSearch();
     $dataProvider = $searchModel->searchChild($model->id);
     return $this->render('view', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Esempio n. 2
0
 public function actionReplyUpdate($id)
 {
     $model = $this->findModel($id);
     $id = $model->parent_task_id;
     $old_attachment = $model->attachment;
     if (!empty($model)) {
         $parentTask = $this->findModelReplyTask($model->parent_task_id);
         $searchModel = new TaskDetailSearch();
         $dataProvider = $searchModel->search($model->parent_task_id);
         if (Yii::$app->request->isPost) {
             if ($model->load(Yii::$app->request->post())) {
                 $model->attachment = UploadedFile::getInstance($model, 'attachment');
                 $model->task_start = date('Y-m-d', strtotime($model->task_start));
                 $model->task_end = date('Y-m-d', strtotime($model->task_end));
                 if ($model->attachment) {
                     $fileName = sprintf('%s.%s', $model->task_to . time(), $model->attachment->extension);
                     $model->attachment->saveAs('uploads/' . $fileName);
                     $model->attachment = $fileName;
                 } else {
                     $model->attachment = $old_attachment;
                 }
                 if ($model->validate() && $model->save()) {
                     if (strcmp($model->attachment, $old_attachment) !== 0) {
                         @unlink('uploads/' . $old_attachment);
                     }
                     Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Detil Tugas Berhasil Diubah'));
                     return $this->redirect(['reply-task', 'id' => $id]);
                 } else {
                     Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Detil Tugas Gagal Diubah'));
                 }
             }
         }
         return $this->render('task-create-detail', ['model' => $model, 'parentTask' => $parentTask, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     }
 }