Returns starting records for LIMIT clause on SQL interrogation

@version 20080521
@param string $sDefaultPageNo
@param int $iRecordsPerPage
@param int $iAllRecords
@param boolean $bKeepFullPage
@return int
192506
private function setStartingPageRecord($sDefaultPageNo, $iRecordsPerPage, $iAllRecords, $bKeepFullPage = true)
    {
        if (is_null($this->tCmnSuperGlobals->get('page'))) {
            switch ($sDefaultPageNo) {
                case 'last':
                    $iStartingPageRecord = $iAllRecords - $iRecordsPerPage;
                    break;
                case 'first':
                default:
                    $iStartingPageRecord = 0;
                    break;
            }
        } else {
            $iStartingPageRecord = ($this->tCmnSuperGlobals->get('page') - 1 ) * $iRecordsPerPage;
        }
        if (($bKeepFullPage ) && (($iStartingPageRecord + $iRecordsPerPage ) > $iAllRecords)) {
            $iStartingPageRecord = $iAllRecords - $iRecordsPerPage;
        }
        return max(0, $iStartingPageRecord);
    }
522577
public function findAllWithoutFetchPaged($page = 0, $limit = 20) {
    $offset = $page * $limit;
    $results = $this->createQuery()
      ->setFirstResult($offset)
      ->setMaxResults($limit)
      ->execute();
    return $results;
  }
700778
public function getFirstRecord($filter = '', $order = ['.id'], $page = 1, $count = null, $dataDimensions = null)
    {
        $records = $this->getRecords($filter, $order, $page, $count, $dataDimensions);
        if ($records) {
            return array_shift($records);
        }

        return false;
    }
992588
public function getSimple(int $page, int $limit = 10, bool $isClount = false): \Illuminate\Contracts\Pagination\Paginator
    {
        if (!$this->_columns && !$this->_query) {
            return null;
        }
        if ($isClount) {
            $countTotal = $this->_query->count();
        }
        $this->_query->skip(($page - 1) * $page)->take($page + 1);
        $this->_data = $this->_query->simplePaginate($limit);
        if ($isClount) {
            $this->_data->totalCount = $countTotal;
        }
        foreach ($this->_data->items() as $key => $instance) {
            if ($instance instanceof \Illuminate\Database\Eloquent\Model) {
                $_listRow = [];
                foreach ($this->_columns->getColumns() as $column) {
                    $_listRow[$column->getKey()] = $column->getValues($instance);
                    if ($column->getKey() === 'preview') {
                    }
                }
                $buttons = $this->_columns->filterActions($instance);
                if (count($buttons)) {
                    $_listRow = array_merge($_listRow, [Column::ACTION_NAME => implode('', $buttons)]);
                }
                $this->_data->offsetSet($key, $_listRow);
            }
        }

        return $this->_data;
    }
307787
final public function queryPager(
        string $querySelect,
        string $queryCount = '',
        int $page = 1,
        int $recordsPerPage = 20
    ) {
        try {
            return $this->createPager($querySelect, $queryCount, $page, $recordsPerPage);
        } catch (\Throwable $exception) {
            $this->logger->error("DBAL::queryPager failure running $querySelect");
            return false;
        }
    }
1088238
public function getPagedResults($limit = 50, $page = 0)
    {
        $dql = sprintf(self::DQL_GET_PAGED, AuditEvent::class);
        return $this->getPaginator($dql, $limit, $page);
    }
766522
private function paginateRecords(ActiveQueryInterface $query, $pageNumber, $count)
    {
        $offset = ($pageNumber - 1) * $count;
        $limit = $count;

        return $query->offset($offset)->limit($limit);
    }
835808
public function getrecord($endtime, $pageindex, $pagesize, $starttime)
    {
        $recond_array = [
            'endtime'   => $endtime,
            'pageindex' => $pageindex,
            'pagesize'  => $pagesize,
            'starttime' => $starttime,
        ];

        $this->apitype = 'customservice';

        $this->module = 'msgrecord';

        $res = $this->_post('getrecord', $recond_array);

        return $res;
    }
1104313
public static function search(
        Client $client,
        array $tags,
        int $page,
        int $limit = 20
    ): array {
        if (!self::isValidPageNumber($page)) {
            throw new InvalidArgumentException('Page number should be greater than zero');
        }

        if (!self::isValidLimitation($page)) {
            throw new InvalidArgumentException('Limit should be greater than zero');
        }

        $query = [
            'page' => $page,
            'limit' => $limit,
            'tags' => implode(',', $tags),
        ];

        $postsAsArrays = $client->sendRequest(
            self::ENDPOINT,
            $query
        );

        return array_map(function (array $post) use ($client): self {
            return self::fromArray($client, $post);
        }, $postsAsArrays);
    }
1277581
public function limit($offset_start, $results_quantity)
    {
        $this->offset_start = (int) $offset_start;
        $this->results_quantity = (int) $results_quantity;

        return $this;
    }
1235873
public function search_records(array $searchFields, array $requiredFields, $orderBy=null, $limit=null, $offset=null) {
		$data = array();
		if(is_array($searchFields) && is_array($requiredFields)) {
			$limitOffsetStr = '';
			if(is_numeric($limit) && $limit > 0) {
				$limitOffsetStr = ' LIMIT '. $limit;
				
				//using an offset without a limit seems silly...
				if(is_numeric($limitOffsetStr) && $offset > 0) {
					$limitOffsetStr .= ' OFFSET '. $offset;
				}
			}
			
			$filterStr = '';
			$required = '';
			$params = array();
			foreach($searchFields as $f=>$v) {
				$filterStr = ToolBox::create_list($filterStr, '(lower('. $f .') LIKE :'. $f .' OR :'. $f .' IS NULL)', ' AND ');
				$params[$f] = '%'. $v .'%';
			}
			foreach($requiredFields as $f=>$v) {
				$required = ToolBox::create_list($required, $f .'=:'. $f, ', ');
				$params[$f] = $v;
			}
			
			$sql = 'SELECT * FROM '. $this->tableName .' WHERE ('. $filterStr .') AND '. $required . $orderByStr . $limitOffsetStr;
			
			$orderByStr = ' ORDER BY '. $this->pkeyField;
			if(is_string($orderBy) && strlen($orderBy)) {
				$orderByStr = ' ORDER BY '. $orderBy;
			}
			
			try {
				$data = $this->dbObj->run_query($sql, $params);
			}
			catch(Exception $e) {
				throw new Exception(__METHOD__ .': error while performing search: '. $e->getMessage());
			}
		}
		else {
			throw new Exception(__METHOD__ .': missing searchFields or requiredFields');
		}
		
		return($data);
	}
529735
private static function getNumPages(int $limit, int $count): int
    {
        return (int) ceil($count / $limit);
    }
828543
public function createPaginator($dql, $page, $limit)
    {
        $offset        = ($page - 1) * $limit;
        $query         = $this->entityManager->createQuery($dql)->setMaxResults($limit)->setFirstResult($offset);
        $paginator     = new Paginator($query);
        $adapter       = new DoctrinePaginatorAdapter($paginator);
        $zendPaginator = new ZendPaginator($adapter);
        $zendPaginator->setCurrentPageNumber($page);
        $zendPaginator->setItemCountPerPage($limit);
        return $zendPaginator;
    }
674240
public function getLimit($sql, $page, $num = 0, $params = array(), $next_page = false)
    {
        $num = (int)$num;
        $sql .= ' limit :limit_from,:limit';

        if ($next_page && $num) {
            $limit_from = ($page - 1) * ($num - 1);
        } else {
            $limit_from = ($page - 1) * $num;
        }

        $ret = $this->getAll($sql, array_merge($params, array('limit' => $num, 'limit_from' => $limit_from)));
        return $ret;
    }
147071
function (page) {
        if (!lang.isNumber(page)) {
            page = this.getCurrentPage();
        }

        var perPage = this.get('rowsPerPage'),
            records = this.get('totalRecords'),
            start, end;

        if (!page || !perPage) {
            return null;
        }

        start = (page - 1) * perPage;
        if (records !== Paginator.VALUE_UNLIMITED) {
            if (start >= records) {
                return null;
            }
            end = Math.min(start + perPage, records) - 1;
        } else {
            end = start + perPage - 1;
        }

        return [start,end];
    }
293419
public function query_db($pagesize, $useinitialsbar = true) {

        $total = \tool_monitor\rule_manager::count_rules_by_courseid($this->courseid);
        $this->pagesize($pagesize, $total);
        $rules = \tool_monitor\rule_manager::get_rules_by_courseid($this->courseid, $this->get_page_start(),
                $this->get_page_size());
        $this->rawdata = $rules;
        // Set initial bars.
        if ($useinitialsbar) {
            $this->initialbars($total > $pagesize);
        }
    }
1307992
public function getByPage(
        int $page = 1,
        int $limit = 10,
        array $where = [],
        array $with = [],
        string $orderBy = null,
        string $order = 'desc'
    ) {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        if ($orderBy) {
            $query = $query->orderBy($orderBy, $order);
        }

        return $query->skip($limit * ($page - 1))
            ->take($limit)
            ->get();
    }