<?php

namespace Modules\Admin\Config\CorporateCreditLimitEmails;

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 the email templates list
		$listObj = new \App\EntityList\CorporateCreditLimitEmailTemplates();
		$listObj->setColumns(['name', 'emailSubject', 'idSendingUser', 'idAddUser', 'addTime']);
		if ($filters['name']) {
			$listObj->setFilter('name', 'LIKE', "%{$filters['name']}%");
		}
		if ($filters['subject']) {
			$listObj->setFilter('emailSubject', 'LIKE', "%{$filters['subject']}%");
		}

		if ($filters['idSendingUser']['id']) {
			$listObj->setFilter('idSendingUser', '=', $filters['idSendingUser']['id']);
		}

		if ($filters['idAddUser']['id']) {
			$listObj->setFilter('idAddUser', '=', $filters['idAddUser']['id']);
		}

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

		// these must be called in this specific order
		$this->recordsList = $listObj->exportRecords();
		$this->totalRecordsCount = $listObj->getRecordsCount();
	}

}
