示例#1
0
 public function api_items($options = [])
 {
     if (!$this->_items) {
         $this->_items = [];
         //$with = ['seo', 'category'];
         $with = ['category'];
         if (Yii::$app->getModule('populac')->activeModules['article']->settings['enableTags']) {
             $with[] = 'tags';
         }
         $query = Item::find()->with($with)->status(Item::STATUS_ON);
         if (!empty($options['where'])) {
             $query->andFilterWhere($options['where']);
         }
         if (!empty($options['tags'])) {
             $query->innerJoinWith('tags', false)->andWhere([Tag::tableName() . '.name' => (new Item())->filterTagValues($options['tags'])])->addGroupBy('item_id');
         }
         if (!empty($options['orderBy'])) {
             $query->orderBy($options['orderBy']);
         } else {
             $query->sort();
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]);
         foreach ($this->_adp->models as $model) {
             $this->_items[] = new ArticleObject($model);
         }
     }
     return $this->_items;
 }
示例#2
0
 public function actionList($query)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $items = [];
     $query = urldecode(mb_convert_encoding($query, "UTF-8"));
     foreach (Tag::find()->where(['like', 'name', $query])->asArray()->all() as $tag) {
         $items[] = ['name' => $tag['name']];
     }
     return $items;
 }
示例#3
0
 public function beforeDelete()
 {
     $pks = [];
     foreach ($this->owner->tags as $tag) {
         $pks[] = $tag->primaryKey;
     }
     if (count($pks)) {
         Tag::updateAllCounters(['frequency' => -1], ['in', 'id', $pks]);
     }
     Tag::deleteAll(['frequency' => 0]);
     TagAssign::deleteAll(['class' => get_class($this->owner), 'item_id' => $this->owner->primaryKey]);
 }