Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CelestialBody::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'pos_galaxy' => $this->pos_galaxy, 'pos_system' => $this->pos_system, 'pos_planet' => $this->pos_planet, 'density_iron' => $this->density_iron, 'density_chemicals' => $this->density_chemicals, 'density_ice' => $this->density_ice, 'gravity' => $this->gravity, 'living_conditions' => $this->living_conditions]);
     return $dataProvider;
 }
Esempio n. 2
0
    /**
     * Selects a celestial body that should be used for a new player.
     * @todo could use a better algorithm. Maybe place new players in areas that
     *       are not too densly populated.
     *       Or place them among other players just having started playing.
     * @return CelestialBody
     */
    public function chooseCelestialBodyForNewPlayer()
    {
        $db = Instance::ensure($this->db, Connection::className());
        /* @var $db Connection */
        $sql = <<<'EOT'
SELECT {{cb}}.[[id]] AS [[id]]
FROM {{%celestial_body}} {{cb}}
LEFT JOIN {{%base}} {{b}} ON {{b}}.[[id]] = {{cb}}.[[id]]
WHERE {{b}}.[[id]] IS NULL
;
EOT;
        $recordSets = $db->createCommand($sql)->queryAll();
        $randomOffset = rand(0, count($recordSets) - 1);
        $randomRecordSet = $recordSets[$randomOffset];
        return CelestialBody::findOne(['id' => $randomRecordSet['id']]);
    }
Esempio n. 3
0
 public function __construct(GravimetricAnomalyEntity $entity)
 {
     parent::__construct($entity);
 }
Esempio n. 4
0
 /**
  * Finds the CelestialBody model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CelestialBody the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CelestialBody::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCelestialBody()
 {
     return $this->hasOne(CelestialBody::className(), ['id' => 'id']);
 }
Esempio n. 6
0
 public function __construct(GasGiantEntity $entity)
 {
     parent::__construct($entity);
 }
Esempio n. 7
0
 public function __construct(ElectricityStormEntity $entity)
 {
     parent::__construct($entity);
 }
Esempio n. 8
0
 public function __construct(VoidEntity $entity)
 {
     parent::__construct($entity);
 }
Esempio n. 9
0
 public function __construct(IonStormEntity $entity)
 {
     parent::__construct($entity);
 }
Esempio n. 10
0
 public function __construct(SpatialDistortionEntity $entity)
 {
     parent::__construct($entity);
 }
Esempio n. 11
0
 public function __construct(TerrestrialPlanetEntity $entity, CelestialBodySpecialtyRepository $celestialBodySpecialtyRepository)
 {
     parent::__construct($entity);
     $this->celestialBodySpecialtyRepository = $celestialBodySpecialtyRepository;
     $this->terrestrialPlanetEntity = $entity;
 }