fitness-web/backend/controllers/ProcurementController.php
2015-09-25 08:57:05 +02:00

128 lines
3.3 KiB
PHP

<?php
namespace backend\controllers;
use Yii;
use common\models\Procurement;
use backend\models\ProcurementSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Warehouse;
/**
* ProcurementController implements the CRUD actions for Procurement model.
*/
class ProcurementController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all Procurement models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ProcurementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Procurement model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Procurement model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Procurement();
$model->id_user = Yii::$app->user->id;
$warehouses = Warehouse::read(null);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_procurement]);
} else {
return $this->render('create', [
'model' => $model,
'warehouses' =>$warehouses
]);
}
}
/**
* Updates an existing Procurement model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_procurement]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Procurement model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Procurement model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Procurement the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Procurement::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}