<?php
namespace Modules\Admin\Banks;

class Model extends \App\Mvc\Model_ListingAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\Mvc\Model_ListingAbstract::list_execute()
	 */
	public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams)
	{
		$filters = $listingParams->getFilters();

		// get banks list
		$listObj = new \App\EntityList\Banks();
		$listObj->setColumns( ['bankName', 'bankName2', 'bankCode', 'addTime',]);

		if ($filters['text']) {
			$listObj->setCustomFilter('bankName LIKE ? OR bankName2 LIKE ? OR bankCode LIKE ?',
			 ["%{$filters['text']}%", "%{$filters['text']}%", "%{$filters['text']}%"]);
		}

		$listObj = $this->entityList_inheritListingParams($listingParams, $listObj);

		$banks = $listObj->exportRecords();
		$banksRecordsCount = $listObj->getRecordsCount();
		$recordList = [];
		foreach ($banks as $bank) {
			$offices = new \App\EntityList\BankOffices();
			$offices->setFilter('idBank', 'LIKE', $bank['id']);
			$bank['officesCount'] = $offices->getRecordsCount();
			$recordList[] = $bank;
		}
		$this->recordsList = $recordList;
		$this->totalRecordsCount = $banksRecordsCount;
	}
}