예제 #1
0
 /**
  * 将文章插入数据库
  * @param $title
  * @param $content
  * @param $publish_at
  * @param $tag
  * @return bool
  */
 public static function insert($title, $content, $publish_at, $tag = '')
 {
     //插入标签(搜索的分类)
     $article = new Article();
     $article->title = $title;
     $article->content = $content;
     $article->author = 'yang';
     $article->status = Article::STATUS_GATHER;
     $article->publish_at = $publish_at;
     $res = $article->save(false);
     if ($tag) {
         try {
             $tagModel = Tag::find()->where(['name' => $tag])->one();
             if (!$tagModel) {
                 $tagModel = new Tag();
                 $tagModel->name = $tag;
                 $tagModel->article_count = 0;
                 $tagModel->save(false);
             }
             $articleTag = new ArticleTag();
             $articleTag->article_id = $article->id;
             $articleTag->tag_id = $tagModel->id;
             $articleTag->save(false);
         } catch (\Exception $e) {
             echo $e->getMessage() . PHP_EOL;
         }
     }
     return $res ? true : false;
 }
예제 #2
0
 /**
  * Finds the Meta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Tag::find()->andWhere('mid=:mid', [':mid' => $id])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #3
0
파일: TagCloud.php 프로젝트: Penton/MoBlog
 public function init()
 {
     parent::init();
     $tags = Tag::find()->orderByCount()->all();
     if (!empty($tags)) {
         foreach ($tags as $v) {
             $this->_htmlStr .= Html::a($v->name, ['site/tag', 'slug' => $v->slug], $this->options);
         }
     }
 }
예제 #4
0
 public function actionTag($slug)
 {
     $tag = Tag::find()->andWhere(['slug' => $slug])->one();
     if (!$tag) {
         throw new NotFoundHttpException('页面不存在');
     }
     $pagination = new Pagination(['totalCount' => $tag->getPosts()->count()]);
     $posts = $tag->getPosts()->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('list', ['posts' => $posts, 'pagination' => $pagination, 'tag' => $tag]);
 }
예제 #5
0
 /**
  * Updates an existing Topic model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('update');
     $post = Yii::$app->request->post();
     if ($model->load($post) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'tags' => Tag::find()->all()]);
     }
 }
예제 #6
0
 /**
  * Lists the Article models in a specific category $slug.
  *
  * @param $slug
  * @return mixed
  */
 public function actionTag($slug)
 {
     $model = Tag::find()->andWhere(['slug' => $slug])->one();
     if (!$model) {
         throw new NotFoundHttpException(Yii::t('frontend', 'Page not found.'));
     }
     $query = Article::find()->with('category')->joinWith('tags')->where('{{%tag}}.slug = :slug', [':slug' => $slug])->published();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => 10]]);
     $dataProvider->sort = ['defaultOrder' => ['created_at' => SORT_DESC]];
     return $this->render('tag', ['model' => $model, 'dataProvider' => $dataProvider, 'menuItems' => self::getMenuItems()]);
 }
예제 #7
0
 public function actionTag($ids)
 {
     $arr_ids = explode('_', $ids);
     $tags = Tag::find()->all();
     $query = Post::find()->joinWith('tags')->where(['tags.id' => $arr_ids]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]);
     $pages->pageSizeParam = false;
     $posts = $query->offset($pages->offset)->limit($pages->limit)->orderBy('id desc')->all();
     return $this->render('category', ['ids' => $arr_ids, 'tags' => $tags, 'posts' => $posts, 'pagination' => $pages]);
 }
예제 #8
0
 public function actionIndex()
 {
     $lastPosts = Post::find()->orderBy('created_at desc')->limit(10)->all();
     $featured = Post::featured();
     $drafts = Post::drafts();
     $mostPopularCategory = Category::find()->joinWith('posts')->select('category.id, post.category_id, count(distinct post.title) as qty, category.title')->groupBy('post.category_id')->orderBy('qty desc')->one();
     $mostPopularTag = Tag::find()->joinWith('posts')->select('tags.id, posts_tags.tag_id, count(distinct posts_tags.post_id) as qty, tags.title')->groupBy('posts_tags.tag_id')->orderBy('qty desc')->one();
     $postsCount = Post::find()->where('active = 1')->count();
     $categoryCount = Category::find()->count();
     return $this->render('index', ['lastPosts' => $lastPosts, 'featured' => $featured, 'drafts' => $drafts, 'mostPopularCategory' => $mostPopularCategory, 'mostPopularTag' => $mostPopularTag, 'postsCount' => $postsCount, 'categoryCount' => $categoryCount]);
 }
예제 #9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tag::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'count' => $this->count, 'topics' => $this->topics, 'shares' => $this->shares, 'labels' => $this->labels, 'created' => $this->created, 'updated' => $this->updated, 'active' => $this->active]);
     $query->andFilterWhere(['like', 'tag', $this->tag]);
     return $dataProvider;
 }
예제 #10
0
 /**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = Tag::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
예제 #11
0
 public function search($params)
 {
     $query = Tag::find()->where(['store_id' => Yii::$app->user->identity->store_id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['sort' => SORT_ASC]], 'pagination' => ['pageSize' => 0]]);
     // load the seach form data and validate
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $dateBegin = strtotime($this->date);
     $dateEnd = $dateBegin + 86400;
     // adjust the query by adding the filters
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['>=', 'created_at', $this->date ? $dateBegin : null])->andFilterWhere(['<', 'created_at', $this->date ? $dateEnd : null]);
     return $dataProvider;
 }
예제 #12
0
 /**
  * Creates data provider instance with search query applied.
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tag::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 60]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'frequency' => $this->frequency]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
예제 #13
0
 public function actionNormalize()
 {
     /**
      * @var $tag Tag
      */
     $updated = 0;
     $deleted = 0;
     $list = [];
     foreach (Tag::find()->each() as $tag) {
         $name = mb_strtolower($tag->name);
         if (isset($list[$name])) {
             TagEvent::updateAll(['tag_id' => $list[$name]], ['tag_id' => $tag->id]);
             $tag->delete();
             $deleted++;
             continue;
         }
         $list[$name] = $tag->id;
     }
     $this->stdout(Console::wrapText("- {$updated} updated, {$deleted} deleted", 10), Console::BOLD);
     $this->stdout("\n");
 }
예제 #14
0
 /**
  * 获取文章列表(可以按分类、标签获取文章列表)
  * @return string
  */
 public function actionIndex()
 {
     $category_id = Html::encode(Yii::$app->request->get('category_id'));
     $tag_id = Html::encode(Yii::$app->request->get('tag_id'));
     $data = Article::find()->where(['status' => Article::STATUS_DISPLAY, 'category_id' => $category_id]);
     if ($tag_id) {
         $article_tags = ArticleTag::find()->where(['tag_id' => $tag_id])->all();
         $article_ids = ArrayHelper::getColumn($article_tags, 'article_id');
         $data = $data->andWhere(['in', 'id', $article_ids]);
     }
     $pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => 20]);
     //全部文章
     $articles = $data->orderBy(['publish_at' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->all();
     //推荐文章
     $recommendArticles = Article::getRecommendArticle();
     //分类
     $categories = Category::find()->where(['status' => Category::STATUS_DISPLAY])->all();
     //热门标签
     $tags = Tag::find()->orderBy(['article_count' => SORT_DESC, 'id' => SORT_DESC])->limit(10)->all();
     return $this->render('index', ['articles' => $articles, 'recommendArticles' => $recommendArticles, 'categories' => $categories, 'tags' => $tags, 'category_id' => $category_id, 'tag_id' => $tag_id]);
 }
예제 #15
0
파일: search.php 프로젝트: jedzura/nzs
<?php

use common\models\City;
use common\models\Tag;
use common\models\University;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;
use yii\helpers\ArrayHelper;
$cities = ArrayHelper::map(City::find()->orderBy('name')->all(), 'id', 'name');
$tags = ArrayHelper::map(Tag::find()->orderBy('name')->all(), 'id', 'name');
$universities = ArrayHelper::map(University::find()->orderBy('name')->all(), 'id', 'name');
?>

<h1><?php 
echo Yii::t('lbl', 'Find organizations');
?>
</h1>
<?php 
$form = ActiveForm::begin();
?>
    <article class="searchbox">
        <div class="row">
            <div class="col-xs-12 col-sm-6 col-md-5">
                <?php 
echo $form->field($model, 'name', ['inputOptions' => ['autofocus' => 'autofocus', 'placeholder' => Yii::t('lbl', 'Name')]])->textInput()->label(false);
?>
            </div>
            <div class="col-xs-12 col-sm-6 col-md-5">
                <?php 
echo $form->field($model, 'city_id')->dropDownList($cities, ['prompt' => Yii::t('lbl', 'City')])->label(false);
?>
예제 #16
0
 /**
  * 
  * @param array $tags
  * @param $model
  */
 protected function checkTags($tags, $model)
 {
     $tagsSaved = Tag::find()->all();
     $tagsArray = ArrayHelper::map($tagsSaved, 'id', 'tag_title');
     $newTags = array_diff($tags, $tagsArray);
     if (!empty(array_filter($newTags))) {
         $query = "INSERT INTO tag (tag_title) VALUES (:tag_title)";
         $cmd = Yii::$app->db->createCommand($query);
         foreach ($newTags as $tag) {
             $cmd->bindValues([':tag_title' => [$tag, \PDO::PARAM_STR]]);
             $cmd->execute();
         }
     }
     $tagsSaved2 = Tag::find()->all();
     $tagsArray2 = ArrayHelper::map($tagsSaved2, 'id', 'tag_title');
     $tagIds = array_intersect($tagsArray2, $tags);
     $query2 = "DELETE FROM page_tag WHERE page_id = {$model->id}";
     $cmd2 = Yii::$app->db->createCommand($query2);
     $cmd2->execute();
     $query3 = "INSERT INTO page_tag (page_id, tag_id) VALUES ({$model->id}, :tag_id)";
     $cmd3 = Yii::$app->db->createCommand($query3);
     foreach ($tagIds as $key => $tag) {
         $cmd3->bindValues([':tag_id' => [$key, \PDO::PARAM_INT]]);
         $cmd3->execute();
     }
 }
예제 #17
0
<?php

use yii\helpers\Html;
use common\models\Category;
use common\models\Tag;
use common\models\Author;
use common\models\Meme;
use common\models\Vidmage;
use common\helpers\Tools;
$channels = Category::find()->all();
$tags = Tag::find()->orderBy(['recount' => SORT_DESC])->limit(10)->all();
$authors = Author::find()->orderBy(['recount' => SORT_DESC])->limit(5)->all();
$latestMemes = Meme::find()->orderBy(['id' => SORT_DESC])->limit(10)->all();
$latestReplicas = Vidmage::find()->joinWith('memeVidmages')->where(['meme_vidmage.is_the_origin' => false])->orderBy(['id' => SORT_DESC])->limit(10)->all();
?>

<?php 
echo $this->render('_left-column-list-items', ['items' => $latestMemes, 'title' => 'Latest Memes', 'icon' => 'globe', 'divId' => 'latest-memes', 'class' => 'success']);
?>

<?php 
echo $this->render('_left-column-list-items', ['items' => $latestReplicas, 'title' => 'Latest Replicas', 'icon' => 'film', 'divId' => 'latest-replicas', 'class' => 'info']);
?>

<?php 
echo $this->render('_left-column-list-items', ['items' => $channels, 'title' => 'Channels', 'icon' => 'blackboard', 'divId' => 'channels', 'class' => 'warning']);
?>

<?php 
echo $this->render('_left-column-list-items', ['items' => $tags, 'title' => 'Trending Tags', 'icon' => 'tag', 'divId' => 'tags', 'class' => 'danger']);
?>
예제 #18
0
 /**
  * Lists all Tag models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Tag::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
예제 #19
0
 public static function removeTags($tags)
 {
     if (empty($tags)) {
         return;
     }
     foreach ($tags as $name) {
         $aTag = Tag::find()->where(['name' => $name])->one();
         $aTagCount = Tag::find()->where(['name' => $name])->count();
         if ($aTagCount) {
             if ($aTagCount && $aTag->frequency <= 1) {
                 $aTag->delete();
             } else {
                 $aTag->frequency -= 1;
                 $aTag->save();
             }
         }
     }
 }
예제 #20
0
 /**
  * @param mixed $id Tag id OR new tag name
  *
  * @return boolean
  */
 public function addTag($id)
 {
     if (is_numeric($id)) {
         $tag = Tag::find()->where(['id' => $id])->one();
     } elseif (strpos($id, '{new}') !== false) {
         $name = mb_substr($id, 5, mb_strlen($id, 'UTF-8') - 5, 'UTF-8');
         $tag = new Tag();
         $tag->name = $name;
         if (!$tag->save()) {
             return false;
         }
     }
     if (!empty($tag)) {
         $tagging = new Tagging();
         $tagging->taggable_id = $this->id;
         $tagging->taggable_type = Tagging::TAGGABLE_VIDEO;
         $tagging->tag_id = $tag->id;
         return $tagging->save();
     }
     return false;
 }
예제 #21
0
 /**
  * @inheritdoc
  */
 public function actionList()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $items = Tag::find()->select(['name'])->orderBy(['name' => SORT_ASC])->all();
     return $items;
 }
예제 #22
0
파일: _form.php 프로젝트: VitaliyProdan/hr
    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?//= $form->field($model, 'status')->textInput() ?>
    <div class="row">
        <div class="col-md-6">
            <?php 
echo $form->field($model, 'photo')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*'], 'pluginOptions' => ['initialPreview' => $model->photo ? [Html::img($model->photoUrl, ['class' => 'file-preview-image', 'alt' => $model->username, 'title' => $model->username])] : false, 'showUpload' => false, 'allowedFileExtensions' => ['jpg', 'gif', 'png', 'bmp']]]);
?>
            <?php 
echo $form->field($model, 'category_id')->dropDownList($model->categoryList());
?>
            <?php 
echo $form->field($model, 'tagIds')->checkboxList(ArrayHelper::map(\common\models\Tag::find()->all(), 'id', 'title'));
?>
        </div>
        <div class="col-md-6">
            <div class="row">
                <div class="col-md-6">
                    <?php 
echo $form->field($model, 'first_name')->textInput();
?>
                </div>
                <div class="col-md-6">
                    <?php 
echo $form->field($model, 'last_name')->textInput();
?>
                </div>
            </div>
예제 #23
0
 /**
  * Page of all tags
  * Url: /tags
  * @return mixed
  * @throws NotFoundHttpException
  */
 public function actionTags()
 {
     $tags = Tag::find()->all();
     if (!isset($tags)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $title = "Все теги";
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['allTags' => ['view' => '@frontend/views/site/tags', 'data' => compact('tags')]], 'columnSecond' => ['short_news' => SiteBlock::getShortNews()]]);
 }