<commit_before><?php

/**
 *
 * @package   ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
 *
 * This file contains code covered by:
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
 *
 * @version 2.0 dev
 *
 */

namespace ElkArte;

/**
 * Constructs a page list.
 *
 * What it does:
 *
 * - Builds the page list, e.g. 1 ... 6 7 [8] 9 10 ... 15.
 * - Flexible_start causes it to use "url.page" instead of "url;start=page".
 * - Very importantly, cleans up the start value passed, and forces it to
 *   be a multiple of num_per_page.
 * - Checks that start is not more than max_value.
 * - Base_url should be the URL without any start parameter on it.
 * - Uses the compactTopicPagesEnable and compactTopicPagesContiguous
 *   settings to decide how to display the menu.
 * - Substitutes {scripturl} to $scripturl and {base_link} based on Flexible_start
 *
 * @param string $base_url The base URL to be used for each link.
 * @param int &$start The start position, by reference. If this is not a multiple of the number
 * of items per page, it is sanitized to be so and the value will persist upon the function's return.
 * @param int $max_value The total number of items you are paginating for.
 * @param int $num_per_page The number of items to be displayed on a given page.
 * @param bool $flexible_start = false Use "url.page" instead of "url;start=page"
 * @param mixed[] $show associative array of option => boolean paris
 *
 * @return string
 * @example $pageindex = constructPageIndex({scripturl} . '?board=' . $board, $_REQUEST['start'], $num_messages,
 *     $maxindex, true);
 */
class ConstructPageIndex extends AbstractModel
{
	/** @var int stating page */
	private $start;

	/** @var array holds the desired options for the index all, prev_next, all_selected */
	private $show;

	/** @var int max page # to show */
	private $max_value;

	/** @var int  */
	private $num_per_page;

	/** @var bool  */
	private $flexible_start;

	/** @var string  */
	private $base_url;

	/** @var string */
	private $base_link;

	/** @var bool If we have tried to navigate off the end */
	private $start_invalid;

	/** @var int */
	private $counter;

	/** @var mixed|string What we are after */
	private $pageindex;

	/** @var int the maximum number of pages in the index */
	private $maxPages;

	/**
	 * ConstructPageIndex constructor.
	 *
	 * @param string $base_url
	 * @param int $start
	 * @param int $max_value
	 * @param int $num_per_page
	 * @param bool $flexible_start
	 * @param array $show
	 */
	public function __construct($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $show = [])
	{
		$this->start = (int) $start;
		$this->show = array_merge(['prev_next' => true, 'all' => false], $show);
		$this->max_value = (int) $max_value;
		$this->num_per_page = (int) $num_per_page;
		$this->flexible_start = $flexible_start;
		$this->base_url = $base_url;

		// Do it!
		$this->createPageIndex();
	}

	/**
	 * Does what it says, creates the handy pageindex navigation bar
	 */
	public function createPageIndex()
	{
		global $context;

		$this->setStart();
		$context['current_page'] = (int) $this->start / $this->num_per_page;

		$this->setBaseLink();

		// Compact pages is off or on?
		if (empty($this->_modSettings['compactTopicPagesEnable']))<commit_msg>! Missed parent call and all its goodness<commit_after><?php

/**
 *
 * @package   ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
 *
 * This file contains code covered by:
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
 *
 * @version 2.0 dev
 *
 */

namespace ElkArte;

/**
 * Constructs a page list.
 *
 * What it does:
 *
 * - Builds the page list, e.g. 1 ... 6 7 [8] 9 10 ... 15.
 * - Flexible_start causes it to use "url.page" instead of "url;start=page".
 * - Very importantly, cleans up the start value passed, and forces it to
 *   be a multiple of num_per_page.
 * - Checks that start is not more than max_value.
 * - Base_url should be the URL without any start parameter on it.
 * - Uses the compactTopicPagesEnable and compactTopicPagesContiguous
 *   settings to decide how to display the menu.
 * - Substitutes {scripturl} to $scripturl and {base_link} based on Flexible_start
 *
 * @param string $base_url The base URL to be used for each link.
 * @param int &$start The start position, by reference. If this is not a multiple of the number
 * of items per page, it is sanitized to be so and the value will persist upon the function's return.
 * @param int $max_value The total number of items you are paginating for.
 * @param int $num_per_page The number of items to be displayed on a given page.
 * @param bool $flexible_start = false Use "url.page" instead of "url;start=page"
 * @param mixed[] $show associative array of option => boolean paris
 *
 * @return string
 * @example $pageindex = constructPageIndex({scripturl} . '?board=' . $board, $_REQUEST['start'], $num_messages,
 *     $maxindex, true);
 */
class ConstructPageIndex extends AbstractModel
{
	/** @var int stating page */
	private $start;

	/** @var array holds the desired options for the index all, prev_next, all_selected */
	private $show;

	/** @var int max page # to show */
	private $max_value;

	/** @var int  */
	private $num_per_page;

	/** @var bool  */
	private $flexible_start;

	/** @var string  */
	private $base_url;

	/** @var string */
	private $base_link;

	/** @var bool If we have tried to navigate off the end */
	private $start_invalid;

	/** @var int */
	private $counter;

	/** @var mixed|string What we are after */
	private $pageindex;

	/** @var int the maximum number of pages in the index */
	private $maxPages;

	/**
	 * ConstructPageIndex constructor.
	 *
	 * @param string $base_url
	 * @param int $start
	 * @param int $max_value
	 * @param int $num_per_page
	 * @param bool $flexible_start
	 * @param array $show
	 */
	public function __construct($base_url, &$start, $max_value, $num_per_page, $flexible_start = false, $show = [])
	{
		$this->start = (int) $start;
		$this->show = array_merge(['prev_next' => true, 'all' => false], $show);
		$this->max_value = (int) $max_value;
		$this->num_per_page = (int) $num_per_page;
		$this->flexible_start = $flexible_start;
		$this->base_url = $base_url;

		// Need to pull in modsettings, db and user
		parent::__construct();

		// Do it!
		$this->createPageIndex();
		$start = $this->start;
	}

	/**
	 * Does what it says, creates the handy pageindex navigation bar
	 */
	public function createPageIndex()
	{
		global $context;

		$this->setStart();
		$context['current_page'] = $this->start / $this->num_per_page;

		$this->setBaseLink();

		// Compact pages is off or on?
		if (empty($this->_modSettings['compactTopicPagesEnable']))
{'fraction_non_alphanumeric': 0.12714677442632413, 'fraction_numerical': 0.004618271034781353, 'mean_word_length': 3.6261682242990654, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4724738', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2177, 'n_words': 786}