/** * Initialize document from array * * @param array $array Data * * @return \Gc\Document\Model */ public static function fromArray(array $array) { $documentTable = new Model(); $documentTable->setData($array); $documentTable->setOrigData(); return $documentTable; }
/** * 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)); } }