示例#1
0
 /**
  * @return \yii\db\ActiveRelation
  */
 public function getTimezone(array $timezones = [])
 {
     $region = $this->region;
     if (empty($region)) {
         $location = self::find()->fromPoint((double) $this->latitude, (double) $this->longitude, self::FIND_REGION_DISTANCE)->andWhere('region IS NOT NULL AND region <> \'\'')->andWhere('country = :country', [':country' => $this->country])->limit(1)->one();
         $region = $location->region;
     }
     $query = Timezones::find()->where('country = :country', [':country' => $this->country]);
     if (!empty($region)) {
         $cloned = clone $query;
         $cloned->andWhere('region = :region', [':region' => $region]);
         $cloned->orderBy('region DESC');
         if ($cloned->exists()) {
             $query = $cloned;
         }
     }
     if (!empty($timezones)) {
         $query->andWhere(['timezone' => $timezones]);
     }
     return $query;
 }