Пример #1
0
 /**
  * Import Documents
  *
  * @param array &$ids     Ids
  * @param array &$errors  Errors
  * @param array $children Children list
  *
  * @return void
  */
 protected function importDocuments(&$ids, &$errors, $children)
 {
     foreach ($children['children'] as $child) {
         $urlKey = (string) $child->url_key;
         $model = Document\Model::fromUrlKey($urlKey);
         $attributes = $child->attributes();
         $id = (int) $attributes['id'];
         if (empty($model)) {
             $model = Document\Model::fromId($id);
             if (empty($model)) {
                 $model = new Document\Model();
             }
         }
         $documentTypeId = isset($ids['document_types'][(int) $child->document_type_id]) ? $ids['document_types'][(int) $child->document_type_id] : $model->getDocumentTypeId();
         $viewId = isset($ids['views'][(int) $child->view_id]) ? $ids['views'][(int) $child->view_id] : $model->getViewId();
         $layoutId = isset($ids['layouts'][(int) $child->layout_id]) ? $ids['layouts'][(int) $child->layout_id] : $model->getLayoutId();
         $parentId = isset($ids['layouts'][(int) $child->parent_id]) ? $ids['layouts'][(int) $child->parent_id] : $model->getParentId();
         $name = (string) $child->name;
         $status = (string) $child->status;
         $userId = (int) $child->user_id;
         $sortOrder = (int) $child->sort_order;
         $showInNav = (int) $child->show_in_nav;
         $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'url_key' => $urlKey, 'status' => empty($status) ? $model->getStatus() : $status, 'show_in_nav' => empty($showInNav) ? $model->getShowInNav() : $showInNav, 'sort_order' => empty($sortOrder) ? $model->getSortOrder() : $sortOrder, 'icon_id' => (int) $child->icon_id, 'view_id' => $viewId, 'parent_id' => $parentId, 'user_id' => $userId, 'layout_id' => $layoutId, 'document_type_id' => empty($documentTypeId) ? $model->getDocumentTypeId() : $documentTypeId));
         if ($model->getUserId() === null) {
             $model->setUserId($this->serviceLocator->get('Auth')->getIdentity()->getId());
         }
         try {
             if (!empty($model)) {
                 $model->save();
                 $ids['documents'][$id] = $model->getId();
                 $values = (array) $child->properties;
                 if (isset($values['property_value']) and is_array($values['property_value'])) {
                     $values = $values['property_value'];
                 }
                 foreach ($values as $value) {
                     $documentId = (int) $value->document_id;
                     $propertyId = (int) $value->property_id;
                     $valueModel = new Property\Value\Model();
                     $valueModel->load(null, isset($ids['documents'][$documentId]) ? $ids['documents'][$documentId] : $documentId, isset($ids['properties'][$propertyId]) ? $ids['properties'][$propertyId] : $propertyId);
                     $valueModel->setValue((string) base64_decode($value->value));
                     $valueModel->save();
                 }
             }
         } catch (Exception $e) {
             $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save document with id (%d)'), $id);
         }
     }
 }
Пример #2
0
 /**
  * Paste document
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function pasteAction()
 {
     $parentId = $this->getRouteMatch()->getParam('id', null);
     $session = $this->getSession();
     if (!empty($parentId)) {
         $parentDocument = DocumentModel::fromId($parentId);
         if (empty($parentDocument)) {
             return $this->returnJson(array('success' => false));
         }
     }
     if (!empty($session['document-cut'])) {
         $document = DocumentModel::fromId($session['document-cut']);
         if (empty($document)) {
             return $this->returnJson(array('success' => false));
         }
         if (!empty($parentDocument)) {
             $availableChildren = $parentDocument->getDocumentType()->getDependencies();
             if (!in_array($document->getDocumentType()->getId(), $availableChildren)) {
                 return $this->returnJson(array('success' => false));
             }
         }
         $searchDocument = DocumentModel::fromUrlKey($document->getUrlKey(), $parentId);
         if (!empty($searchDocument)) {
             return $this->returnJson(array('success' => false));
         }
         $document->setParentId($parentId);
         $document->save();
         unset($session['document-cut']);
         return $this->returnJson(array('success' => true));
     } elseif (!empty($session['document-copy'])) {
         $urlKey = $this->getRequest()->getQuery('url_key');
         $searchDocument = DocumentModel::fromUrlKey($urlKey, $parentId);
         if (!empty($searchDocument)) {
             return $this->returnJson(array('success' => false));
         }
         $document = DocumentModel::fromId($session['document-copy']);
         if (empty($document)) {
             return $this->returnJson(array('success' => false));
         }
         if (!empty($parentDocument)) {
             $availableChildren = $parentDocument->getDocumentType()->getDependencies();
             if (!in_array($document->getDocumentType()->getId(), $availableChildren)) {
                 return $this->returnJson(array('success' => false));
             }
         }
         $copyDocument = new DocumentModel();
         $copyDocumentProperties = new Property\Collection();
         $copyDocumentProperties->load(null, null, $document->getId());
         $copyDocument->addData($document->getData());
         $copyDocument->setData('id', null);
         $copyDocument->setParentId($parentId);
         $copyDocument->setName($this->getRequest()->getQuery('name'));
         $copyDocument->setUrlKey($urlKey);
         $copyDocument->save();
         foreach ($copyDocumentProperties->getProperties() as $property) {
             $value = $property->getValueModel();
             if (empty($value)) {
                 continue;
             }
             $copyProperty = new Property\Value\Model();
             $copyProperty->addData($value->getData());
             $copyProperty->setData('id', null);
             $copyProperty->setDocumentId($copyDocument->getId());
             $copyProperty->save();
         }
         return $this->returnJson(array('success' => true));
     } else {
         return $this->returnJson(array('success' => false));
     }
 }