function getFolderParent($repositoryId, $folderId, $includeAllowableActions, $includeRelationships, $returnToRoot, $filter = '') { // NOTE the root folder obviously has no parent, throw an ObjectNotFoundException here if this is the root folder if (CMISUtil::isRootFolder($repositoryId, $folderId, $this->ktapi)) { throw new ObjectNotFoundException('Root folder has no parent'); } $ancestry = array(); $repository = new CMISRepository($repositoryId); // if this is not a folder, cannot get folder parent :) $folderId = CMISUtil::decodeObjectId($folderId, $type); // NOTE this will quite possibly break the webservices if ($type != 'Folder') { return $ancestry; } $ktapiFolder = $this->ktapi->get_folder_by_id($folderId); if ($returnToRoot) { $folder = $ktapiFolder->get_folder(); $parents = $folder->generateFolderIDs($folderId); // remove the id of the requesting folder and convert to array $ancestry = explode(',', str_replace(',' . $folderId, '', $parents)); // reverse to get bottom up listing? don't think so with the current implementation // specifying that objectTypes may have children but do not have parents listed. // $ancestry = array_reverse($ancestry); } else { $parent = $ktapiFolder->get_parent_folder_id(); $ancestry[] = $parent; } // need some info about the parent(s) in order to correctly create the hierarchy $tmpArray = array(); foreach ($ancestry as $key => $ancestor) { $tmpArray[$key] = $this->ktapi->get_folder_by_id($ancestor); } $ancestry = $tmpArray; unset($tmpArray); $ancestry = CMISUtil::createParentObjectHierarchy($ancestry, $repository->getRepositoryURI, $this->ktapi); return $ancestry; }
/** * Creates an AtomPub entry for a CMIS entry and adds it to the supplied feed * * @param object $feed The feed to which we add the entry * @param array $cmisEntry The entry data * @param string $parent The parent folder */ public static function createObjectEntry(&$response, $cmisEntry, $parent, $pwc = false, $method = 'GET') { $workspace = $response->getWorkspace(); $type = strtolower($cmisEntry['properties']['ObjectTypeId']['value']); // create entry $entry = $response->newEntry(); // FIXME this maybe belongs in the response feed class only how? if ($method == 'POST' || $pwc) { // append attributes $entry->appendChild($response->newAttr('xmlns', 'http://www.w3.org/2005/Atom')); $entry->appendChild($response->newAttr('xmlns:app', 'http://www.w3.org/2007/app')); $entry->appendChild($response->newAttr('xmlns:cmis', 'http://docs.oasis-open.org/ns/cmis/core/200901')); } // TODO dynamic actual creator name $responseElement = $response->newField('author'); $element = $response->newField('name', 'admin', $responseElement); $entry->appendChild($responseElement); if (!empty($cmisEntry['properties']['ContentStreamLength']['value'])) { $field = $response->newElement('content'); $field->appendChild($response->newAttr('type', $cmisEntry['properties']['ContentStreamMimeType']['value'])); $field->appendChild($response->newAttr('src', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); $entry->appendChild($field); } // content & id tags $id = $cmisEntry['properties']['ObjectId']['value']; $response->newField('id', 'urn:uuid:' . $id, $entry); // links $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'self')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . (!$pwc ? $type : 'pwc') . '/' . $cmisEntry['properties']['ObjectId']['value'])); $entry->appendChild($link); $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'edit')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'])); $entry->appendChild($link); if (strtolower($cmisEntry['properties']['ObjectTypeId']['value']) == 'document' && !empty($cmisEntry['properties']['ContentStreamLength']['value'])) { $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'edit-media')); $link->appendChild($response->newAttr('type', $cmisEntry['properties']['ContentStreamMimeType']['value'])); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); $entry->appendChild($link); $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'enclosure')); $link->appendChild($response->newAttr('type', $cmisEntry['properties']['ContentStreamMimeType']['value'])); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); $entry->appendChild($link); } // according to spec this MUST be present, but spec says that links for function which are not supported // do not need to be present, so unsure for the moment $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'allowableactions')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/permissions')); $entry->appendChild($link); // according to spec this MUST be present, but spec says that links for function which are not supported // do not need to be present, so unsure for the moment $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'relationships')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/rels')); $entry->appendChild($link); // if there is no parent or parent is 0, do not add the parent link // also if this is specifically the root folder, do not add the parent link // if (!empty($cmisEntry['properties']['ParentId']['value']) && !CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['ObjectId']['value'])) if (!CMISUtil::isRootFolder(self::$repositoryId, $cmisEntry['properties']['ObjectId']['value'], self::$ktapi)) { // TODO check parent link is correct, fix if needed $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'parents')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/folder/' . $cmisEntry['properties']['ObjectId']['value'] . '/parent')); $entry->appendChild($link); } // Folder/Document specific links if (strtolower($cmisEntry['properties']['ObjectTypeId']['value']) == 'folder') { $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'children')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/children')); $entry->appendChild($link); $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'descendants')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/descendants')); $entry->appendChild($link); } else { if (strtolower($cmisEntry['properties']['ObjectTypeId']['value']) == 'document') { // according to spec this MUST be present, but spec says that links for function which are not supported // do not need to be present, so unsure for the moment // $link = $response->newElement('link'); // $link->appendChild($response->newAttr('rel', 'allversions')); // $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ParentId']['value'])); // $entry->appendChild($link); // according to spec this MUST be present, but spec says that links for function which are not supported // do not need to be present, so unsure for the moment // $link = $response->newElement('link'); // $link->appendChild($response->newAttr('rel', 'latestversion')); // $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ParentId']['value'])); // $entry->appendChild($link); // if there is a content stream, this link MUST be present // not sure yet where it must point... if (!empty($cmisEntry['properties']['ContentStreamLength']['value'])) { $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'stream')); $link->appendChild($response->newAttr('type', $cmisEntry['properties']['ContentStreamMimeType']['value'])); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); $entry->appendChild($link); } // if the document is checked out and this is NOT the PWC, this link MUST be present // NOTE at the moment the document and the PWC are the same object, so we always show it for a checked out document // TODO separated code for PWC and actual document object if (!empty($cmisEntry['properties']['VersionSeriesCheckedOutId']['value'])) { $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'pwc')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); $entry->appendChild($link); $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'source')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ObjectId']['value'] . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); $entry->appendChild($link); } // $link = $response->newElement('link'); // $link->appendChild($response->newAttr('rel', 'stream')); // $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type // . '/' . $cmisEntry['properties']['ObjectId']['value'] // . '/' . $cmisEntry['properties']['ContentStreamFilename']['value'])); } } $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'type')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/type/' . $type)); $entry->appendChild($link); $link = $response->newElement('link'); $link->appendChild($response->newAttr('rel', 'repository')); $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . '/servicedocument')); $entry->appendChild($link); // according to spec this MUST be present, but spec says that links for function which are not supported // do not need to be present, so unsure for the moment - policies are being abandoned, or so I thought... // $link = $response->newElement('link'); // $link->appendChild($response->newAttr('rel', 'policies')); // $link->appendChild($response->newAttr('href', CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $cmisEntry['properties']['ParentId']['value'])); // $entry->appendChild($link); // end links // TODO proper date $entry->appendChild($response->newField('published', self::formatDatestamp())); $entry->appendChild($response->newElement('summary', $cmisEntry['properties']['Name']['value'])); $entry->appendChild($response->newElement('title', $cmisEntry['properties']['Name']['value'])); $entry->appendChild($response->newField('updated', self::formatDatestamp())); // main CMIS entry $objectElement = $response->newElement('cmis:object'); $propertiesElement = $response->newElement('cmis:properties'); foreach ($cmisEntry['properties'] as $propertyName => $property) { $propElement = $response->newElement('cmis:' . $property['type']); $propElement->appendChild($response->newAttr('cmis:name', $propertyName)); if (!empty($property['value'])) { if ($propertyName == 'ContentStreamUri') { $property['value'] = CMIS_APP_BASE_URI . $workspace . '/' . $type . '/' . $property['value']; } $response->newField('cmis:value', CMISUtil::boolToString($property['value']), $propElement); } $propertiesElement->appendChild($propElement); } $objectElement->appendChild($propertiesElement); $entry->appendChild($objectElement); // after every entry, append a cmis:terminator tag $entry->appendChild($response->newElement('cmis:terminator')); // TODO check determination of when to add app:edited tag // if ($method == 'POST') { $entry->appendChild($response->newElement('app:edited', self::formatDatestamp())); // } }