<?php
 namespace App\OfferProfileRules; class Criterion_ServiceRemarks extends CriterionAbstract { private $remarksValuesList; public function __construct(array $remarksValuesList) { if ($remarksValuesList) { $this->remarksValuesList = $remarksValuesList; } $this->checkOperation(); } public function getRemarksValues() { return $this->remarksValuesList; } public function checkOperation() { foreach ($this->remarksValuesList as $list) { if (!$list['operation']) { throw new \Exception('No operation set for '.get_called_class()); } $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $currentEntity = $this->getEntity(); if (!$CFG['offerProfileRules']['criteriaOperations'][$currentEntity]) { throw new \Exception("The entity `{$currentEntity}` is not configured for ".get_called_class()); } if (!in_array($list['operation'], $CFG['offerProfileRules']['criteriaOperations'][$currentEntity])) { throw new \Exception("The operation `{$this->operation}` is not valid for ".get_called_class()); } } } public function checkFields(\App\OfferProfileRules\Fields $fields) { foreach ($this->remarksValuesList as $crit) { if (!$this->getOperationResult($fields->serviceRemarks[$crit['var']], $crit['operation'], $crit['values'])) { return false; } } return true; } public function checkAssignedValues(\App\MessagesCollector $msgs) { foreach ($this->remarksValuesList as $remark) { if ($remark['operation'] and !$remark['var']) { $msgs->addWarning("You must define the variable name for the service remark."); } if (in_array($remark['operation'], ['equal', 'notEqual']) and !$remark['values']) { $msgs->addWarning("For the operation you set in services remarks you must also set the values."); } if ($remark['values'] and !is_array($remark['values'])) { $msgs->addWarning("The remark values must be set list."); } } } public function createDescription() { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $entityField = $this->getEntity(); $return = []; foreach ($this->remarksValuesList as $remark) { if ($remark['operation']=='anyValue' or $remark['operation']=='notSet') { $return[] = "<b>".$remark['var']."</b> ".$_LANG['OfferProfileRules']['criterionOperation'][$remark['operation']]; } else { $return[] = "<b>".$remark['var']."</b> ".$_LANG['OfferProfileRules']['criterionOperation'][$remark['operation']]." ".implode(', ', $remark['values']); } } return sprintf(sprintf($_LANG['OfferProfileRules']['criterionDescription1'], $_LANG['OfferProfileRules']['criterionFieldName'][$entityField], implode(', ', $return))); } protected function createDescription_getEntityName($code) {} } 