/** * Retrieve the details for a specific commodity * @param integer $id * @return array */ public function actionView($id = NULL) { if ($id === NULL) { throw new HttpException(400, 'Missing ID parameter'); } $query = Station::find()->where(['id' => $id]); return ResponseBuilder::build($query, 'stations', Yii::$app->request->get('sort', 'name'), Yii::$app->request->get('order', 'asc')); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Station::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(['station_id' => $this->station_id]); $query->andFilterWhere(['like', 'station_name', $this->station_name]); return $dataProvider; }
$this->title = 'Wagons'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="wagon-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::button('Thêm toa', ['value' => Url::to('wagon/create'), 'class' => 'btn btn-success', 'id' => 'modalButton']); ?> </p> <?php Modal::begin(['header' => '<h4>THÊM TOA XE</h4>', 'id' => 'modal', 'size' => 'modal-lg']); echo "<div id='modalContent'></div>"; Modal::end(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'wagon_number', 'created_year', ['attribute' => 'start_date', 'value' => 'start_date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'start_date', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], ['attribute' => 'wagon_status_id_status', 'value' => 'wagonStatusIdStatus.name_of_status', 'filter' => Html::activeDropDownList($searchModel, 'wagon_status_id_status', ArrayHelper::map(WagonStatus::find()->all(), 'status_id', 'name_of_status'), ['class' => 'form-control', 'prompt' => 'Please select...'])], ['attribute' => 'station_station_id', 'value' => 'stationStation.station_name', 'filter' => Html::activeDropDownList($searchModel, 'station_station_id', ArrayHelper::map(\app\models\Station::find()->all(), 'station_id', 'station_name'), ['class' => 'form-control', 'prompt' => 'Please select...'])], ['attribute' => 'kind_of_wagon_kind_id', 'value' => 'kindOfWagonKind.kind_name', 'filter' => Html::activeDropDownList($searchModel, 'kind_of_wagon_kind_id', ArrayHelper::map(\app\models\KindOfWagon::find()->all(), 'kind_id', 'kind_name'), ['class' => 'form-control', 'prompt' => 'Please select...'])], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
<?php echo $form->field($model, 'created_year')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'start_date')->widget(DatePicker::className(), ['inline' => false, 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]); ?> <?php echo $form->field($model, 'wagon_status_id_status')->dropDownList(ArrayHelper::map(WagonStatus::find()->all(), 'status_id', 'name_of_status'), ['prompt' => 'Trạng thái toa...']); ?> <?php echo $form->field($model, 'station_station_id')->dropDownList(ArrayHelper::map(Station::find()->all(), 'station_id', 'station_name'), ['prompt' => 'Chọn ga...']); ?> <?php echo $form->field($model, 'kind_of_wagon_kind_id')->dropDownList(ArrayHelper::map(KindOfWagon::find()->all(), 'kind_id', 'kind_name'), ['prompt' => 'Chọn loại toa...']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end();
/** * The object parser for EDDB stations * @return function */ private function getStationsObjectParser() { return function ($obj) { // Remove keys we don't want, and extract them as variables to the symbols table $exportKeys = ['economies', 'listings', 'import_commodities', 'export_commodities', 'prohibited_commodities', 'updated_at']; foreach ($exportKeys as $key) { ${$key} = $obj[0][$key]; unset($obj[0][$key]); } $model = Station::find()->where(['id' => $obj[0]['id']])->one(); if ($model === NULL) { $model = new Station(); } else { if ($model->updated_at + 43200 >= time()) { // If the model is less than 12 hours old, skip it. $this->stdOut('.'); return; } } $this->stdOut('Importing station: '); $this->stdOut("{$obj[0]['name']} :: {$obj[0]['id']}\n", Console::BOLD); // Update the stations listing foreach ($obj[0] as $name => $value) { if ($model->hasAttribute($name)) { $model->{$name} = $value; } } $model->save(); $db = Yii::$app->db; // Update the economies listing $db->createCommand('DELETE FROM station_economies WHERE station_id = :station_id')->bindValue(':station_id', $obj[0]['id'])->execute(); foreach ($economies as $economy) { $model = new StationEconomy(); $model->attributes = ['station_id' => $obj[0]['id'], 'name' => $economy]; $model->save(); } foreach (['listings', 'import_commodities', 'export_commodities', 'prohibited_commodities'] as $k) { $this->importStationCommodity($obj[0], $k, new StationCommodity(), ${$k}); } }; }