<?php

namespace App\OfferProfileRules;

class Criterion_FormOfPayment extends CriterionAbstract
{

	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::checkFields()
	 */
	public function checkFields(\App\OfferProfileRules\Fields $fields)
	{
		return $this->checkField($fields->offerFormOfPayment);
	}


	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::checkAssignedValues()
	 */
	public function checkAssignedValues(\App\MessagesCollector $msgs)
	{

		// check that at least one value set
		if (($this->operation=='equal' or $this->operation=='notEqual') and !$this->values) {
			$msgs->addWarning("No form of payment set.");
		}
		else {
			$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();

			foreach($this->values as $elem) {
				if (!in_array($elem, $CFG['offers']['formOfPaymentList'])) {
					$msgs->addWarning("The offer FOP `{$elem}` is not valid.");
				}
			}
		}

	}

	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::createDescription_getEntityName()
	 */
	protected function createDescription_getEntityName($code)
	{
		$_LANG = \App\Loader_Lang::getInstance()->getAll();
		return $_LANG['offers']['formOfPayment'][$code];
	}

}
