Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace backend\controllers;
- use Yii;
- use backend\models\Zayvki;
- use backend\models\ZayvkiSearch;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use backend\models\Order;
- use backend\models\OrderForm;
- use backend\models\Category;
- use backend\models\Uslugi;
- /**
- * ZayvkiController implements the CRUD actions for Zayvki model.
- */
- class ZayvkiController extends Controller
- {
- /**
- * {@inheritdoc}
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
- /**
- * Lists all Zayvki models.
- * @return mixed
- */
- public function actionIndex()
- {
- $searchModel = new ZayvkiSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- ]);
- }
- /**
- * Displays a single Zayvki model.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * Creates a new Zayvki model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new Zayvki();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- $order = new Order();
- $order->load(Yii::$app->request->post());
- $order->uslugi_id = Yii::$app->request->post('Zayvki')['uslugi_id'];
- $order->hours = Yii::$app->request->post('Zayvki')['hours'];
- $order->date = Yii::$app->request->post('Zayvki')['date'];
- $order->category_id = 3;
- $order->link('zayvki', $model);
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- public function actionCreateiko()
- {
- $model = new Zayvki();
- $orders = [new OrderForm()];
- if ($model->load(Yii::$app->request->post()) && $model->save())
- {
- foreach(Yii::$app->request->post('OrderForm', []) as $form) {
- foreach ($form['uslugi_id'] as $service) {
- $order = new Order();
- $order->category_id =$form['category_id'];
- $order->uslugi_id = $service;
- $order->link('zayvki', $model);
- }
- }
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('createiko', [
- 'model' => $model,
- 'orders' => $orders,
- ]);
- }
- /**
- * Updates an existing Zayvki model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- }
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- /**
- * Deletes an existing Zayvki model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- /**
- * Finds the Zayvki model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Zayvki the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = Zayvki::findOne($id)) !== null) {
- return $model;
- }
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- public function actionGetCategory($q = null, $uslugi_id = null)
- {
- $response = Yii::$app->response;
- $response->format = \yii\web\Response::FORMAT_JSON;
- $query = Category::find()
- ->asArray()
- ->select(['category.id', 'category.name AS text']);
- if ($uslugi_id) {
- $query->join('join', 'usligi rs', 'category.id = rs.category_id')
- ->andWhere(['rs.id' => $uslugi_id]);
- }
- $query->andFilterWhere(['like', 'category.name', $q]);
- $data = $query->orderBy('category.name ASC')->limit(20)->all();
- $out['results'] = array_values($data);
- return $out;
- }
- public function actionGetService($q = null, $category_id = null)
- {
- $response = Yii::$app->response;
- $response->format = \yii\web\Response::FORMAT_JSON;
- $query =Uslugi::find()
- ->asArray()
- ->select(['uslugi.id', 'uslugi.usluginame AS text']);
- if (null !== $category_id ) {
- $query->join('join', 'category cat', 'uslugi.category_id = cat.id')
- ->andWhere(['cat.id' => $category_id]);
- }
- $data = $query->orderBy('uslugi.usluginame ASC')->limit(20)->all();
- $out['results'] = array_values($data);
- return $out;
- }
- }
Add Comment
Please, Sign In to add comment