/** * @param \Kendo\Content\CatalogInterface $forItem */ public function setForItem($forItem) { $this->forItem = $forItem; $this->setCatalogId($forItem->getCatalogId()); }
/** * @param CatalogInterface|PosterInterface $item * @param $data */ public function updateItemAttribute($item, $data = []) { $catalogId = $item->getCatalogId(); if (!$catalogId) { return; } $form = $this->getInternalFormByCatalogId($catalogId); $form->setData($data); $atTable = $item->getAttributeValueTable(); $atTable->delete()->where('item_id=?', $item->getId())->execute(); $maps = []; foreach ($form->getElements() as $element) { if (!$element instanceof FormField) { continue; } $fieldId = $element->getFieldId(); if (!$fieldId) { continue; } $maps[$fieldId] = $element->getValue(); } foreach ($maps as $fieldId => $value) { $entry = $atTable->fetchNew(['item_id' => $item->getId(), 'field_id' => $fieldId, 'value' => $value]); $entry->save(); } }