123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\forks\ListView;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Html;
- class ListView extends \yii\widgets\ListView
- {
- /**
- * Runs the widget.
- */
- public function run()
- {
- $content = preg_replace_callback('/{\\w+}/', function ($matches) {
- $content = $this->renderSection($matches[0]);
- return $content === false ? $matches[0] : $content;
- }, $this->layout);
- $options = $this->options;
- $tag = ArrayHelper::remove($options, 'tag', 'div');
- echo Html::tag($tag, $content, $options);
- }
- /**
- * Renders all data models.
- * @return string the rendering result
- */
- public function renderItems()
- {
- try{
- $pageStart = new \DateTime(\Yii::$app->request->get("page","now"));
- } catch (\Exception $exception){
- $pageStart = new \DateTime("now");
- }
- $pageStart->setTime(0,0,0);
- $pageEnd = (clone $pageStart)->setTime(23,59,59);
- $query = clone $this->dataProvider->query;
- $pageQuery = clone $query;
- $pageQuery->andFilterWhere(["BETWEEN",'dt_pub',$pageStart->format("Y-m-d H:i:s"),$pageEnd->format("Y-m-d H:i:s")]);
- if($pageQuery->count()==0){
- //Такой странички не существует, кидаем на первую
- $pageQuery = clone $query;
- $pageQuery->limit(20);
- }
- $models = $pageQuery->all();
- $rows = [];
- if(count($models)==0){
- return "<span>К сожалению, за ".$pageStart->format("d.m.Y")." ничего нет</span>";
- }
- foreach (array_values($models) as $index => $model) {
- $key = $model->id;
- if (($before = $this->renderBeforeItem($model, $key, $index)) !== null) {
- $rows[] = $before;
- }
- $rows[] = $this->renderItem($model, $key, $index);
- if (($after = $this->renderAfterItem($model, $key, $index)) !== null) {
- $rows[] = $after;
- }
- }
- return implode($this->separator, $rows);
- }
- public function renderPager()
- {
- $pager['view'] = $this->getView();
- $pager['dataProvider'] = $this->dataProvider;
- return DatePager::widget($pager);
- }
- }
|