public function postDestroy()
 {
     $warranty = Warranty::find(Input::get('id'));
     if ($warranty) {
         $warranty->delete();
         return Redirect::to('warranty')->with('message', 'Request Deleted');
     }
     return Redirect::to('warranty')->with('message', 'Something went wrong, please try again');
 }
 /**
  * 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)
 {
     $model = $this->loadModel($id);
     if ($model->person->company_id == User::getMyCompany() || Yii::app()->user->role == 1) {
         if (file_exists('images/barcode/' . $model->barcode . '.png')) {
             unlink('images/barcode/' . $model->barcode . '.png');
         }
         /*Убиваем гарантии. Если нет железяки, то и гарантия нах не нужна*/
         $warranties = Warranty::model()->findAllByAttributes(array('dev_id' => $id));
         if (!empty($warranties)) {
             foreach ($warranties as $warranty) {
                 $warranty->delete();
             }
         }
         $model->delete();
         // 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'));
         }
     } else {
         throw new CHttpException(403, 'У вас нет прав в этой организации');
     }
 }
 public function getView($id)
 {
     return View::make('warranties.view')->with('warranty', Warranty::find($id));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Warranty the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Warranty::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }