Beispiel #1
0
 /**
  * Internal helper function which interpreted the passed emotion elements and save convert the data array
  * to an model array.
  *
  * @param $emotion
  * @param $data
  * @return array
  */
 private function fillElements($emotion, $data)
 {
     $elements = array();
     $mediaService = Shopware()->Container()->get('shopware_media.media_service');
     $mediaFields = $this->getMediaXTypes();
     foreach ($data['elements'] as $elementData) {
         $element = new \Shopware\Models\Emotion\Element();
         $component = Shopware()->Models()->find('Shopware\\Models\\Emotion\\Library\\Component', $elementData['componentId']);
         foreach ($elementData['data'] as $item) {
             $model = new \Shopware\Models\Emotion\Data();
             $field = Shopware()->Models()->find('Shopware\\Models\\Emotion\\Library\\Field', $item['id']);
             $model->setComponent($component);
             $model->setComponentId($component->getId());
             $model->setElement($element);
             $model->setFieldId($item['id']);
             /**@var $field \Shopware\Models\Emotion\Library\Field*/
             $model->setField($field);
             $value = '';
             switch (strtolower($field->getValueType())) {
                 case "json":
                     if (is_array($item['value'])) {
                         foreach ($item['value'] as &$val) {
                             $val['path'] = $mediaService->normalize($val['path']);
                         }
                     }
                     $value = Zend_Json::encode($item['value']);
                     break;
                 case "string":
                 default:
                     $value = $item['value'];
                     break;
             }
             if (in_array($field->getXType(), $mediaFields)) {
                 $value = $mediaService->normalize($value);
             }
             $model->setValue($value);
             $model->setEmotionId($emotion->getId());
             Shopware()->Models()->persist($model);
         }
         $elementData['emotion'] = $emotion;
         $elementData['component'] = $component;
         unset($elementData['data']);
         $element->fromArray($elementData);
         $elements[] = $element;
     }
     return $elements;
 }
Beispiel #2
0
 /**
  * Internal helper function which interpreted the passed emotion elements and save convert the data array
  * to an model array.
  *
  * @param $emotion
  * @param $data
  * @return array
  */
 private function fillElements($emotion, $data)
 {
     $elements = array();
     foreach ($data['elements'] as $elementData) {
         $element = new \Shopware\Models\Emotion\Element();
         $component = Shopware()->Models()->find('Shopware\\Models\\Emotion\\Library\\Component', $elementData['componentId']);
         foreach ($elementData['data'] as $item) {
             $model = new \Shopware\Models\Emotion\Data();
             $field = Shopware()->Models()->find('Shopware\\Models\\Emotion\\Library\\Field', $item['id']);
             $model->setComponent($component);
             $model->setComponentId($component->getId());
             $model->setElement($element);
             $model->setFieldId($item['id']);
             /**@var $field \Shopware\Models\Emotion\Library\Field*/
             $model->setField($field);
             $value = '';
             switch (strtolower($field->getValueType())) {
                 case "json":
                     $value = Zend_Json::encode($item['value']);
                     break;
                 case "string":
                 default:
                     $value = $item['value'];
                     break;
             }
             $model->setValue($value);
             $model->setEmotionId($emotion->getId());
             Shopware()->Models()->persist($model);
         }
         $elementData['emotion'] = $emotion;
         $elementData['component'] = $component;
         unset($elementData['data']);
         $element->fromArray($elementData);
         $elements[] = $element;
     }
     return $elements;
 }