<?php

namespace App\OfferProfileRules;

class Criterion_OwnerCorporate extends CriterionAbstract
{

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

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

		// check that at least one value set
		if ($this->operation=='notEqual' and !$this->values) {
			$msgs->addWarning("No corporate set.");
		}
		else {
			// check the corporate id
			foreach($this->values as $idCorporate) {
				if (!\Entity\Corporate::select($idCorporate)->recordExists()) {
					$msgs->addWarning("The corporate id `{$idCorporate}` is not valid.");
				}
			}
		}

	}

	/**
	 * (non-PHPdoc)
	 * @see \App\OfferProfileRules\CriterionAbstract::createDescription_getEntityName()
	 */
	protected function createDescription_getEntityName($code)
	{
		return \Entity\Corporate::select($code)->alias;
	}

}
