<?php

namespace Modules\Admin\Config\Documents\IssueDocs;

/**
 * Model class for listing issue documents.
 */
class Model extends \App\Mvc\Model_ListingAbstract
{

	public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams)
	{

		$filters = $listingParams->getFilters();

		$list = [];
		foreach (\App\Config\IssueDocuments::getAdmin()->getAll() as $code => $details) {

			// APPLY FILTERS ----------------------------------------------------------------------
			if ($filters['pivot'] and $details['pivot']!=$filters['pivot']) {
				continue;
			}
			if (($filters['active']==1 or !$filters['active']) and $details['active']!=$filters['active']) {
				continue;
			}
			if ($filters['text']) {
				if (mb_stripos($code, $filters['text'])===false and mb_stripos($details['name'], $filters['text'])===false and mb_stripos($details['docCategory'], $filters['text'])===false) {
					continue ;
				}
			}

			$details['id'] = $code;
			$list[$code] = $details;

		}

		$startIndex = $listingParams->getResultsPerPage()*$listingParams->getCurrentPage();

		$this->totalRecordsCount = count($list);
		$this->recordsList = array_slice($list, $startIndex, $listingParams->getResultsPerPage());

	}
}