<?php
namespace Modules\Admin\Config\ClientInvoices\RowsDescriptions;

/**
 * Model class for listing schemas
 * @author adrian.voicu
 */
class Model extends \App\Mvc\Model_ListingAbstract
{

	public function list_execute(\App\Mvc\View\Listing\Members\Params $listingParams)
	{

		$list = [];

		$filters = $listingParams->getFilters();

		foreach (\App\Config\InvoiceRowsDescription::getAdmin()->getSchemesName() as $name) {

			// remove elements that are not according to the filters
			if ($filters['name'] && strpos(mb_strtolower($name), mb_strtolower($filters['name']))===false) {
				continue;
			}

			if($name) {
				$list[$name] = [
						'id' => $name
				];
			}
		}

		$defaultSchema = \App\Config\InvoiceRowsDescription::getAdmin()->getDefaultItem();

		// if in $list, add the default value
		if (array_key_exists($defaultSchema,$list)) {
			$list[$defaultSchema]['default'] = true;
		}

		$this->totalRecordsCount = count($list);
		$this->recordsList = $list;


	}
}