/** * Creates a new Order model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Order(); $session = Yii::$app->session; if ($model->load(Yii::$app->request->post())) { $model->setIsNewRecord(true); $model->createTime = date('Y-m-d H:i:s'); $model->session = $session->get('session_order'); $model->fullCost = $session->get('fullcost'); $model->save(); $fullCart = $session['cart']; $fioCart = $session['cart_fio']; if ($fullCart && $fioCart) { for ($i = 0; $i < $session->get('cards'); $i++) { $inOrder = new Inorder(); $inOrder->setIsNewRecord(true); $inOrder->orderID = $model->id; $inOrder->cardID = $session['cart'][$i]; $thisCard = Cards::find()->where(['id' => $session['cart'][$i]])->one(); $inOrder->cost = $thisCard->cost; $inOrder->fio = $session['cart_fio'][$i]; $inOrder->save(); } } $session->remove('cards'); $session->remove('session_order'); $session->remove('cart'); $session->remove('fullcost'); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Cards::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'cardTypeID' => $this->cardTypeID, 'clubID' => $this->clubID, 'cost' => $this->cost]); $query->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getcards() { return $this->hasOne(Cards::className(), ['ID_Holder' => 'ID']); }
public function actionCards() { if (Yii::$app->request->isAjax) { $clubID = Yii::$app->request->get('club'); if ($cards = Cards::find()->where(['clubID' => $clubID])->asArray()->all()) { return json_encode($cards, JSON_UNESCAPED_UNICODE); } else { return 'No cards in this club.'; } } return $this->redirect('index'); }
/** * @return \yii\db\ActiveQuery */ public function getCards() { return $this->hasMany(Cards::className(), ['clubID' => 'id']); }
/** * Finds the Cards model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Cards the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Cards::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/* @var $searchModel app\models\SearchCards */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Карты'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="cards-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Добавить карту', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'cardTypeID', 'label' => 'Тип карты', 'format' => 'text', 'content' => function ($data) { return $data->getTypesName(); }, 'filter' => \app\models\Cards::getTypesList()], ['attribute' => 'clubID', 'label' => 'Клуб', 'format' => 'text', 'content' => function ($data) { return $data->getClubsName(); }, 'filter' => \app\models\Cards::getClubsList()], 'cost', 'header', ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
<div class="row row-offcanvas row-offcanvas-right"> <div class="col-xs-12 col-sm-9"> <p class="pull-right visible-xs"> <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Меню</button> </p> <div class="row"> </div><!--/row--> </div><!--/span--> <?php $cities = \app\models\City::find()->count(); $clubs = \app\models\Clubs::find()->count(); $cards = \app\models\Cards::find()->count(); $types = \app\models\Types::find()->count(); $orders = \app\models\Order::find()->count(); $viziting = \app\models\Viziting::find()->count(); $duration = \app\models\Duration::find()->count(); ?> <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation"> <div class="list-group"> <?php if (Yii::$app->user->identity->username == "admin") { echo '<a href="/city" class="list-group-item">Города (' . $cities . ')</a> <a href="/clubs" class="list-group-item">Клубы (' . $clubs . ')</a> <a href="/cards" class="list-group-item">Карты (' . $cards . ')</a> <a href="/types" class="list-group-item">Типы карт (' . $types . ')</a> <a href="/viziting" class="list-group-item">Время посещений (' . $viziting . ')</a>