Exemple #1
0
 /**
  * Deletes an existing Task model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id = null, array $ids = null)
 {
     $ok_message = false;
     if (!$id && $ids) {
         // multiple
         if (Task::deleteAll(['id' => $ids])) {
             $ok_message = __('Items have been deleted successfully.');
         }
     } elseif ($this->findModel($id)->delete()) {
         // single
         $ok_message = __('Item has been deleted successfully.');
     }
     if ($ok_message) {
         Yii::$app->session->setFlash('success', $ok_message);
         // if ($referrer = Yii::$app->request->referrer) {
         //     return $this->redirect($referrer);
         // }
     }
     return $this->redirect(['index']);
 }
 /**
  * Deletes an existing Task model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $parent_id = $model->id;
     if (!empty($model) && $model->task_from == Yii::$app->user->getId()) {
         if ($model->delete()) {
             if (!empty($model->attachment)) {
                 @unlink('uploads/' . $old_attachment);
             }
             $detil = Task::find(['parent_task_id' => $parent_id])->all();
             if (!empty($detil)) {
                 foreach ($detil as $attachmentItem) {
                     if (!empty($attachmentItem->attachment)) {
                         @unlink('uploads/' . $attachmentItem->attachment);
                     }
                 }
                 Task::deleteAll('parent_task_id = :parent_task_id', [':parent_task_id' => $parent_id]);
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Tugas Berhasil Dihapus'));
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Tugas Gagal Dihapus'));
         }
     }
     return $this->redirect(['index']);
 }