示例#1
0
 /**
  * Finds the Domain model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Domain the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Domain::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDomains()
 {
     return $this->hasMany(Domain::className(), ['language_id' => 'id']);
 }
示例#3
0
文件: _form.php 项目: BeforyDeath/tfa
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\models\DomainPattern */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="domain-pattern-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'domain_id')->dropdownList(\backend\models\Domain::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Domain:'])->label('Domain Name');
?>

    <?php 
echo $form->field($model, 'model_id')->dropdownList(\backend\models\PatternModel::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Pattern Model:'])->label('Pattern Model Name');
?>

    <?php 
echo $form->field($model, 'type_id')->dropdownList(\backend\models\PatternType::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => 'Pattern Type:'])->label('Pattern Type Name');
?>

    <?php 
echo $form->field($model, 'value')->textarea(['rows' => 6]);
?>

    <div class="form-group">
示例#4
0
 public function actionGenerate($name, $alias = '')
 {
     // командер
     $commander = new Commander();
     // проверяем домен
     $domain = Domain::find()->where(['name' => $name])->with('language')->one();
     if (!$domain) {
         $this->stdout('No domain:' . $name . PHP_EOL, Console::FG_RED);
         return Controller::EXIT_CODE_ERROR;
     }
     // паттерны и модели
     $models = DomainPattern::find()->select(['model_id']);
     // todo только указаные модели, разделённые слешем
     if ($alias) {
         $alias = explode("/", $alias);
         $_models = PatternModel::find()->select('id')->where(['alias' => $alias])->column();
         $models = $models->where(['model_id' => $_models]);
     }
     $models = $models->groupBy('model_id')->column();
     $result = [];
     $addiction = [];
     foreach ($models as $model) {
         $patterns = DomainPattern::find()->where(['domain_id' => $domain->id, 'model_id' => $model])->asArray()->with(['domain', 'domain.language', 'domain.group', 'model', 'model.addiction', 'type'])->orderBy('model_id')->all();
         // зависимости
         foreach ($patterns as $pattern) {
             $result[$pattern['model']['alias']][$pattern['type']['alias']] = $pattern['value'];
             if (!empty($pattern['model']['addiction'])) {
                 $addiction[$pattern['model']['alias']] = strtolower($pattern['model']['addiction']['alias']);
             }
         }
     }
     // читаем модели
     foreach ($result as $model => $patterns) {
         $this->stdout('Delete ' . $model . PHP_EOL, Console::FG_GREEN);
         DomainGeneration::deleteAll(['domain' => $name, 'model' => $model]);
         $this->stdout('Generation ' . $model . PHP_EOL, Console::FG_GREEN);
         $_addiction = [];
         if (!empty($addiction[$model])) {
             if ($model == 'Direction') {
                 $_addiction = ['cityFrom', 'cityTo', 'cityFrom.country', 'cityTo.country', 'iataCode'];
             } elseif ($addiction[$model] != 'route') {
                 $_addiction = $addiction[$model];
             }
         }
         /** @var ActiveRecord $_model */
         $_model = 'common\\models\\' . $model;
         $elements = $_model::find()->asArray();
         $elements = $elements->with($_addiction);
         if ($model == 'Direction') {
             $elements = $elements->groupBy(['city_from_code', 'city_to_code']);
         }
         $elements = $elements->all();
         // проходим по записям
         $_count = count($elements);
         Console::startProgress(0, $_count);
         $count = 0;
         $count_ = 0;
         foreach ($elements as $element) {
             //                print_r($element);die();
             // генерим паттерны
             $commander->setMember($element);
             $pattern_result = [];
             foreach ($patterns as $alias => $pattern) {
                 $cmd = $pattern;
                 $cmd = $commander->getProperty($cmd);
                 $cmd = $commander->getFunction($cmd);
                 $cmd = $commander->setProperty($cmd);
                 $pattern_result[$alias] = $cmd;
             }
             $commander->clearMember();
             //                print_r($pattern_result);
             //                die();
             // todo сохраняем паттерны в базу
             $generation = DomainGeneration::find()->select('id')->where(['hash' => md5($domain->name . '/' . $pattern_result['url'])])->asArray()->one();
             //                $generation = true;
             if (!$generation) {
                 $generation = new DomainGeneration();
                 $generation->domain = $domain->name;
                 $generation->url = $pattern_result['url'];
                 $generation->parent_url = $pattern_result['parent_url'];
                 $generation->hash = md5($domain->name . '/' . $pattern_result['url']);
                 $generation->hash_ = md5($domain->name . '/' . $pattern_result['url']);
                 $generation->model = $model;
                 $generation->anchor = $pattern_result['anchor'];
                 unset($pattern_result['url']);
                 unset($pattern_result['parent_url']);
                 unset($pattern_result['anchor']);
                 unset($pattern_result['hash']);
                 unset($pattern_result['model']);
                 $generation->data = json_encode($pattern_result);
                 if (!$generation->save()) {
                     print_r($generation->errors);
                     return Controller::EXIT_CODE_ERROR;
                 }
             }
             $count++;
             Console::updateProgress(++$count_, $_count);
             //}
             // todo собираем ссылки
             // todo генерить redis
             // todo создавать сайтмэп
             //                die();
         }
         Console::endProgress();
     }
     return Controller::EXIT_CODE_NORMAL;
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDomain()
 {
     return $this->hasOne(Domain::className(), ['id' => 'domain_id']);
 }