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]); }
/** * 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; }
/** * */ 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; }
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; }
/** * 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.'); } }