/** * @param type $addr * @throws AppException */ public function fromBlock($addr) { if (!is_scalar($addr)) { throw new Exception('Location address is not valid.'); } $block = LocationBlock::find()->where(':addr BETWEEN start AND end', [':addr' => ip2long($addr)])->one(); if ($block !== null) { $this->andWhere('id = :id', [':id' => $block->id]); } else { $this->andWhere(0); } return $this; }