Exemplo n.º 1
0
 /**
  * Returns tag names and their corresponding weights.
  * Only the tags with the top weights will be returned.
  * @param integer the maximum number of tags that should be returned
  * @return array weights indexed by tag names.
  */
 public function findTagWeights($limit = 20)
 {
     $query = $this->find();
     $tagPostQuery = TagPost::find()->select('tag_id')->all();
     $total = [];
     foreach ($tagPostQuery as $tag) {
         $total[] = $tag['tag_id'];
     }
     $frequency = array_count_values($total);
     $models = $query->limit($limit)->all();
     $tags = [];
     foreach ($models as $model) {
         $tags[$model->title] = 8 + (int) (16 * $frequency[$model->id] / ($frequency[$model->id] + 10));
     }
     ksort($tags);
     return $tags;
 }
Exemplo n.º 2
0
 public function init()
 {
     parent::init();
 }
Exemplo n.º 3
0
 /**
  * Возвращает тэги поста.
  * @return ActiveQuery
  */
 public function getTagPost()
 {
     return $this->hasMany(TagPost::className(), ['post_id' => 'id']);
 }