<?php
namespace Modules\Admin\Config\ImportedOrders\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\ImportedOrdersSystems();
		$listObj->setColumns(['code', 'name', 'active', 'type', 'url', 'addTime']);

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

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

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

		// 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();
	}

	public function getSystemTypes()
	{
		$typesList = new \Modules\Admin\Config\ImportedOrders\SystemManagement\Systems\TypesList();

		\Engine\Plugins\Manager::getInstance()->executeEvent('Modules\Admin\Config\ImportedOrders\SystemManagement-getSystemTypes', ['typesList'=>$typesList]);

		return $typesList->getAll();
	}
}