/**
  * 列表页
  * @param integer $taxonomy
  * @return \yii\base\string
  */
 public function actionList($taxonomy = -1)
 {
     $query = Content::findPublished(['content_type' => $this->content_type]);
     if (intval($taxonomy) > 0) {
         $query->andFilterWhere(['taxonomy_id' => intval($taxonomy)]);
     }
     $taxonomyModel = $this->taxonomyService->getTaxonomyById($taxonomy);
     LuLu::setViewParam(['taxonomyModel' => $taxonomyModel]);
     $vars = $this->getListVars($taxonomyModel);
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => $vars['pageSize']]);
     $locals['taxonomyModel'] = $taxonomyModel;
     $this->layout = $vars['layout'];
     return $this->render($vars['view'], $locals);
 }
예제 #2
0
 private static function buildContentQuery($where = null, $options = [])
 {
     $query = Content::findPublished($where);
     if (isset($options['taxonomy'])) {
         $ids = [];
         if (is_array($options['taxonomy'])) {
             foreach ($options['taxonomy'] as $t) {
                 if (intval($t) > 0) {
                     $ids[] = intval($t);
                 }
             }
         } else {
             if (intval($options['taxonomy']) > 0) {
                 $ids = intval($options['taxonomy']);
             }
         }
         if (!empty($ids)) {
             $query->andWhere(['taxonomy_id' => $ids]);
         }
     }
     foreach (['recommend', 'headline', 'sticky'] as $att) {
         if (isset($options[$att]) && is_integer($options[$att])) {
             $query->andWhere([$att => $options[$att]]);
         }
     }
     if (isset($options['flag'])) {
         $flagValue = Common::getFlagValue($options['flag']);
         if ($flagValue > 0) {
             $query->andWhere('flag&' . $flagValue . '>0');
         }
     }
     if (isset($options['is_pic'])) {
         $query->andWhere(['!=', 'thumb', '']);
     }
     if (isset($options['content_type'])) {
         if (is_string($options['content_type'])) {
             $type = $options['content_type'];
         } else {
             $module = LuLu::$app->controller->module;
             if (!$module instanceof Application) {
                 $type = $module->id;
             }
         }
         if (!empty($type)) {
             $query->andWhere(['content_type' => $options['content_type']]);
         }
     }
     return $query;
 }