<?php
namespace Modules\Admin\Config\ImportedDocuments\SystemManagement;

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 imported order systems
		$listObj = new \App\EntityList\ImportedDocumentsSystems();
		$listObj->setColumns(['code', 'name', 'active', 'addTime']);

		// filter: name
		if ($filters['name']) {
			$listObj->setFilter('name', 'LIKE', "%{$filters['name']}%");
		}

		// filter: code
		if ($filters['code']) {
			$listObj->setFilter('code', '=', $filters['code']);
		}

		// filter:active
		if ($filters['active'] == 'active') {
			$listObj->setFilter('active', '=', '1');
		}
		elseif ($filters['active'] == 'inactive') {
			$listObj->setFilter('active', '=', '0');
		}

		// these must be called in this specific order
		$listObj = $this->entityList_inheritListingParams($listingParams, $listObj);

		$this->recordsList = $listObj->exportRecords();
		$this->totalRecordsCount = $listObj->getRecordsCount();
	}
}