<commit_before><?php
namespace dash\utility;

class pagination
{
	private static $have_pages = false;
	public static $detail      = [];


	/**
	 * save every thing in temp to get every where
	 *
	 * @param      <type>  $_key    The key
	 * @param      <type>  $_value  The value
	 *
	 * @return     <type>  ( description_of_the_return_value )
	 */
	public static function detail($_key = null, $_value = null)
	{
		if(isset($_value))
		{
			self::$detail[$_key] = $_value;
		}
		else
		{
			if($_key)
			{
				if(array_key_exists($_key, self::$detail))
				{
					return self::$detail[$_key];
				}
				else
				{
					return null;
				}
			}
			else
			{
				return self::$detail;
			}

		}
	}


	private static function destroy()
	{
		self::$have_pages = false;
		self::$detail     = [];
	}


	/**
	 * Gets the query limit.
	 *
	 * @param      <type>   $_total_rows  The total rows
	 * @param      integer  $_page        The page
	 * @param      integer  $_limit       The limit
	 *
	 * @return     <type>   The query limit.
	 */
	public static function init($_total_rows, $_limit = 10)
	{
		self::destroy();

		self::$have_pages = true;
		$page             = \dash\request::get('page');
		$url_get_length   = \dash\request::get('length');

		$page             = $page && ctype_digit($page) ? $page : 1;
		$page             = intval($page) > 0 ? intval($page) : 1;
		$_total_rows      = intval($_total_rows);

		if($url_get_length && ctype_digit($url_get_length) && intval($url_get_length) <= 1000)
		{
			$limit = intval($url_get_length);
		}
		else
		{
			$limit = intval($_limit);
		}

		$limit = $limit ? $limit : 10;

		if($page > 0)
		{
			$start_limit = $limit * ($page - 1);
		}
		else
		{
			$start_limit = 0;
		}

		$end_limit = $limit;

		$total_page = ceil($_total_rows / $limit);

		// save some detail
		self::detail('start_limit', $start_limit);
		self::detail('end_limit', $end_limit);
		self::detail('page', $page);
		self::detail('total_page', $total_page);
		self::detail('limit', $limit);
		self::detail('total_rows', $_total_rows);

		// set from and to
		$record_from = $start_limit + 1;
		$record_to = $start_limit + $end_limit;
		if($record_to > $_total_rows)
		{
			$record_to = $_total_rows;
		}

		self::detail('from', $record_from);
		self::detail('to', $record_to);

		// create desc of pagination
		// page 3 of 20 - Show record 21 to 30 from 200
		$desc = T_("page :current of :total", ['current' => $page, 'total' => $total_page]);
		$desc .= ' - ';
		$desc .= T_("Show record :min to :max of :total", ['min' => $record_from, 'max' => $record_to, 'total' => $_total_rows]);
		self::detail('desc', $desc);

		return [$start_limit, $end_limit];
	}<commit_msg>add fitNumber<commit_after><?php
namespace dash\utility;

class pagination
{
	private static $have_pages = false;
	public static $detail      = [];


	/**
	 * save every thing in temp to get every where
	 *
	 * @param      <type>  $_key    The key
	 * @param      <type>  $_value  The value
	 *
	 * @return     <type>  ( description_of_the_return_value )
	 */
	public static function detail($_key = null, $_value = null)
	{
		if(isset($_value))
		{
			self::$detail[$_key] = $_value;
		}
		else
		{
			if($_key)
			{
				if(array_key_exists($_key, self::$detail))
				{
					return self::$detail[$_key];
				}
				else
				{
					return null;
				}
			}
			else
			{
				return self::$detail;
			}

		}
	}


	private static function destroy()
	{
		self::$have_pages = false;
		self::$detail     = [];
	}


	/**
	 * Gets the query limit.
	 *
	 * @param      <type>   $_total_rows  The total rows
	 * @param      integer  $_page        The page
	 * @param      integer  $_limit       The limit
	 *
	 * @return     <type>   The query limit.
	 */
	public static function init($_total_rows, $_limit = 10)
	{
		self::destroy();

		self::$have_pages = true;
		$page             = \dash\request::get('page');
		$url_get_length   = \dash\request::get('length');

		$page             = $page && ctype_digit($page) ? $page : 1;
		$page             = intval($page) > 0 ? intval($page) : 1;
		$_total_rows      = intval($_total_rows);

		if($url_get_length && ctype_digit($url_get_length) && intval($url_get_length) <= 1000)
		{
			$limit = intval($url_get_length);
		}
		else
		{
			$limit = intval($_limit);
		}

		$limit = $limit ? $limit : 10;

		if($page > 0)
		{
			$start_limit = $limit * ($page - 1);
		}
		else
		{
			$start_limit = 0;
		}

		$end_limit = $limit;

		$total_page = ceil($_total_rows / $limit);

		// save some detail
		self::detail('start_limit', $start_limit);
		self::detail('end_limit', $end_limit);
		self::detail('page', $page);
		self::detail('total_page', $total_page);
		self::detail('limit', $limit);
		self::detail('total_rows', $_total_rows);

		// set from and to
		$record_from = $start_limit + 1;
		$record_to = $start_limit + $end_limit;
		if($record_to > $_total_rows)
		{
			$record_to = $_total_rows;
		}

		self::detail('from', $record_from);
		self::detail('to', $record_to);

		// create desc of pagination
		// page 3 of 20 - Show record 21 to 30 from 200
		$desc = T_("page :current of :total", ['current' => $page, 'total' => $total_page]);
		$desc .= ' - ';
		$desc .= T_("Show record :min to :max of :total", ['min' => $record_from, 'max' => $record_to, 'total' => $_total_rows]);
		$desc = \dash\utility\human::fitNumber($desc);
		self::detail('desc', $desc);

		return [$start_limit, $end_limit];
	}
{'fraction_non_alphanumeric': 0.17111806962608214, 'fraction_numerical': 0.009209799226376865, 'mean_word_length': 2.84016973125884, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5869916', 'n_tokens_mistral': 2258, 'n_tokens_neox': 1935, 'n_words': 437}