Example #1
0
 public function actionSuggestTags($q = '', $limit = 20, $timestamp = 0)
 {
     if (($keyword = trim($q)) !== '') {
         $tags = Tag::suggestTags($keyword);
         if ($tags !== array()) {
             echo implode("\n", $tags);
         }
     }
 }
Example #2
0
 protected function renderContent()
 {
     $tags = Tag::findTagWeights($this->maxTags);
     foreach ($tags as $tag => $weight) {
         if ($weight > 14) {
             $weight = 14;
         }
         $class = 'label ';
         if (isset($this->_labels[$weight])) {
             $class .= $this->_labels[$weight];
         }
         // TODO: controller route
         echo Html::a(Html::encode($tag), array('blog/post/index', 'tag' => $tag), array('class' => $class)) . "\n";
     }
 }
Example #3
0
 public static function addTags($tags)
 {
     if (count($tags) > 0) {
         $inTags = preg_replace('/(\\S+)/i', '\'\\1\'', $tags);
         $sql = "UPDATE " . Tag::tableName() . " SET frequency=frequency+1 WHERE name IN (" . join(",", $inTags) . ' ) ';
         Yii::$app->db->createCommand($sql)->execute();
         foreach ($tags as $name) {
             $model = static::find()->where('name=:name', array(':name' => $name))->one();
             if ($model === null) {
                 $tag = new Tag();
                 $tag->name = $name;
                 $tag->frequency = 1;
                 $tag->save();
             }
         }
     }
 }