<?php

namespace Modules\Admin\Departments;

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 departments list
		$listObj = new \App\EntityList\Departments();
		$listObj->setColumns(['name', 'code', 'addTime', 'idAddUser']);
		if ($filters['text']) {
			$listObj->setCustomFilter("dept.name LIKE ? OR dept.code LIKE ?", ["%{$filters['text']}%", "%{$filters['text']}%"]);
		}
		if ($filters['addUser']['id']) {
			$listObj->setFilter('dept.idAddUser', '=', $filters['addUser']['id']);
		}
		$listObj = $this->entityList_inheritListingParams($listingParams, $listObj);

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

	}

}
