Пример #1
0
 /**
  * validate & save module
  * @return void
  */
 public function execute()
 {
     $response = $this->umcFactory->create();
     $response->setGlue(self::ERROR_GLUE);
     try {
         /** @var \Zend\Stdlib\Parameters $data */
         $data = $this->getRequest()->getPost();
         $module = $this->moduleFactory->create();
         $module->initFromData($data->toArray());
         $errors = $module->validate();
         if (count($errors) == 0) {
             $xml = $module->toXml([], $module->getEntityCode(), true, true);
             $this->writer->setPath($module->getSettings()->getXmlRootPath());
             $this->writer->write($module->getExtensionName() . '.xml', $xml);
             $this->builder->setModule($module)->build();
             $response->setError(false);
             $response->setMessage(__('Done!!! Check you var folder'));
         } else {
             if (isset($errors[''])) {
                 $response->setMessage(implode(self::ERROR_GLUE, $errors['']));
                 unset($errors['']);
             }
             $response->setError(true);
             $response->setAttributes($errors);
         }
     } catch (\Exception $e) {
         $response->setError(true);
         $response->setMessage($e->getMessage());
     }
     $this->getResponse()->setBody($response->toJson());
 }
Пример #2
0
 /**
  * map elements
  *
  * @param array $data
  * @return array
  */
 public function map(array $data)
 {
     /** @var \Umc\Base\Model\Umc $object */
     $object = $this->umcFactory->create();
     $object->setData($data);
     foreach ($this->paths as $path => $elements) {
         $_data = $object->getData($path);
         if (is_array($_data)) {
             foreach ($elements as $element) {
                 foreach ($_data as $key => &$values) {
                     if (isset($values[$element])) {
                         uasort($values[$element], [$this, 'cmp']);
                         $object->setDataByPath($path . '/' . $key . '/' . $element, $values[$element]);
                     }
                 }
             }
         }
     }
     return $object->getData();
 }