Default all discussions view: chronological by most recent comment.

@since 2.0.0
@access public

@param int $Page Multiplied by PerPage option to determine offset.
559108
public function Index($Page = FALSE) {
      // Figure out which discussions layout to choose (Defined on "Homepage" settings page).
      $Layout = C('Vanilla.Discussions.Layout');
      switch($Layout) {
         case 'table':
            if ($this->SyndicationMethod == SYNDICATION_NONE)
               $this->View = 'table';
            break;
         default:
            // $this->View = 'index';
            break;
      }
      Gdn_Theme::Section('DiscussionList');
      
      // Determine offset from $Page
      list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
      $Page = PageNumber($Offset, $Limit);
      $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
      
      // We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
      $MaxPages = C('Vanilla.Discussions.MaxPages');
      if ($MaxPages && $Page > $MaxPages) {
         throw NotFoundException();
      }
      
      // Setup head.
      if (!$this->Data('Title')) {
         $Title = C('Garden.HomepageTitle');
         if ($Title)
            $this->Title($Title, '');
         else
            $this->Title(T('Recent Discussions'));
      }
      if (!$this->Description())
         $this->Description(C('Garden.Description', NULL));
      if ($this->Head)
         $this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
      
      // Add modules
      $this->AddModule('DiscussionFilterModule');
      $this->AddModule('NewDiscussionModule');
      $this->AddModule('CategoriesModule');
      $this->AddModule('BookmarkedModule');
      $this->SetData('Breadcrumbs', array(array('Name' => T('Recent Discussions'), 'Url' => '/discussions')));
      
      
      // Set criteria & get discussions data
      $this->SetData('Category', FALSE, TRUE);
      $DiscussionModel = new DiscussionModel();
      $DiscussionModel->Watching = TRUE;
      
      // Get Discussion Count
      $CountDiscussions = $DiscussionModel->GetCount();
      
      if ($MaxPages)
         $CountDiscussions = $MaxPages * $Limit;
      
      $this->SetData('CountDiscussions', $CountDiscussions);
      
      // Get Announcements
      $this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
		$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
      
      // Get Discussions
      $this->DiscussionData = $DiscussionModel->GetWhere(FALSE, $Offset, $Limit);
      
      $this->SetData('Discussions', $this->DiscussionData, TRUE);
      $this->SetJson('Loading', $Offset . ' to ' . $Limit);

      // Build a pager
      $PagerFactory = new Gdn_PagerFactory();
		$this->EventArguments['PagerType'] = 'Pager';
		$this->FireEvent('BeforeBuildPager');
      $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
      $this->Pager->ClientID = 'Pager';
      $this->Pager->Configure(
         $Offset,
         $Limit,
         $CountDiscussions,
         'discussions/%1$s'
      );
      if (!$this->Data('_PagerUrl'))
         $this->SetData('_PagerUrl', 'discussions/{Page}');
      $this->SetData('_Page', $Page);
      $this->SetData('_Limit', $Limit);
		$this->FireEvent('AfterBuildPager');
      
      // Deliver JSON data if necessary
      if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'discussions';
      }
      
      // We don't want search engines to index these pages because they can go in through the individual categories MUCH faster.
      if ($this->Head)
         $this->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
      
      $this->Render();
   }
1201229
protected function calculateCurrentPage($lastPage)
	{
		$page = $this->env->getCurrentPage();

		// The page number will get validated and adjusted if it either less than one
		// or greater than the last page available based on the count of the given
		// items array. If it's greater than the last, we'll give back the last.
		if (is_numeric($page) && $page > $lastPage)
		{
			return $lastPage > 0 ? $lastPage : 1;
		}

		return $this->isValidPageNumber($page) ? (int) $page : 1;
	}
174387
public function paginate($perPage)
    {
        if (\filter_var($perPage, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]) && ! \is_bool($perPage)) {
            $this->perPage = $perPage;
            $this->paginate = true;
        } elseif (\filter_var($perPage, FILTER_VALIDATE_BOOLEAN)) {
            $this->perPage = null;
            $this->paginate = $perPage;
        } else {
            $this->perPage = null;
            $this->paginate = false;
        }

        return $this;
    }
63862
static function FindPageGroup(Page $page)
    {
        $currPage = $page;
        $result = null;
        do 
        {
            $result = $currPage->GetUserGroup();
            $currPage = $currPage->GetParent();
        } 
        while (!$result && $currPage);
        if (!$result && $page->GetSite())
        {
            return $page->GetSite()->GetUserGroup();
        }
        return $result;
    }
49263
public function getPositionOrderedChildren($perPage = null)
    {
        $children = $this->children()
            ->defaultOrder();

        return $this->determineChildrenPagination($perPage, $children);
    }
708427
private function setCurrentPage($currentPage, $totalPage)
    {
        if (1 > $currentPage) {
            $currentPage = 1;
        }

        if ((0 < $totalPage) && ($totalPage < $currentPage)) {
            $currentPage = $totalPage;
        }

        $this->currentPage = $currentPage;
    }
823865
static function LastPageLog(Page $page)
    {
        $tblLogPage = LogPage::Schema()->Table();
        $tblLogItem = LogItem::Schema()->Table();
        $sql = Access::SqlBuilder();
        $orderBy = $sql->OrderList($sql->OrderDesc($tblLogItem->Field('Changed')));
        $joinCond = $sql->Equals($tblLogPage->Field('LogItem'), $tblLogItem->Field('ID'));
        $where = $sql->Equals($tblLogPage->Field('Page'), $sql->Value($page->GetID()));
        return LogItem::Schema()->First($where, $orderBy, null, $sql->Join($tblLogPage), JoinType::Inner(), $joinCond);
    }
699328
public function actionIndex($page = 1)
    {
        $this->trigger(self::EVENT_BEFORE_RECENT_SHOW);

        $data['page'] = (int) $page;
        $data['route'] = '/' . $this->getRoute();

        $finder = new VideoFinder();
        $data['videos'] = $finder->getNewVideos($page);
        $data['total_items'] = $finder->totalCount();

        $pagination = new Pagination([
            'totalCount' => $data['total_items'],
            'defaultPageSize' => Module::getInstance()->settings->get('items_per_page', 20),
            'pageSize' => Module::getInstance()->settings->get('items_per_page', 20),
            'route' => $data['route'],
            'forcePageParam' => false,
        ]);

        $settings = Yii::$app->settings->getAll();
        $settings['videos'] = Module::getInstance()->settings->getAll();

        $this->trigger(self::EVENT_AFTER_RECENT_SHOW);

        return $this->render('recent', [
            'data' => $data,
            'settings' => $settings,
            'pagination' => $pagination,
        ]);
    }
684551
public function indexAction($currentPage = 1)
    {
        // set current page
        $this->currentPage = (int)$currentPage;
        if ($this->currentPage < 1) {
            $this->currentPage = 1;
        }
        if ($this->currentPage > $this->numberOfPages) {
            // set $modifiedObjects to NULL if the page does not exist
            $modifiedObjects = null;
        } else {
            // modify query
            $this->itemsPerPage = (int)$this->configuration['itemsPerPage'];
            $this->offset = $this->itemsPerPage * ($this->currentPage - 1);
            // use slice here for array support
            $modifiedObjects = $this->prepareObjectsSlice($this->itemsPerPage, $this->offset);
        }
        $this->view->assign('contentArguments', [
            $this->widgetConfiguration['as'] => $modifiedObjects,
        ]);
        $this->view->assign('configuration', $this->configuration);
        $this->view->assign('pagination', $this->buildPagination());
    }
608797
public function followPage($page)
    {
        \PHPUnit_Framework_Assert::assertNotNull(
            $link = $this->findPager()->findLink($page),
            sprintf('The page "%s" could not be found.', $page)
        );

        $link->click();
    }
884838
public function onAfterDuplicate(\Page $page)
    {
        foreach ($this->owner->PageSlices() as $slice) {
            /** @var PageSlice $slice */
            $sliceCopy = $slice->duplicate(true);
            $page->PageSlices()->add($sliceCopy);
            $sliceCopy->publishRecursive();
        }
    }
306648
public function check_page_access($page) {
        global $DB;

        if ($this->get_currentpage() != $page) {
            if ($this->get_navigation_method() == QUIZ_NAVMETHOD_SEQ && $this->get_currentpage() > $page) {
                return false;
            }
        }
        return true;
    }
192944
public function setPage($page)
    {
        if (!is_scalar($page)) {
            $this->page = self::DEFAULT_PAGE;

            return $this;
        } else {
            $page = (int)$page;
        }

        if ($page < 1) {
            $this->page = 1;
        } else {
            $this->page = $page;
        }

        return $this;
    }
495742
public function setPage(int $page): Pagination
    {
        $this->current_page = $page;
        $this->calculate();
        return $this;
    }
1260110
public function paginate($perPage, $page = null)
    {
        if (empty($page)) {
            $page = request('page', 1);
        }
        $offset = ($page * $perPage) - $perPage;

        $collection = $this->all();
        $newItems = array_slice($collection, $offset, $perPage, true);
        return $this->createChildCollection($newItems);
    }
1272676
public function index($page = null)
    {
        $url = sprintf('buckets/%d/inboxes/%d/forwards.json', $this->bucket, $this->parent);

        $forwards = $this->client->get($url, [
            'query' => [
                'page' => $page,
            ]
        ]);

        return $this->indexResponse($forwards, Forward::class);
    }
1048782
public function setCurrentPage($page)
  {
    $this->currentPage = $page;
    $this->forcedPage = true;
    $this->updateTable();
  }