Пример #1
0
 /**
  * @param mnRelation $entity
  * @param array $data
  * @return mnRelation|void
  */
 public function load(EntityInterface $entity, array $data)
 {
     parent::load($entity, $data);
     $firstField = $this->getFirstFieldName();
     $secondField = $this->getSecondFieldName();
     if (isset($data[$firstField])) {
         $this->setField($entity, self::FIRST_ENTITY_FIELD, $data[$firstField]);
     } elseif (isset($data[self::FIRST_ENTITY_FIELD])) {
         $this->setField($entity, self::FIRST_ENTITY_FIELD, $data[self::FIRST_ENTITY_FIELD]);
     }
     if (isset($data[$secondField])) {
         $this->setField($entity, self::SECOND_ENTITY_FIELD, $data[$secondField]);
     } elseif (isset($data[self::SECOND_ENTITY_FIELD])) {
         $this->setField($entity, self::SECOND_ENTITY_FIELD, $data[self::SECOND_ENTITY_FIELD]);
     }
     return $entity;
 }
Пример #2
0
 public function load(EntityInterface $entity, array $data)
 {
     $cm = $this->getCategoryManager();
     if (isset($data["categories"])) {
         $data["categories"] = is_array($data["categories"]) ? $data["categories"] : explode(',', $data["categories"]);
         foreach ($data["categories"] as $key => $category) {
             if (is_numeric($category)) {
                 $data["categories"][$key] = (int) $category;
             } else {
                 $query = ['name' => $category];
                 $category = $cm->findOne($query);
                 if (!$category) {
                     $category = $cm->create($query);
                     $cm->save($category);
                 }
                 $data["categories"][$key] = $category->getId();
             }
         }
     } else {
         $data["categories"] = [];
     }
     if (!empty($data["categories"])) {
         $cm->addReferredIds($data["categories"]);
     }
     if (isset($data['images'])) {
         $fm = $this->getFileManager();
         foreach ($data['images'] as $image) {
             if (isset($image['id'])) {
                 if (isset($image['removed']) && $image['removed'] === true) {
                     $fm->deleteById($image['id']);
                 } else {
                     /** @var \Attach\Model\File $row */
                     $row = $fm->findById($image['id']);
                     if (isset($image['name'])) {
                         $row->setName($image['name']);
                     }
                     if (isset($image['description'])) {
                         $row->setDescription($image['description']);
                     }
                     $fm->save($row);
                 }
             }
         }
     }
     if (isset($data['flowImages'])) {
         $fm = $this->getFileManager();
         foreach ($data['flowImages'] as $image) {
             if (isset($image['uniqueIdentifier'])) {
                 $type = FileSystem::FST_IMAGE;
                 //                    $maxFileSize = $this->getConfig(["Articles", "Attach", "Size"], 500*1024);
                 $path = ROOT_DIR . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . $image['uniqueIdentifier'];
                 $file = new FlowFile($image['uniqueIdentifier'], $path);
                 if (!$file->checkType($type)) {
                     continue;
                 }
                 //                    if ($file->getSize() > $maxSize) {
                 //                        continue;
                 //                    }
                 $title = '';
                 if (isset($image['name'])) {
                     $title = $image['name'];
                 }
                 $description = '';
                 if (isset($image['description'])) {
                     $description = $image['description'];
                 }
                 $fm->saveFileForObject($entity, $file, $title, $description);
             }
         }
     }
     parent::load($entity, $data);
     return $entity;
 }