<?php
namespace App\Form\Input;

class Autocomplete_Data_DocumentSeries extends \Engine\Form\Input\Autocomplete_Data_GeneralAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete_Data_GeneralAbstract::getPageResultsBulk()
	 */
	protected function getPageResultsBulk() :array
	{
		$documentSeriesListObj = new \App\EntityList\DocumentSeries();
		$documentSeriesListObj->applyUserRestriction(false);
		$documentSeriesListObj->setColumns(['series.code', 'series.nextNumber']);
		$documentSeriesListObj->setFilter('series.code', 'LIKE', "{$this->searchString}%");
		$documentSeriesListObj->setOrderBy('series.code', 'ASC');
		$documentSeriesListObj->setLimit($this->offset, $this->resultsCountPage);

		return $this->executeSqlEntityList($documentSeriesListObj);
	}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Input\Autocomplete_Data_GeneralAbstract::getPageResultsFormatted()
	 */
	protected function getPageResultsFormatted(Array $pageResults)
	{
		$list = [];
		foreach($pageResults as $row) {
			// set extra
			$extra = $row['nextNumber'];

			$list[] = $this->getCleanItem($row['id'], $row['code'], $extra, '');
		}

		return $list;
	}

}
