コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Building::find();
     $query->select(['id', 'address', "ST_X(location)||','||ST_Y(location) as location"]);
     $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]);
     $query->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'location', $this->location]);
     return $dataProvider;
 }
コード例 #2
0
 private function openCompanies($count = 100)
 {
     print_r("Open companies. Count: " . $count . "...");
     $this->faker->unique(true);
     $buildings = Building::find()->asArray()->all();
     $building_ids = ArrayHelper::getColumn($buildings, 'id');
     $building_ids_length = count($building_ids) - 1;
     for ($i = 0; $i < $count; $i++) {
         $company = new Company();
         $company->title = $this->faker->unique()->company;
         $company->building_id = $building_ids[mt_rand(1, $building_ids_length)];
         $company->save();
     }
     print_r("DONE" . PHP_EOL);
 }
コード例 #3
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::find()->select(['id', 'address', "ST_X(location)||','||ST_Y(location) as location"])->where(['id' => $id])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: Company.php プロジェクト: novikovsergey/doublegis
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBuilding()
 {
     return $this->hasOne(Building::className(), ['id' => 'building_id']);
 }
コード例 #5
0
ファイル: _form.php プロジェクト: novikovsergey/doublegis
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model app\models\Company */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="company-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => true]);
?>
    <?php 
echo $form->field($model, 'building_id')->dropDownList(ArrayHelper::map(\app\models\Building::find()->all(), 'id', 'address'));
?>

    <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();
?>

</div>
コード例 #6
0
ファイル: Castle.php プロジェクト: nvchernov/tsargrad
 public function fortification()
 {
     return Building::where('castles_id', $this->id)->where('buildings_id', 4)->first();
 }
コード例 #7
0
 public function actionBuildings()
 {
     $buildings = Building::find()->select(['id', 'address', "ST_X(location)||','||ST_Y(location) as location"])->asArray()->all();
     return $buildings;
 }
コード例 #8
0
ファイル: GameController.php プロジェクト: nvchernov/tsargrad
 public function upgradeBuildingLevel($id)
 {
     $build = Building::find($id);
     $build->castle()->first()->calcCastleIncreaseResources();
     $currentWood = $build->castle()->first()->getResources('wood');
     $currentGold = $build->castle()->first()->getResources('gold');
     $cost = $build->costUpdate();
     if ($currentWood >= $cost && $currentGold >= $cost) {
         $build->levelUp();
         $build->castle()->first()->subResource('wood', $cost);
         $build->castle()->first()->subResource('gold', $cost);
         return "success";
     } else {
         return "no_costs";
     }
 }