예제 #1
0
 public function run()
 {
     $tags = BlogTag::findTagWeights();
     $str = '';
     foreach ($tags as $tag => $weight) {
         $link = Html::a(Html::encode($tag), Yii::$app->getUrlManager()->createUrl(['blog/default/index', 'tag' => $tag]));
         $str .= Html::tag('span', $link, ['class' => 'tag', 'style' => "font-size:{$weight}pt"]) . "\n";
     }
     return $this->render('portal', ['title' => $this->title, 'content' => $str]);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BlogTag::find();
     $query->orderBy(['frequency' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'frequency' => $this->frequency]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
예제 #3
0
 /**
  *
  */
 public function getTagLinks()
 {
     $links = [];
     foreach (BlogTag::string2array($this->tags) as $tag) {
         $links[] = Html::a($tag, Yii::$app->getUrlManager()->createUrl(['blog/default/index', 'tag' => $tag]));
     }
     return $links;
 }
예제 #4
0
 public static function findTagWeights($limit = 20)
 {
     $models = BlogTag::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;
 }
예제 #5
0
 /**
  * Finds the Tag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Tag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BlogTag::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }