Пример #1
0
 /**
  * init module from data
  *
  * @param array $data
  * @return $this
  */
 public function initFromData(array $data)
 {
     if (isset($data[$this->getEntityCode()])) {
         $this->addData($data[$this->getEntityCode()]);
     }
     $settings = $this->settingsFactory->create();
     if (isset($data[$settings->getEntityCode()])) {
         $settings->setData($data[$settings->getEntityCode()]);
         $this->setSettings($settings);
     }
     $entitiesByIndex = [];
     if (isset($data['entity'])) {
         $entities = $data['entity'];
         if (is_array($entities)) {
             foreach ($entities as $key => $entityData) {
                 if (!$entityData) {
                     continue;
                 }
                 /** @var \Umc\Base\Model\Core\Entity $entity */
                 $entity = $this->entityFactory->create();
                 if (isset($entityData['attributes']) && is_array($entityData['attributes'])) {
                     if (isset($entityData['attributes']['is_name'])) {
                         $isName = $entityData['attributes']['is_name'];
                         unset($entityData['attributes']['is_name']);
                         if (isset($entityData['attributes'][$isName])) {
                             $entityData['attributes'][$isName]['is_name'] = 1;
                         }
                     }
                     foreach ($entityData['attributes'] as $attrKey => $attributeData) {
                         /** @var \Umc\Base\Model\Core\Attribute $attribute */
                         $attribute = $this->attributeFactory->create();
                         $attribute->addData($attributeData);
                         $attribute->setIndex($attrKey);
                         $entity->addAttribute($attribute);
                     }
                 }
                 unset($data['attribute']);
                 $entity->addData($entityData);
                 $entity->setIndex($key);
                 $this->addEntity($entity);
                 $entitiesByIndex[$key] = $entity;
             }
         }
     }
     if (isset($data['relation'])) {
         foreach ($data['relation'] as $index => $values) {
             foreach ($values as $jndex => $type) {
                 if (isset($entitiesByIndex[$index]) && isset($entitiesByIndex[$jndex])) {
                     /** @var \Umc\Base\Model\Core\Relation $relation */
                     $relation = $this->relationFactory->create();
                     $relation->setEntities($entitiesByIndex[$index], $entitiesByIndex[$jndex], $type);
                     $this->addRelation($relation);
                 }
             }
         }
     }
     return $this;
 }
Пример #2
0
 /**
  * @return \Magento\Customer\Model\Attribute
  */
 protected function _createCustomerAttribute()
 {
     return $this->_attributeFactory->create();
 }