<?php

namespace App\OfferProfileRules;

class Criterion_OfferLocation extends CriterionAbstract
{

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


	/**
	 * (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 offer location set.");
		}
		else {
			$CFG = \Engine\Loader_Cfg::getInstance()->getGlobal();

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

	}

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

}
