Example #1
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;
 }
Example #2
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;
 }