/** * 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(); }
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(); }
/** * Редактирование поста. * @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()]); } }
/** * 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; }
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(); }
/** * Lists all Tags models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Tags::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * 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(); } }
public static function getPopular($count = 10) { return Tags::find()->orderBy(["cnt" => SORT_DESC])->limit(10)->all(); }
/** * Return Tag list as ['id'=>'name'] * @return array */ public function getListTags() { return ArrayHelper::map(Tags::find()->all(), 'name', 'name'); }