<?php
namespace Modules\Utils\AppReports;

/**
 * Model class for listing appReports.
 * @author Florin Rusu
 */
class Model extends \App\Mvc\Model_ListingAbstract
{
	/**
	 *
	 * {@inheritDoc}
	 * @see \App\Mvc\Model_ListingAbstract::list_execute()
	 */
	public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams)
	{
		$list = [];
		$filters = $listingParams->getFilters();

		foreach (\Modules\Utils\AppReports\SqlManager::getInstance()->getAll() as $details) {

			if ($filters['name'] and strpos($details['name'], $filters['name']) === false) {
				continue;
			}
			if ($filters['sql'] and strpos($details['sql'], $filters['sql']) === false) {
				continue;
			}
			if ($filters['monthTable'] and strpos($details['monthTable'], $filters['monthTable']) === false) {
				continue;
			}


			$list[$details['name']] = [
				"name"			=>	$details['name'],
				"sql"			=>	$details['sql'],
				"monthTable"	=>	$details['monthTable']
			];

		}


		$start = $listingParams->getResultsPerPage()*$listingParams->getCurrentPage();
		$count = $listingParams->getResultsPerPage();

		$this->totalRecordsCount = count($list);
		$recordsList = array_slice($list, $start, $count);

//		looping thru the sliced list of records to use entity match only on a limited/smaller number
//		of records
		$this->recordsList = $recordsList;

	}


}