Ejemplo n.º 1
0
 /**
  * Просмотр списка постов по тегу
  * @param $id
  * @return string
  */
 public function actionView($id)
 {
     $tagModel = new Tags();
     $tag = $tagModel->getTag($id);
     $categoryModel = new Category();
     return $this->render('view', ['tag' => $tag, 'posts' => $tag->getTagPosts(), 'categories' => $categoryModel->getCategories()]);
 }
Ejemplo n.º 2
0
 /**
  * Return Ticket IDs of Tickets which contain tag names
  *
  * @param $tagSearch string/array list of Tag Names to search for (when string CSV)
  * @return array
  */
 public static function getTicketId($tagSearch)
 {
     // tagSearch can be string or array
     // If empty then return empty array
     // The goal is to create an array of Tag Names for the sql IN clause
     if (is_array($tagSearch)) {
         if (count($tagSearch)) {
             $tagSearchValues = $tagSearch;
         } else {
             //nothing to search for return empty array
             return [];
         }
     } elseif (is_string($tagSearch)) {
         if (trim($tagSearch) == '') {
             //nothing to search for return empty array
             return [];
         } else {
             $tagSearchValues = explode(',', $tagSearch);
         }
     } else {
         //nothing to search for return empty array
         return [];
     }
     return Tags::find()->select('`ticket_tag_mm`.`ticket_id` id')->innerJoin('ticket_tag_mm', '`tags`.`id` = `ticket_tag_mm`.`tag_id`')->where(['`tags`.`name`' => $tagSearchValues])->asArray()->all();
 }
Ejemplo n.º 3
0
 public function getAllItems($lastId = 0, $searchTag = "", $userId = false, $limit = false)
 {
     $query = Video::find()->from(["v" => Video::tableName()])->joinWith(['items i'])->andWhere('i.deleted = 0')->orderBy('id DESC');
     // Определяем за какой период будем показывать
     if (!empty($limit)) {
         $query = $query->limit((int) $limit);
     } else {
         $query = $query->limit(100);
     }
     if ($lastId != 0) {
         $query = $query->andWhere('i.id < :id', [':id' => $lastId]);
     }
     if (!empty($userId)) {
         $query = $query->andWhere('i.user_id = :userId', [':userId' => $userId]);
     }
     if (!empty($searchTag)) {
         if (is_array($searchTag)) {
             $tagsId = $searchTag;
         } else {
             $tags = Tags::find()->where(['name' => $searchTag])->all();
             $tagsId = [];
             foreach ($tags as $tag) {
                 $tagsId[] = (int) $tag->id;
             }
         }
         if (count($tagsId) > 0) {
             $query = $query->andWhere('(SELECT COUNT(*) as tagCount FROM `' . TagEntity::tableName() . '` te WHERE te.entity = "' . TagEntity::ENTITY_ITEM . '" AND te.entity_id = i.id  AND te.tag_id IN (' . join(',', $tagsId) . ')) > 0');
         }
     }
     return $query->all();
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param boolean $searchPool (-1 Completed, 0 Backlog, otherwise all)
  *
  * @return ActiveDataProvider
  */
 public function search($params, $searchPool = null)
 {
     switch ($searchPool) {
         case -1:
             $query = self::findCompleted();
             break;
         case 0:
             $query = self::findBacklog();
             break;
         default:
             $query = self::find();
             break;
     }
     $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;
     }
     // If Create From Date given add to query
     $query->andFilterWhere(['>=', 'created_at', $this->from_date]);
     // If Created To Date given add to query
     $query->andFilterWhere(['<=', 'created_at', $this->to_date]);
     // If Text search given, search for text in title and description
     $query->andFilterWhere(['or', ['like', 'title', $this->text_search], ['like', 'description', $this->text_search]]);
     // If Users selected, restrict ticket search to the selected users (as created by)
     $query->andFilterWhere(['created_by' => $this->user_search]);
     if (trim($this->tag_search) != '') {
         $query->andFilterWhere(['id' => Tags::getTicketId($this->tag_search)]);
     }
     return $dataProvider;
 }
Ejemplo n.º 5
0
 /**
  * return tag's model
  * @param int $id
  * @return Tags
  * @throws NotFoundHttpException
  */
 public function getTag($id)
 {
     if (($model = Tags::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist');
     }
 }
Ejemplo n.º 6
0
 public static function getTags($tagGroup)
 {
     $tags = Tags::findAll(['tag_group' => $tagGroup]);
     $result = [];
     foreach ($tags as $tag) {
         $result[] = $tag->getName();
     }
     return $result;
 }
Ejemplo n.º 7
0
 /**
  * Редактирование поста.
  * @param string $id идентификатор редактируемого поста
  * @return string|Response
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'authors' => User::find()->all(), 'tags' => Tags::find()->all(), 'category' => Category::find()->all()]);
     }
 }
Ejemplo n.º 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tags::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, 'frequency' => $this->frequency]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Ejemplo n.º 9
0
 public function getAllItems($lastId = 0, $orderBy = self::ORDER_BY_ID, $dateCreateType = self::DATE_CREATE_LAST, $searchTag = "", $userId = false, $limit = false)
 {
     $query = Item::find()->from(["t" => Item::tableName()])->andWhere('t.deleted = 0')->addSelect('*');
     if ($lastId != 0) {
         $query = $query->andWhere('t.id < :id', [':id' => $lastId]);
     }
     // Определяем сортировку
     if ($orderBy == self::ORDER_BY_ID) {
         $query = $query->orderBy('id DESC');
     } elseif ($orderBy == self::ORDER_BY_LIKE) {
         $query = $query->orderBy('like_count DESC');
     } elseif ($orderBy == self::ORDER_BY_SHOW) {
         $query = $query->orderBy('show_count DESC');
     } elseif ($orderBy == self::ORDER_BY_LIKE_SHOW) {
         $query = $query->addSelect(['(like_count * 15 + show_count) as like_show_count'])->orderBy('like_show_count DESC');
     }
     // Определяем за какой период будем показывать
     if (!empty($limit)) {
         $query = $query->limit((int) $limit);
     } elseif ($dateCreateType == self::DATE_CREATE_LAST) {
         $query = $query->limit(10);
     } elseif ($dateCreateType == self::DATE_CREATE_ALL) {
         $query = $query->limit(50);
     } elseif ($dateCreateType == self::DATE_CREATE_WEEK) {
         $query = $query->andWhere('t.date_create >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 WEEK))');
     } elseif ($dateCreateType == self::DATE_CREATE_MONTH) {
         $query = $query->andWhere('t.date_create >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
     }
     if (!empty($userId)) {
         $query = $query->andWhere('user_id = :userId', [':userId' => $userId]);
     }
     if (!empty($searchTag)) {
         if (is_array($searchTag)) {
             $tagsId = $searchTag;
         } else {
             $tags = Tags::find()->where(['name' => $searchTag])->all();
             $tagsId = [];
             foreach ($tags as $tag) {
                 $tagsId[] = (int) $tag->id;
             }
         }
         if (count($tagsId) > 0) {
             $query = $query->andWhere('(SELECT COUNT(*) as tagCount FROM `' . TagEntity::tableName() . '` te WHERE te.entity = "' . TagEntity::ENTITY_ITEM . '" AND te.entity_id = t.id  AND te.tag_id IN (' . join(',', $tagsId) . ')) > 0');
         }
     }
     $query = $query->with(['videos', 'tagEntity', 'tagEntity.tags']);
     return $query->all();
 }
Ejemplo n.º 10
0
                        </li>
                    <?php 
    }
    ?>

                <?php 
}
?>
            </ul>
        </div>
        <div class="column-one-fourth">
            <h5 class="line"><span>Теги</span></h5>

            <ul>
                <?php 
if ($tags = \common\models\Tags::getPopular()) {
    ?>
                    <?php 
    foreach ($tags as $tag) {
        ?>
                        <li><?php 
        echo \yii\helpers\Html::encode($tag->name);
        ?>
</li>
                    <?php 
    }
    ?>
                <?php 
}
?>
            </ul>
Ejemplo n.º 11
0
 /**
  * Return Tag list as ['id'=>'name']
  * @return array
  */
 public function getListTags()
 {
     return ArrayHelper::map(Tags::find()->all(), 'name', 'name');
 }
Ejemplo n.º 12
0
 /**
  * Creates a new Posts model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('create-post')) {
         $modelPost = new Posts();
         $model = new Postt($modelPost);
         if (Yii::$app->request->isAjax && $model->load($_POST)) {
             Yii::$app->response->format = 'json';
             return ActiveForm::validate($model);
         }
         if ($model->load(Yii::$app->request->post())) {
             /*
              * get the instance of the uploaded file
              */
             //            $imagename = $model->title;
             //            $model->file = UploadedFile::getInstance($model, 'file');
             //            $model->file->saveAs('uploads/'. $imagename.'.'.$model->file->extension);
             //save the path in the db
             //            $model->logo = 'uploads/'. $imagename.'.'.$model->file->extension;
             $model->save();
             //                print_r($model->getErrors());
             //                return $this->redirect(['view', 'id' => $model->id]);
             return $this->redirect(['index']);
         } else {
             //                $model->id = Yii::$app->user->id;
             //                $model->loadDefaultValues();
             return $this->renderAjax('create', ['model' => $model, 'tags' => Tags::find()->all(), 'authors' => Author::find()->all()]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
Ejemplo n.º 13
0
 public static function getPopular($count = 10)
 {
     return Tags::find()->orderBy(["cnt" => SORT_DESC])->limit(10)->all();
 }
Ejemplo n.º 14
0
 public static function fillTags($content, $id_news)
 {
     if ($tagList = KeywordDetector::detect($content)) {
         foreach ($tagList as $tagName) {
             $tagName = NewsParserComponent::replace4byte($tagName);
             $tag = Tags::findOne(['name' => $tagName]);
             if (!$tag) {
                 $tag = new Tags();
                 $tag->name = $tagName;
                 $tag->cnt = 0;
                 $tag->save();
             }
             $nht = new NewsHasTags();
             $nht->news_id = $id_news;
             $nht->tag_id = $tag->id;
             if ($nht->save()) {
                 $tag->updateCounters(['cnt' => 1]);
             }
         }
     }
 }
Ejemplo n.º 15
0
 public function actionEdit($id)
 {
     /** @var Event $event */
     $event = Event::findOne($id);
     if ($event->user_id != User::thisUser()->id || $event->deleted) {
         return Yii::$app->getResponse()->redirect($event->getUrl());
     }
     if ($event && $event->load(Yii::$app->request->post())) {
         $eventPost = Yii::$app->request->post('Event');
         $event->country = $eventPost['country'];
         $event->description = \yii\helpers\HtmlPurifier::process($event->description, []);
         $event->date = strtotime($eventPost['date']);
         if ($event->save()) {
             // Добавляем картинки к записи
             $imgs = Yii::$app->request->post('imgs');
             if (!empty($imgs) && is_array($imgs)) {
                 $event->saveImgs($imgs);
             } else {
                 $event->saveImgs([]);
             }
             TagEntity::deleteAll(['entity' => TagEntity::ENTITY_EVENT, 'entity_id' => $event->id]);
             $tagsArr = explode(',', Yii::$app->request->post('tags'));
             $tags = array_shift($tagsArr);
             $event->saveTags($tags);
             $event->saveLocations(Yii::$app->request->post('location'));
             return Yii::$app->getResponse()->redirect($event->getUrl());
         }
     }
     Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL);
     return $this->render('edit', ['event' => $event]);
 }
Ejemplo n.º 16
0
 /**
  * 
  * @param integer $entityId  Entity Id
  * @param integer $entityType Entity Type Id
  * @param string $tag Media tag
  */
 public function removeAsset($entityId, $entityType, $tag)
 {
     $tag = Tags::findOne(['name' => $tag]);
     if ($tag) {
         \yii::trace('delete Media Tags Ids:' . $tag->Id);
         Tagmap::deleteAll(['entityId' => $entityId, 'entityType' => $entityType, 'tagId' => $tag->Id]);
         Tagassetmap::deleteAll(['tagId' => $tag->Id]);
     }
 }
Ejemplo n.º 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTags()
 {
     return $this->hasMany(Tags::className(), ['id' => 'tag_id'])->viaTable('ticket_tag_mm', ['ticket_id' => 'id']);
 }
Ejemplo n.º 18
0
 public function getTagPost()
 {
     return $this->hasMany(Tags::className(), ['id' => 'tag_id'])->viaTable(TagPost::tableName(), ['post_id' => 'id']);
 }
Ejemplo n.º 19
0
 public function getTag()
 {
     return $this->hasOne(Tags::className(), ['id' => 'tag_id']);
 }
Ejemplo n.º 20
0
 public function actionEdit($id)
 {
     /** @var Item $item */
     $item = Item::findOne($id);
     if ($item->user_id != User::thisUser()->id || $item->deleted) {
         return Yii::$app->getResponse()->redirect($item->getUrl());
     }
     if ($item && $item->load(Yii::$app->request->post())) {
         $item->description = \yii\helpers\HtmlPurifier::process($item->description, []);
         if ($item->save()) {
             EntityLink::deleteAll(['entity_1' => Item::THIS_ENTITY, 'entity_1_id' => $item->id, 'entity_2' => Video::THIS_ENTITY]);
             // Добавление видео к записи
             $videosUrl = Yii::$app->request->post('videos');
             if (!empty($videosUrl) && is_array($videosUrl)) {
                 $item->saveVideos($videosUrl, $item->user_id);
             }
             // Добавляем аудиозаписи к записи
             $sounds = Yii::$app->request->post('sounds');
             if (!empty($sounds) && is_array($sounds)) {
                 $item->saveSounds($sounds);
             } else {
                 $item->saveSounds([]);
             }
             // Добавляем картинки к записи
             $imgs = Yii::$app->request->post('imgs');
             if (!empty($imgs) && is_array($imgs)) {
                 $item->saveImgs($imgs);
             } else {
                 $item->saveImgs([]);
             }
             TagEntity::deleteAll(['entity' => TagEntity::ENTITY_ITEM, 'entity_id' => $item->id]);
             $tags = explode(',', Yii::$app->request->post('tags'));
             if (is_array($tags)) {
                 $item->saveTags($tags);
             }
             return Yii::$app->getResponse()->redirect($item->getUrl());
         }
     }
     Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL);
     return $this->render('edit', ['item' => $item]);
 }
Ejemplo n.º 21
0
 /**
  * Finds the Tags model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tags the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Tags::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 22
0
 public function actionEdit($id)
 {
     /** @var School $school */
     $school = School::findOne($id);
     if ($school->user_id != User::thisUser()->id || $school->deleted) {
         return Yii::$app->getResponse()->redirect($school->getUrl());
     }
     if ($school && $school->load(Yii::$app->request->post())) {
         $schoolPost = Yii::$app->request->post('School');
         $school->country = $schoolPost['country'];
         $school->description = \yii\helpers\HtmlPurifier::process($school->description, []);
         if ($school->save()) {
             // Добавляем картинки к записи
             $imgs = Yii::$app->request->post('imgs');
             if (!empty($imgs) && is_array($imgs)) {
                 $school->saveImgs($imgs);
             } else {
                 $school->saveImgs([]);
             }
             TagEntity::deleteAll(['entity' => TagEntity::ENTITY_SCHOOL, 'entity_id' => $school->id]);
             $tagsArr = explode(',', Yii::$app->request->post('tags'));
             $school->saveTags($tagsArr);
             $school->saveLocations(Yii::$app->request->post('location'));
             return Yii::$app->getResponse()->redirect($school->getUrl());
         }
     }
     Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL);
     return $this->render('edit', ['school' => $school]);
 }