private function setFormatters() { $currentPage = $this->dataProvider->getPagination()->getPage() + 1; $response = Yii::$app->response; $response->formatters[UrlsetResponseFormatter::FORMAT_URLSET] = new UrlsetResponseFormatter(['gzip' => $this->gzip, 'gzipFilename' => 'sitemap.' . $currentPage . '.xml.gz']); $response->format = UrlsetResponseFormatter::FORMAT_URLSET; }
/** * set Action Response Formatter */ protected function setFormatters() { $currentPage = $this->dataProvider->getPagination()->getPage() + 1; $response = Yii::$app->response; $formatter = new UrlsetResponseFormatter(['gzip' => $this->gzip, 'gzipFilename' => 'sitemap.' . $currentPage . '.xml.gz']); $xmlns = $this->xmlns; if (null === $xmlns) { $xmlns = call_user_func([$this->urlClass, 'getXmlns']); } $formatter->addXmlns($xmlns); $response->formatters[UrlsetResponseFormatter::FORMAT_URLSET] = $formatter; $response->format = UrlsetResponseFormatter::FORMAT_URLSET; }
public function actionList($event_id) { \Yii::$app->response->format = Response::FORMAT_JSON; $dp = new ActiveDataProvider(); $dp->query = Comment::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]); $dp->pagination->pageSize = 6; return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()]; }
/** * Lists all MyClick models. * @return mixed */ public function actionIndex() { $query = (new \yii\db\Query())->select('article.*')->from('my_click')->where(['user_id' => \Yii::$app->user->id])->orderBy('my_click.id DESC'); $click_query = $query->limit(50)->join('LEFT JOIN', 'article', 'article.id = my_click.article_id'); $provide = new ActiveDataProvider(['query' => $click_query, 'pagination' => ['pageSize' => 10]]); $provide->prepare(); $pagination = $provide->getPagination(); return $this->render('index', ['data' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]); }
public function actionRead($id) { $taxonomy = Taxonomy::findByIdOrSlug($id); $children = $taxonomy->children()->all(); $ids = ArrayHelper::getColumn($children, "taxonomy_id"); array_unshift($ids, $taxonomy->getPrimaryKey()); $dataProvider = new ActiveDataProvider(['query' => TaxonomyIndex::find()->select(['entity', 'entity_id'])->distinct()->where(["taxonomy_id" => $ids])->orderBy(['taxonomy_index_id' => SORT_DESC]), 'pagination' => ['pageSize' => 15]]); list($title, $desc, $keys) = $taxonomy->getMetaData(); $this->getView()->setMetaData($title, $desc, $keys); return $this->render('view', ['taxonomyIndexs' => $dataProvider->getModels(), "pagination" => $dataProvider->getPagination(), "taxonomy" => $taxonomy]); }
public function actionIndex() { if (\Yii::$app->user->isGuest) { $this->redirect(['user/sign-in/login']); } $article = (new Query())->from('article')->all(); $query = Article::find(); $provide = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC, 'title' => 'simon']]]); $provide->prepare(); $pagination = $provide->getPagination(); return $this->render('index', ['article' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]); }
/** * * @return type */ public function run() { $data = new ActiveDataProvider(['query' => $this->query, 'pagination' => ['class' => Pagination::class, 'pageSize' => $this->recordOnPage]]); $data->query->addOrderBy($this->sort); if (Yii::$app->getRequest()->isAjax) { Yii::$app->getResponse()->format = Response::FORMAT_JSON; return $this->controller->renderPartial($this->view, ['model' => $data->getModels()]); } else { $this->controller->layout = $this->layout; return $this->controller->render($this->view, ['model' => $data->getModels(), 'pages' => $data->getPagination()]); } }
/** * Search by request criteria. * * @param array|null Filter params. * @return ActiveDataProvider Data provider. */ public function search($params) { $query = User::find()->with('roles'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date_create' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]); $dataProvider->getPagination()->setPageSize(Yii::$app->request->get('pageSize'), true); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['ip' => !empty($this->ip) ? ip2long($this->ip) : null, 'status' => $this->status, 'role' => $this->role, 'DATE(date_create)' => $this->date_create]); $query->andFilterWhere(['like', 'user.username', $this->username]); $query->andFilterWhere(['like', 'user.email', $this->email]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Country::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); //手动添加的分页 $dataProvider->getPagination()->pageSize = 5; $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(['population' => $this->population]); $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionView($slug) { $album = Gallery::cat($slug); if (!$album) { throw new \yii\web\NotFoundHttpException('无照片.'); } // 评论列表 $commentDataProvider = new ActiveDataProvider(['query' => Comment::find()->andWhere(['article_id' => $album->model->category_id, 'parent_id' => 0, 'comment_type' => 'gallery']), 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); //评论数 $commentNum = Comment::find()->andWhere(['article_id' => $slug, 'parent_id' => 0, 'comment_type' => 'gallery'])->count(1); $commentModels = $commentDataProvider->getModels(); $pages = $commentDataProvider->getPagination(); // 评论框 $commentModel = new Comment(); return $this->render('view', ['album' => $album, 'photos' => $album->photos(['pagination' => ['pageSize' => 10]]), 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'commentDataProvider' => $commentDataProvider, 'commentNum' => $commentNum]); }
/** * Displays a single Estimate model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $dataProvider = new ActiveDataProvider(['query' => $model->getEntries()->with('product.supplier')]); $dataProvider->sort = ['defaultOrder' => ['rank' => SORT_ASC]]; // Set last page as default $pagination = $dataProvider->getPagination(); $page = Yii::$app->request->getQueryParam($pagination->pageParam); if (!$page) { $pagination->totalCount = $dataProvider->getTotalCount(); $page = $pagination->getPageCount() - 1; $pagination->setPage($page); } if (Yii::$app->request->post('hasEditable')) { $id = Yii::$app->request->post('editableKey'); $entry = EstimateEntry::findOne($id); $out = Json::encode(['output' => '', 'message' => '']); $post = []; $posted = current($_POST['EstimateEntry']); $post['EstimateEntry'] = $posted; if ($entry->load($post)) { if ($entry->save()) { $entry->estimate->doEstimate(); } $output = ''; if (isset($posted['status'])) { $output = $entry->statusLabel; } $out = Json::encode(['output' => $output, 'message' => $entry->getErrors()]); } // return ajax json encoded response and exit echo $out; return; } return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider]); }
/** * Show topic with posts * @param $id integer topic_id * @param $nav string post-id or "last" */ public function actionTopic($id = null, $nav = null, $postId = null) { $id = $id ?: \Yii::$app->request->get('id'); $topic = BbiiTopic::findOne($id); if ($topic === null) { throw new HttpException(404, Yii::t('BbiiModule.bbii', 'The requested topic does not exist.')); } $forum = BbiiForum::findOne($topic->forum_id); if (\Yii::$app->user->isGuest && $forum->public == 0) { throw new HttpException(403, Yii::t('BbiiModule.bbii', 'You have no permission to read requested topic.')); } if ($forum->membergroup_id != 0) { if (\Yii::$app->user->isGuest) { throw new HttpException(403, Yii::t('BbiiModule.bbii', 'You have no permission to read requested topic.')); } elseif (!$this->isModerator()) { $groupId = BbiiMember::find(\Yii::$app->user->identity->id)->one()->group_id; if ($forum->membergroup_id != $groupId) { throw new HttpException(403, Yii::t('BbiiModule.bbii', 'You have no permission to read requested topic.')); } } } /* $dataProvider = new ActiveDataProvider( 'BbiiPost', array( 'criteria' => array( 'condition' => 'approved = 1 and topic_id = ' . $topic->id, 'order' => 't.id', 'with' => array('poster'), ), 'pagination' => array( 'pageSize' => $this->module->postsPerPage, ), )); */ $dataProvider = new ActiveDataProvider(['query' => BbiiPost::find()->where('approved = 1 and topic_id = ' . $topic->id)->orderBy('id ASC')]); // @todo Poll not enabled for inital release - DJE : 2015-05-27 // Determine poll /* $criteria = new CDbCriteria; $criteria->condition = 'post_id = ' . $topic->first_post_id; $this->poll = BbiiPoll::find()->find($criteria); if ($this->poll !== null) { $this->choiceProvider = new ActiveDataProvider('BbiiChoice', array( 'criteria' => array( 'condition' => 'poll_id = ' . $this->poll->id, 'order' => 'sort', ), 'pagination' => false, )); // Determine whether user has voted if (\Yii::$app->user->isGuest) { $this->voted = true; // A guest may not vote and sees the result immediately } else { $criteria->condition = 'poll_id = ' . $this->poll->id . ' and user_id = ' . \Yii::$app->user->identity->id ; $this->voted = BbiiVote::find()->exists($criteria); } // Determine wheter the poll has expired if (!$this->voted && isset($this->poll->expire_date) && $this->poll->expire_date < date('Y-m-d')) { $this->voted = true; } } */ // Navigate to a post in a topic if (isset($nav)) { $cPage = $dataProvider->getPagination(); if (is_numeric($nav)) { $criteria->condition = 'topic_id = ' . $topic->id . ' and id < = ' . $nav . ' and approved = 1'; $count = BbiiPost::find()->count($criteria); $page = ceil($count / $cPage->pageSize); $post = $nav; } else { $page = ceil($dataProvider->totalItemCount / $cPage->pageSize); $post = $topic->last_post_id; } if (\Yii::$app->user->hasFlash('moderation')) { \Yii::$app->session->addFlash('moderation', \Yii::$app->user->getFlash('moderation'), true); } return \Yii::$app->response->redirect(array('forum/forum/topic', 'id' => $id, 'BbiiPost_page' => $page, 'postId' => $post)); } // Increase topic views $topic->updateCounters(array('num_views' => 1)); // Register the last visit of a topic if (!\Yii::$app->user->isGuest) { $object = new BbiiTopicsRead(); $model = BbiiTopicRead::find()->where(['user_id' => \Yii::$app->user->identity->id])->one(); if (empty($model->data)) { $model = new BbiiTopicRead(); $model->user_id = \Yii::$app->user->identity->id; } else { $object->unserialize($model->data); } $object->setRead($topic->id, $topic->last_post_id); if ($object->follows($topic->id)) { $object->setFollow($topic->id, $topic->last_post_id); } $model->setAttribute('data', $object->serialize()); if (!$model->validate() || !$model->save()) { \Yii::$app->session->addFlash('moderation', Yii::t('BbiiModule.bbii', 'Error saving data.')); } } return $this->render('topic', array('dataProvider' => $dataProvider, 'forum' => $forum, 'postId' => $postId, 'topic' => $topic)); }
/** * * @param array $data [page, limit, sort_column, sort_order, filters=json] * @return multitype:multitype:Ambigous <NULL> multitype:unknown string |\stdClass */ public static function jgridBooks(array $data) { $query = self::jqgridPepareQuery($data); $data['limit'] = empty($data['limit']) || $data['limit'] <= 0 || $data['limit'] > 30 ? 10 : $data['limit']; $data['page'] = empty($data['page']) || $data['page'] <= 0 ? 1 : $data['page']; $provider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $data['limit'], 'page' => $data['page'] - 1]]); $books = $provider->getModels(); $to_array = function ($obj_arr, $query) { $ar = []; foreach ($obj_arr as $o) { /* @var $o Books */ $book = []; $attr = $o->getAttributes($o->fields()); //jgrid required no assoc array same order foreach ($query->select as $col) { if ($col == 'created_date') { $book[] = \Yii::$app->formatter->asDate($attr[$col], 'php:d-m-Y'); } else { $book[] = $attr[$col]; } } $ar[] = ['id' => $attr['book_guid'], 'cell' => $book]; } return $ar; }; return self::jqgridPrepareResponse($provider->getPagination()->getPage(), $provider->getPagination()->getPageCount(), $provider->getTotalCount(), $to_array($books, $query)); }
public function initDataProvider() { $this->search = new Search(CmsContentElement::className()); $this->dataProvider = $this->search->getDataProvider(); if ($this->enabledPaging == Cms::BOOL_Y) { $this->dataProvider->getPagination()->defaultPageSize = $this->pageSize; $this->dataProvider->getPagination()->pageParam = $this->pageParamName; $this->dataProvider->getPagination()->pageSizeLimit = [(int) $this->pageSizeLimitMin, (int) $this->pageSizeLimitMax]; } else { $this->dataProvider->pagination = false; } if ($this->orderBy) { $this->dataProvider->getSort()->defaultOrder = [$this->orderBy => (int) $this->order]; } return $this; }
public function actionTestl() { echo "sss"; $dataProvider = new ActiveDataProvider(['query' => Appcomments::find()]); //$dataProvider->keys; //$dataProvider->models; /*$dataProvider->setPagination(false); $mymodel=$dataProvider->models; foreach ($mymodel as $model){ echo $model['appid']; }*/ $pagination = $dataProvider->getPagination(); var_dump($pagination->page); $count = 0; while ($categories = $dataProvider->models) { /*foreach ($categories as $model) { $model['appid']=0; }*/ //echo $pagination->page=1+$count; $count++; $dataProvider->setPagination($count); } //$mymodel[4]['kind']="bbbbbb"; //$dataProvider->setModels($mymodel); //var_dump($dataProvider->models[4]['kind']); //echo $dataProvider->models; }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Post::find()->orderBy(['id' => SORT_DESC]), 'pagination' => ['pageSize' => 15]]); $this->getView()->setMetaData(\Yii::$app->get("config")->get("app.name"), \Yii::$app->get("config")->get("app.description"), \Yii::$app->get("config")->get("app.keywords")); return $this->render('index', ["posts" => $dataProvider->getModels(), "pagination" => $dataProvider->getPagination()]); }
echo Url::to(['ajax/deletecomment', 'id' => $comment['id']]); ?> "><?php echo \Yii::t('app', 'Удалить комментарий'); ?> </a> </p> <?php } ?> </div> <?php } ?> <?php echo LinkPager::widget(['pagination' => $provider->getPagination()]); ?> </div> <?php if (!Yii::$app->user->isGuest) { ?> <script> var editor = CKEDITOR.replace('CommentForm[body]', { language: '<?php echo Yii::$app->session->has('language') ? Yii::$app->session->get('language') : 'ru'; ?> ', }); $('#deletePhoto').click(function () { $.ajax({ url: '<?php
public function actionTest() { echo "test"; $dataProvider = new ActiveDataProvider(['query' => app::find()]); $pagination = $dataProvider->getPagination(); $count = $pagination->pageCount; $count1 = 0; while ($categories = $dataProvider->models) { foreach ($categories as $category) { echo $category['id']; } $count1++; if ($count1 > $count) { break; } } }
/** * * @param unknown $id */ public function actionRead($id) { $dataProvider = new ActiveDataProvider(['query' => TagIndex::find()->where(["tag_id" => $id]), 'pagination' => ['pageSize' => 15]]); return $this->render('view', ['tagIndexs' => $dataProvider->getModels(), "pagination" => $dataProvider->getPagination()]); }
/** * Возвращает созданные события * @param $id Ид пользователя * @return mixed * @throws NotFoundHttpException */ public function actionEventsCreated($id) { /** * @var User $user */ if (!\Yii::$app->request->isAjax) { throw new NotFoundHttpException(); } $params = array_merge(['pageSize' => 12], $_GET); $user = User::findOne($id); if (!$user) { throw new NotFoundHttpException(); } $dp = new ActiveDataProvider(); $dp->getPagination()->pageSize = $params['pageSize']; $dp->query = $user->getEventCreate()->checkSubscribe()->orderBy('event.id DESC'); return $this->renderCollection($dp); }
public function testPaginationBeforeModels() { $query = new Query(); $provider = new ActiveDataProvider(['db' => $this->getConnection(), 'query' => $query->from('order')->orderBy('id')]); $pagination = $provider->getPagination(); $this->assertEquals(0, $pagination->getPageCount()); $this->assertCount(3, $provider->getModels()); $this->assertEquals(1, $pagination->getPageCount()); $provider->getPagination()->pageSize = 2; $this->assertEquals(3, count($provider->getModels())); $provider->refresh(); $this->assertEquals(2, count($provider->getModels())); }
/** * @param $event_id * @return array Вывод подписчиков на страницу события * Вывод подписчиков на страницу события * @throws \yii\web\NotFoundHttpException */ public function actionEventSubscribers($event_id) { if (!\Yii::$app->request->isAjax) { throw new NotFoundHttpException(); } \Yii::$app->response->format = Response::FORMAT_JSON; $dp = new ActiveDataProvider(); $dp->query = EventSubscriber::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]); $dp->pagination->pageSize = 12; return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()]; }
public function actionTopic($id, $nav = null, $postId = null) { $topic = YBoardTopic::findOne($id); if ($topic === null) { throw new NotFoundHttpException(YBoard::t('yboard', 'The requested topic does not exist.')); } $replyModel = new YBoardPost(); $replyModel->topic_id = $topic->id; $replyModel->subject = YBoard::t('yboard', 're:') . $topic->title; $forum = YBoardForum::findOne($topic->forum_id); if (Yii::$app->user->isGuest && $forum->public == 0) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } if ($topic->approved == 0 && !Yii::$app->user->can('moderator')) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } if ($forum->membergroup_id != 0) { if (Yii::$app->user->isGuest) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } elseif (!Yii::$app->user->can('moderator')) { $groupId = YBoardMember::findOne(Yii::$app->user->id)->group_id; if ($forum->membergroup_id != $groupId) { throw new ForbiddenHttpException(YBoard::t('yboard', 'You have no permission to read requested topic.')); } } } $dataProvider = new ActiveDataProvider(['query' => YBoardPost::find()->where(['approved' => 1])->andWhere(['topic_id' => $topic->id])->orderBy('id')->with('poster'), 'pagination' => array('pageSize' => $this->module->postsPerPage)]); // Determine poll $this->poll = YBoardPoll::find()->where(['post_id' => $topic->first_post_id])->one(); if ($this->poll !== null) { $this->choiceProvider = new ActiveDataProvider(['query' => YBoardChoice::find()->where(['poll_id' => $this->poll->id])->orderBy('sort'), 'pagination' => false]); // Determine whether user has voted if (Yii::$app->user->isGuest) { $this->voted = true; // A guest may not vote and sees the result immediately } else { $this->voted = YBoardVote::find()->where(['poll_id' => $this->poll->id])->andWhere(['user_id' => Yii::$app->user->id])->exists(); } // Determine wheter the poll has expired if (!$this->voted && isset($this->poll->expire_date) && $this->poll->expire_date < date('Y-m-d')) { $this->voted = true; } } // Navigate to a post in a topic if (isset($nav)) { $cPage = $dataProvider->getPagination(); if (is_numeric($nav)) { $count = YBoardPost::find()->where('topic_id = ' . $topic->id . ' and id <= ' . $nav . ' and approved = 1')->count(); $page = ceil($count / $cPage->pageSize); $post = $nav; } else { $page = ceil($dataProvider->totalCount / $cPage->pageSize); $post = $topic->last_post_id; } if (Yii::$app->session->hasFlash('moderation')) { Yii::$app->session->setFlash('moderation', Yii::$app->session->getFlash('moderation')); } //set current page to calculated if we are having last page if (!isset($_GET['per-page'])) { $dataProvider->pagination->page = $page - 1; } //pages are 0 indexed } // Increase topic views $topic->updateCounters(['num_views' => 1]); // Register the last visit of a topic if (!Yii::$app->user->isGuest) { $topicLog = YBoardLogTopic::findOne(['member_id' => Yii::$app->user->id, 'topic_id' => $topic->id]); if ($topicLog === null) { $topicLog = new YBoardLogTopic(); $topicLog->member_id = Yii::$app->user->id; $topicLog->topic_id = $topic->id; $topicLog->forum_id = $topic->forum_id; } $topicLog->last_post_id = $topic->last_post_id; $topicLog->save(); } return $this->render('topic', array('forum' => $forum, 'reply' => $replyModel, 'topic' => $topic, 'dataProvider' => $dataProvider, 'choiceProvider' => $this->choiceProvider, 'postId' => $postId)); }