Exemplo n.º 1
0
 /**
  * Rebuilds table of top tags
  *     
  */
 public function actionTagsCloudRebuild()
 {
     $success = false;
     $connection = Yii::$app->db;
     $query = 'DELETE FROM ' . TagsCloud::tableName();
     $cmd = $connection->createCommand($query)->execute();
     $query = 'SELECT tag_id AS i, count(tag_id) AS c FROM taggings GROUP BY tag_id ORDER BY c DESC LIMIT 50';
     $cmd = $connection->createCommand($query);
     $newTopTags = $cmd->queryAll();
     $weight = 10;
     $count = 0;
     foreach ($newTopTags as $topTag) {
         $count++;
         if (50 % $count == 0) {
             $weight -= 2;
         }
         $cmd = $connection->createCommand()->batchInsert(TagsCloud::tableName(), ['tag_id', 'weight'], [[$topTag['i'], $weight]])->execute();
     }
     $success = true;
     return $this->render('rebuildSuccess', ['success' => $success]);
 }
Exemplo n.º 2
0
 /**
  * Get top 200 tags to cloud
  * @return array Data
  */
 public static function getTop200Tags()
 {
     $topTags = TagsCloud::find()->orderBy(['weight' => SORT_DESC])->all();
     $block = ['view' => '@frontend/views/blocks/top_tags_block', 'data' => ['topTags' => $topTags]];
     return $block;
 }