コード例 #1
0
ファイル: AttributeController.php プロジェクト: elcodi/bamboo
 /**
  * Given an attribute and an array of Values, perform database and relation
  * stuff
  *
  * @param AttributeInterface $attribute Attribute
  * @param array              $values    Values
  *
  * @return $this Self object
  */
 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;
 }