Elcodi\Admin\AttributeBundle\Controller\AttributeController::evaluateAttributeValues PHP 메소드

evaluateAttributeValues() 보호된 메소드

Given an attribute and an array of Values, perform database and relation stuff
protected evaluateAttributeValues ( Elcodi\Component\Attribute\Entity\Interfaces\AttributeInterface $attribute, array $values = [] )
$attribute Elcodi\Component\Attribute\Entity\Interfaces\AttributeInterface Attribute
$values array Values
    protected function evaluateAttributeValues(AttributeInterface $attribute, array $values = [])
    {
        $actualValues = [];
        $values = array_filter($values, function ($value) {
            return !empty($value);
        });
        /**
         * We remove all deleted values
         */
        $attribute->setValues($attribute->getValues()->filter(function (ValueInterface $value) use($attribute, $values, &$actualValues) {
            $found = false;
            if (in_array($value->getValue(), $values)) {
                $actualValues[] = $value->getValue();
                $found = true;
            } else {
                $attribute->removeValue($value);
            }
            return $found;
        }));
        $newValues = array_diff($values, $actualValues);
        foreach ($newValues as $newValue) {
            $value = $this->get('elcodi.factory.attribute_value')->create()->setValue($newValue)->setAttribute($attribute);
            $attribute->addValue($value);
        }
        return $this;
    }