Skip to content

Commit

Permalink
Added availableZones
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Sep 29, 2016
1 parent bf01059 commit 8111d0a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 66 deletions.
56 changes: 4 additions & 52 deletions src/controllers/DomaincheckerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
namespace hipanel\modules\domainchecker\controllers;

use hipanel\modules\domain\models\Domain;
use hipanel\modules\domain\repositories\DomainTariffRepository;
use hipanel\modules\finance\models\DomainResource;
use hipanel\modules\finance\models\Tariff;
use Yii;
use yii\base\InvalidConfigException;

class DomaincheckerController extends \hipanel\base\CrudController
{
Expand Down Expand Up @@ -67,9 +66,9 @@ public function actionCheckDomain()
$results = [];
$model = new Domain();
$model->scenario = 'check-domain';

$tariff = $this->getDomainTariff();
$zones = $this->getDomainZones($tariff, DomainResource::TYPE_DOMAIN_REGISTRATION);
$repository = Yii::createObject(DomainTariffRepository::class);
$tariff = $repository->getTariff();
$zones = $repository->getZones($tariff, DomainResource::TYPE_DOMAIN_REGISTRATION);

$dropDownZones = [];
foreach ($zones as $resource) {
Expand Down Expand Up @@ -112,51 +111,4 @@ public function actionCheckDomain()
'results' => $results,
]);
}

/**
* Returns the tariff for the domain operations
* Caches the API request for 3600 seconds and depends on client id and seller login.
* @throws \yii\base\InvalidConfigException
* @return Tariff
*/
protected function getDomainTariff()
{
if (Yii::$app->user->isGuest) {
if (isset(Yii::$app->params['seller'])) {
$params = [
Yii::$app->params['seller'],
null
];
} else throw new InvalidConfigException('"seller" is must be set');
} else {
$params = [
Yii::$app->user->identity->seller,
Yii::$app->user->id,
];
}

return Yii::$app->getCache()->getTimeCached(3600, $params, function ($seller, $client_id) {
return Tariff::find(['scenario' => 'get-available-info'])
->joinWith('resources')
->andFilterWhere(['type' => 'domain'])
->andFilterWhere(['seller' => $seller])
->one();
});
}

/**
* @param Tariff $tariff
* @param string $type
* @return array
*/
protected function getDomainZones($tariff, $type = DomainResource::TYPE_DOMAIN_REGISTRATION)
{
if ($tariff === null || !$tariff instanceof Tariff) {
return [];
}

return array_filter((array)$tariff->resources, function ($resource) use ($type) {
return $resource->zone !== null && $resource->type === $type;
});
}
}
8 changes: 5 additions & 3 deletions src/controllers/WhoisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace hipanel\modules\domainchecker\controllers;

use hipanel\modules\domain\models\Domain;
use hipanel\helpers\ArrayHelper;
use hipanel\modules\domain\repositories\DomainTariffRepository;
use hipanel\modules\domainchecker\models\Whois;
use hiqdev\hiart\ErrorResponseException;
use yii\web\UnprocessableEntityHttpException;
use Yii;

Expand All @@ -26,7 +26,9 @@ public function actionIndex($domain = null)
if (!$model->validate()) {
throw new UnprocessableEntityHttpException();
}
$availableZones = [];
/** @var DomainTariffRepository $repository */
$repository = Yii::createObject(DomainTariffRepository::class);
$availableZones = ArrayHelper::getColumn($repository->getAvailableZones(), 'zone', false);

return $this->render('index', [
'model' => $model,
Expand Down
10 changes: 0 additions & 10 deletions src/repositories/DomainTariffRepositry.php

This file was deleted.

6 changes: 5 additions & 1 deletion src/views/whois/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/** @var \hipanel\modules\domain\models\Domain $model */

use hipanel\modules\domainchecker\assets\WhoisAsset;
use hipanel\widgets\ArraySpoiler;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;
use yii\helpers\Url;
Expand Down Expand Up @@ -43,7 +44,10 @@
<?php ActiveForm::end() ?>
<div class="bg-warning md-mt-10" style="padding: 5px 7px">
<span class="text-bold"><?= Yii::t('hipanel/domainchecker', 'Available zones') ?>:</span><br>
com, net, name, cc, tv, org, info, pro, mobi, biz, xxx, porn, adult, sex, me, kiev.ua, com.ua, su, ru
<?= ArraySpoiler::widget([
'data' => $availableZones,
'visibleCount' => count($availableZones),
]) ?>
</div>
<p class="md-mt-20">
<?= Yii::t('hipanel/domainchecker', 'WHOIS isn’t an acronym, though it may look like one. In fact, it is the system that provides information, who is responsible for a domain name.') ?>
Expand Down

0 comments on commit 8111d0a

Please sign in to comment.