/** * Fetch document by id * @param integer $id * @throws Exception */ public function getDocumentById($id) { $tags = $this->_repository->getDocument((int) $id); if (empty($tags)) { throw new \Exception('Document not found'); } $xml = new XmlDocument(); $xml->setId($id); foreach ($tags as $tag) { $tagObj = new XmlTag(); $tagObj->setId($tag['documents_tags_id']); $tagObj->setDocumentId($tag['documents_id']); $tagObj->setTagId($tag['tag_id']); $tagObj->setParentTagId($tag['parent_tag_id']); $tagObj->setTagName($tag['tag_name']); $tagObj->setValue($tag['value']); /** * we have only one attribute per tag */ if (!is_null($tag['attribute_name'])) { $attribute = new XmlAttribute(); $attribute->setId($tag['tags_attributes_id']); $attribute->setDocumentsTagId($tagObj->getId()); $attribute->setName($tag['attribute_name']); $attribute->setValue($tag['attribute_value']); $tagObj->addAttribute($attribute); } $xml->addTag($tagObj, true); } return $xml; }