Exemple #1
0
 public function getPhotos()
 {
     if (!$this->_photos) {
         $this->_photos = [];
         foreach (Photo::find()->where(['class' => Item::className(), 'item_id' => $this->id])->sort()->all() as $model) {
             $this->_photos[] = new PhotoObject($model);
         }
     }
     return $this->_photos;
 }
Exemple #2
0
 public function items($options = [])
 {
     if (!$this->_items) {
         $this->_items = [];
         //$with = ['seo'];
         $with = [];
         if (Yii::$app->getModule('populac')->activeModules['article']->settings['enableTags']) {
             $with[] = 'tags';
         }
         //$query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sortDate();
         $query = Item::find()->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sort();
         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');
         }
         $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;
 }
Exemple #3
0
 private function findItem($id_slug)
 {
     $article = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     if ($article) {
         $article->updateCounters(['views' => 1]);
         return new ArticleObject($article);
     } else {
         return null;
     }
 }
Exemple #4
0
 public function actionDelete($id)
 {
     if ($model = Item::findOne($id)) {
         $model->delete();
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse(Yii::t('easyii/article', 'Article deleted'));
 }
Exemple #5
0
 public function getItems()
 {
     return $this->hasMany(Item::className(), ['category_id' => 'category_id'])->sort();
 }