/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $random = [];
     if (Yii::$app->session->has('random')) {
         $random = Yii::$app->session->get('random');
     }
     $query = Main::find()->joinWith(['mainTrashPlaces', 'mainTrashMen', 'mainTrashRecycles', 'mainTrashRelations', 'mainRubberItems']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (isset($params['MainSearch']['region']) && $params['MainSearch']['region'] == -1) {
         unset($params['MainSearch']['region']);
     }
     $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->select('main.*');
     $query->distinct();
     $query->andFilterWhere(['region' => $this->region, 'city' => $this->city, 'type' => $this->type, 'resident' => $this->resident, 'children' => $this->children, 'employee' => $this->employee, 'retiree' => $this->retiree, 'dominant' => $this->dominant, 'trash_man' => $this->trash_man, 'trash_out' => $this->trash_out, 'trash_count' => $this->trash_count, 'trash_count_summer' => $this->trash_count_summer, 'trash_count_winter' => $this->trash_count_winter, 'paper' => $this->paper, 'trash_relation' => $this->trash_relation, 'trash_recycle' => $this->trash_recycle, 'person' => $this->person, 'id' => $this->id, 'main_trash_place.trash_place_id' => $this->getAttribute('places'), 'main_trash_man.trash_man_id' => $this->getAttribute('men'), 'main_trash_recycle.trash_recycle_id' => $this->getAttribute('recycles'), 'main_trash_relation.trash_relation_id' => $this->getAttribute('relations'), 'main_rubber_items.rubber_item_id' => $this->getAttribute('rubber_items')]);
     $query = $this->addBetween($query);
     if (!empty($random)) {
         $query->andFilterWhere(['IN', 'main.id', $random]);
     }
     $query->andFilterWhere(['like', 'answer_count', $this->answer_count])->andFilterWhere(['like', 'woman_count', $this->woman_count])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'interrogatory', $this->interrogatory]);
     return $dataProvider;
 }
Example #2
0
 public function actionIndex()
 {
     if (\Yii::$app->user->isGuest) {
         \Yii::$app->user->loginRequired();
     }
     $dataProvider = new ActiveDataProvider(['query' => Main::find()->with(['source', 'period', 'catalog'])->where(["user_id" => Yii::$app->user->identity->id]), 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['date' => SORT_DESC], 'attributes' => []]]);
     return $this->render('index', ["dataProvider" => $dataProvider]);
 }
Example #3
0
 /**
  * 获取热门
  *
  * @param 类型,1为问答,2为文章,3为笔记 $type            
  * @return Ambigous <multitype:, multitype:\yii\db\ActiveRecord , array, multitype:unknown >
  */
 public static function getHotMain($type, $name)
 {
     if (3 == $type) {
         $where = ['type' => 3, 'status' => 2];
     } else {
         $where = ['type' => $type];
     }
     return Main::find()->where($where)->andWhere(['like', 'tags', $name])->orderBy('scanNum DESC,id asc')->limit('10')->all();
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Main::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, 'catalog_id' => $this->catalog_id, 'date' => $this->date, 'enddate' => $this->enddate, 'period_id' => $this->period_id, 'source_id' => $this->source_id]);
     $query->andFilterWhere(['like', 'amount', $this->amount]);
     return $dataProvider;
 }
Example #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Main::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, 'status' => $this->status, 'userId' => $this->userId, 'createTime' => $this->createTime, 'scanNum' => $this->scanNum, 'cellectNum' => $this->cellectNum, 'attentionNum' => $this->attentionNum, 'type' => $this->type]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags]);
     return $dataProvider;
 }
Example #6
0
 public function actionNote()
 {
     $query = Main::find()->where(['type' => 3, 'status' => 2])->orderBy('id desc');
     $get = Yii::$app->request->get();
     if (isset($get['soft'])) {
         if ('hot' == $get['soft']) {
             // 热门
             $query = Main::find()->where(['type' => 3, 'status' => 2])->orderBy('scanNum DESC,id desc');
         }
     }
     $indexSql = clone $query;
     $pages = new Pagination(['totalCount' => $indexSql->count()]);
     $pages->defaultPageSize = 10;
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('note', ['ask' => $models, 'pages' => $pages, 'tags' => $this->getHotTag(), 'hotAsk' => $this->getHotAsk(3)]);
 }
 public function actionMain()
 {
     $params = Yii::$app->request->queryParams;
     $region = 1;
     if (!empty($params['MainSearch']['region'])) {
         $region = $params['MainSearch']['region'];
     }
     if (!empty($params['id'])) {
         $model = Main::find()->where(['id' => $params['id']])->one();
         $arrayParams = ['MainSearch' => ['region' => $model->region]];
     } else {
         $model = new Main();
         $model->region = $region;
         $arrayParams = ['MainSearch' => ['region' => $region]];
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if (!$model->isNewRecord) {
                 MainTrashPlace::deleteAll(['main_id' => $model->id]);
                 MainTrashMan::deleteAll(['main_id' => $model->id]);
                 MainTrashRelation::deleteAll(['main_id' => $model->id]);
                 MainTrashRecycle::deleteAll(['main_id' => $model->id]);
                 MainRubberItems::deleteAll(['main_id' => $model->id]);
             }
             $model->save();
             $main = Yii::$app->request->post()['Main'];
             if (!empty($main['places'])) {
                 foreach ($main['places'] as $value) {
                     $relationModel = new MainTrashPlace();
                     $relationModel->main_id = $model->id;
                     $relationModel->trash_place_id = $value;
                     $relationModel->save();
                 }
             }
             if (!empty($main['men'])) {
                 foreach ($main['men'] as $value) {
                     $relationModel = new MainTrashMan();
                     $relationModel->main_id = $model->id;
                     $relationModel->trash_man_id = $value;
                     $relationModel->save();
                 }
             }
             if (!empty($main['relations'])) {
                 foreach ($main['relations'] as $value) {
                     $relationModel = new MainTrashRelation();
                     $relationModel->main_id = $model->id;
                     $relationModel->trash_relation_id = $value;
                     $relationModel->save();
                 }
             }
             if (!empty($main['recycles'])) {
                 foreach ($main['recycles'] as $value) {
                     $relationModel = new MainTrashRecycle();
                     $relationModel->main_id = $model->id;
                     $relationModel->trash_recycle_id = $value;
                     $relationModel->save();
                 }
             }
             if (!empty($main['rubberItemsData'])) {
                 foreach ($main['rubberItemsData'] as $value) {
                     $relationModel = new MainRubberItems();
                     $relationModel->main_id = $model->id;
                     $relationModel->rubber_item_id = $value;
                     $relationModel->save();
                 }
             }
             $arrayParams['id'] = $model->id;
             $params = array_merge(["site/index"], $arrayParams);
             $url = Yii::$app->urlManager->createUrl($params);
             return $this->redirect($url);
         }
     }
     $model->places = ArrayHelper::getColumn($model->mainTrashPlaces, 'trash_place_id');
     $model->men = ArrayHelper::getColumn($model->mainTrashMen, 'trash_man_id');
     $model->relations = ArrayHelper::getColumn($model->mainTrashRelations, 'trash_relation_id');
     $model->recycles = ArrayHelper::getColumn($model->mainTrashRecycles, 'trash_recycle_id');
     $model->rubberItemsData = ArrayHelper::getColumn($model->mainRubberItems, 'rubber_item_id');
     return $this->render('main', ['model' => $model, 'region' => $region]);
 }
 public static function getMainData($region)
 {
     $random = [];
     if (Yii::$app->session->has('random')) {
         $random = Yii::$app->session->get('random');
     }
     $query = Main::find();
     if (!empty($random)) {
         $query->andFilterWhere(['IN', 'main.id', $random]);
     }
     if ($region != -1) {
         $query->andFilterWhere(['region' => $region]);
     }
     return $query->all();
 }