Пример #1
0
 public function run()
 {
     $tags = Tag::findTagWeights();
     $str = '';
     foreach ($tags as $tag => $weight) {
         $link = Html::a(Html::encode($tag), Yii::$app->getUrlManager()->createUrl(['main/default/index', 'tag' => $tag]));
         $str .= Html::tag('span', $link, ['class' => 'tag', 'style' => "font-size:{$weight}pt"]) . "\n";
     }
     return $this->render('tag', ['title' => $this->title, 'content' => $str]);
 }
Пример #2
0
 public static function findTagWeights($limit = 20)
 {
     $models = Tag::find()->orderBy(['frequency' => SORT_DESC])->all();
     $total = 0;
     foreach ($models as $model) {
         $total += $model->frequency;
     }
     $tags = [];
     if ($total > 0) {
         foreach ($models as $model) {
             $tags[$model->name] = 8 + (int) (16 * $model->frequency / ($total + 10));
         }
         ksort($tags);
     }
     return $tags;
 }
Пример #3
0
 public function getTagLinks()
 {
     $links = [];
     foreach (Tag::string2array($this->tags) as $tag) {
         $links[] = Html::a($tag, Yii::$app->getUrlManager()->createUrl(['main/default/index', 'tag' => $tag]));
     }
     return $links;
 }