Inheritance: extends yii\db\ActiveRecord
Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Building::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'cost_iron' => $this->cost_iron, 'cost_steel' => $this->cost_steel, 'cost_chemicals' => $this->cost_chemicals, 'cost_vv4a' => $this->cost_vv4a, 'cost_ice' => $this->cost_ice, 'cost_water' => $this->cost_water, 'cost_energy' => $this->cost_energy, 'cost_people' => $this->cost_people, 'cost_credits' => $this->cost_credits, 'cost_time' => $this->cost_time, 'balance_iron' => $this->balance_iron, 'balance_steel' => $this->balance_steel, 'balance_chemicals' => $this->balance_chemicals, 'balance_vv4a' => $this->balance_vv4a, 'balance_ice' => $this->balance_ice, 'balance_water' => $this->balance_water, 'balance_energy' => $this->balance_energy, 'balance_people' => $this->balance_people, 'balance_credits' => $this->balance_credits, 'balance_satisfaction' => $this->balance_satisfaction, 'storage_chemicals' => $this->storage_chemicals, 'storage_ice_and_water' => $this->storage_ice_and_water, 'storage_energy' => $this->storage_energy, 'shelter_iron' => $this->shelter_iron, 'shelter_steel' => $this->shelter_steel, 'shelter_chemicals' => $this->shelter_chemicals, 'shelter_vv4a' => $this->shelter_vv4a, 'shelter_ice_and_water' => $this->shelter_ice_and_water, 'shelter_energy' => $this->shelter_energy, 'shelter_people' => $this->shelter_people, 'highscore_points' => $this->highscore_points, 'modified' => $this->modified, 'limit' => $this->limit]);
     $query->andFilterWhere(['like', 'group', $this->group])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #2
0
 public function search($params)
 {
     $query = Building::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]);
     // load the seach form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $dateBegin = strtotime($this->date);
     $dateEnd = $dateBegin + 86400;
     // adjust the query by adding the filters
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['school_id' => $this->school_id])->andFilterWhere(['status' => $this->status])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]);
     return $dataProvider;
 }
 public function actionUpdate($id)
 {
     $model = Building::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException('未找到该学校建筑。');
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '成功更新学校建筑“' . $model->name . '”。');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', '更新学校建筑失败。');
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 public function actionBuildings($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $output = ['status' => 'ok', 'html' => ''];
     $list = Building::getKeyValuePairs($id);
     foreach ($list as $key => $name) {
         $output['html'] .= "<option value=\"{$key}\">{$name}</option>";
     }
     return $output;
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBuilding()
 {
     return $this->hasOne(Building::className(), ['id' => 'building_id']);
 }
Example #6
0
use yii\helpers\Html;
use yii\widgets\Pjax;
use yii\web\JsExpression;
use kartik\date\DatePicker;
use kartik\select2\Select2;
use common\models\Building;
use common\models\School;
$this->title = '学校建筑列表';
?>
<p>
    <?php 
echo Html::a('<i class="fa fa-plus"></i> 添加学校建筑', ['building/add'], ['class' => 'btn btn-primary']);
?>
</p>
<div class="row">
    <div class="col-lg-12">
        <?php 
Pjax::begin();
?>
        <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table table-striped table-bordered table-center'], 'summaryOptions' => ['tag' => 'p', 'class' => 'text-right text-info'], 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'headerOptions' => ['class' => 'col-md-1']], ['attribute' => 'name', 'headerOptions' => ['class' => 'col-md-3'], 'filterInputOptions' => ['class' => 'form-control input-sm']], ['attribute' => 'school_id', 'headerOptions' => ['class' => 'col-md-3'], 'filterInputOptions' => ['class' => 'form-control input-sm'], 'value' => function ($model, $key, $index, $column) {
    return $model->school->name;
}, 'filter' => Select2::widget(['model' => $searchModel, 'initValueText' => ($school = School::findOne($searchModel->school_id)) ? $school->name : '', 'attribute' => 'school_id', 'size' => Select2::SMALL, 'theme' => Select2::THEME_KRAJEE, 'options' => ['placeholder' => '搜索学校名称...'], 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 3, 'ajax' => ['url' => Url::to(['/school/name-filter']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }')], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function (store) { return store.text; }'), 'templateSelection' => new JsExpression('function (store) { return store.text; }')]])], ['attribute' => 'status', 'filter' => Building::getStatusList(), 'filterInputOptions' => ['class' => 'form-control input-sm'], 'headerOptions' => ['class' => 'col-md-1'], 'value' => function ($model, $key, $index, $column) {
    return $model->statusMsg;
}], ['attribute' => 'created_at', 'format' => ['date', 'php:Y-m-d H:i'], 'filter' => DatePicker::widget(['model' => $searchModel, 'type' => DatePicker::TYPE_COMPONENT_APPEND, 'attribute' => 'date', 'options' => ['class' => 'input-sm'], 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]), 'headerOptions' => ['class' => 'col-md-3']], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'headerOptions' => ['class' => 'col-md-1'], 'template' => '{update}']]]);
?>
        <?php 
Pjax::end();
?>
    </div>
</div>
 public function actionBuildings($id)
 {
     return Building::getKeyValuePairs($id);
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBuildings()
 {
     return $this->hasMany(Building::className(), ['school_id' => 'id']);
 }
Example #9
0
    <?php 
echo $form->field($model, 'consignee', ['template' => "{label}\n{beginWrapper}\n{beginRow}\n{beginCol}\n{input}\n{hint}\n{error}\n{endCol}\n{beginCol}\n{gender}\n{endCol}\n{endRow}\n{endWrapper}", 'parts' => ['{gender}' => Html::activeRadioList($model, 'gender', Address::getGenderList()), '{beginRow}' => '<div class="row">', '{endRow}' => '</div>', '{beginCol}' => '<div class="col-xs-6">', '{endCol}' => '</div>']]);
?>
    <?php 
echo $form->field($model, 'cellphone');
?>
    <?php 
echo $form->field($model, 'school_id')->dropDownList(School::getKeyValuePairs());
?>
    <div class="form-group">
        <label class="col-md-2 control-label">收货地址</label>
        <div class="col-md-8">
            <div class="row">
                <div class="col-xs-6">
                    <div class="col-md-12"><?php 
echo $form->field($model, 'building_id', ['template' => "{input}\n{hint}\n{error}"])->dropDownList(Building::getKeyValuePairs($model->school_id));
?>
</div>
                </div>
                <div class="col-xs-6">
                    <div class="col-md-12"><?php 
echo $form->field($model, 'room', ['template' => "{input}\n{hint}\n{error}"])->textInput(['placeholder' => '房间、地点等']);
?>
</div>
                </div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-8"><?php 
echo Html::submitButton('<i class="fa fa-save"></i> 保存', ['class' => 'btn btn-warning']);
Example #10
0
 /**
  * Finds the Building model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Building the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Building::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }