public function createBuildings() { // Лепим лесопилку $sawmill = new Building(); $sawmill->castle()->associate($this); $sawmill->buildingType()->associate(BuildingType::where('building_name', 'sawmill')->first()); $sawmill->level = 1; $sawmill->save(); // Шахту $sawmill = new Building(); $sawmill->castle()->associate($this); $sawmill->buildingType()->associate(BuildingType::where('building_name', 'mine')->first()); $sawmill->level = 1; $sawmill->save(); // Ферму $farm = new Building(); $farm->castle()->associate($this); $farm->buildingType()->associate(BuildingType::where('building_name', 'farm')->first()); $farm->level = 1; $farm->save(); // Защитные сооружения $defences = new Building(); $defences->castle()->associate($this); $defences->buildingType()->associate(BuildingType::where('building_name', 'defenses')->first()); $defences->level = 0; $defences->save(); }
private function contructBuildings($count = 100) { print_r("Construct buildings. Count: " . $count . "..."); for ($i = 0; $i < $count; $i++) { $building = new Building(); $building->address = $this->faker->address; $building->location = Building::getPostgisFormatByCoordinate($this->faker->longitude, $this->faker->latitude); $building->save(); } print_r("DONE" . PHP_EOL); }
/** * Creates a new Building model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Building(); if (Yii::$app->request->isPost) { $post = Yii::$app->request->post('Building'); $model->address = $post['address']; $model->location = Building::locationStringToGeometry($post['location']); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }