You are here

class CMISService in CMIS API 7

Same name and namespace in other branches
  1. 6.4 cmis_common/lib/cmis_repository_wrapper.php \CMISService
  2. 6.3 cmis_common/lib/cmis_repository_wrapper.php \CMISService

Hierarchy

Expanded class hierarchy of CMISService

File

cmis_common/lib/cmis_repository_wrapper.php, line 450

View source
class CMISService extends CMISRepositoryWrapper {
  var $_link_cache;
  function __construct($url, $username, $password, $options = null) {
    parent::__construct($url, $username, $password, $options);
    $this->_link_cache = array();
    $this->_title_cache = array();
    $this->_objTypeId_cache = array();
    $this->_type_cache = array();
  }

  // Utility Methods -- Added Titles
  // Should refactor to allow for single object
  function cacheEntryInfo($obj) {
    $this->_link_cache[$obj->id] = $obj->links;
    $this->_title_cache[$obj->id] = $obj->properties["cmis:name"];

    // Broad Assumption Here?
    $this->_objTypeId_cache[$obj->id] = $obj->properties["cmis:objectTypeId"];
  }
  function cacheFeedInfo($objs) {
    foreach ($objs->objectList as $obj) {
      $this
        ->cacheEntryInfo($obj);
    }
  }
  function cacheTypeInfo($tDef) {
    $this->_type_cache[$tDef->id] = $tDef;
  }
  function getPropertyType($typeId, $propertyId) {
    if (!empty($this->_type_cache[$typeId])) {
      return $this->_type_cache[$typeId]->properties[$propertyId]["cmis:propertyType"];
    }
    $obj = $this
      ->getTypeDefinition($typeId);
    return $obj->properties[$propertyId]["cmis:propertyType"];
  }
  function getObjectType($objectId) {
    if ($this->_objTypeId_cache[$objectId]) {
      return $this->_objTypeId_cache[$objectId];
    }
    $obj = $this
      ->getObject($objectId);
    return $obj->properties["cmis:objectTypeId"];
  }
  function getTitle($objectId) {
    if ($this->_title_cache[$objectId]) {
      return $this->_title_cache[$objectId];
    }
    $obj = $this
      ->getObject($objectId);
    return $obj->properties["cmis:name"];
  }
  function getLink($objectId, $linkName) {
    if (array_key_exists($objectId, $this->_link_cache)) {
      return $this->_link_cache[$objectId][$linkName];
    }
    $obj = $this
      ->getObject($objectId);
    return $obj->links[$linkName];
  }

  // Repository Services
  function getRepositories() {
    throw Exception("Not Implemented");
  }
  function getRepositoryInfo() {
    return $this->workspace;
  }
  function getTypeChildren() {
    throw Exception("Not Implemented");
  }
  function getTypeDescendants() {
    throw Exception("Not Implemented");
  }
  function getTypeDefinition($typeId, $options = array()) {

    // Nice to have
    $varmap = $options;
    $varmap["id"] = $typeId;
    $myURL = $this
      ->processTemplate($this->workspace->uritemplates['typebyid'], $varmap);
    $ret = $this
      ->doGet($myURL);
    $obj = $this
      ->extractTypeDef($ret->body);
    $this
      ->cacheTypeInfo($obj);
    return $obj;
  }
  function getObjectTypeDefinition($objectId) {

    // Nice to have
    $myURL = $this
      ->getLink($objectId, "describedby");
    $ret = $this
      ->doGet($myURL);
    $obj = $this
      ->extractTypeDef($ret->body);
    $this
      ->cacheTypeInfo($obj);
    return $obj;
  }

  //Navigation Services
  function getFolderTree($folderId, $depth, $options = array()) {
    $hash_values = $options;
    $hash_values['depth'] = $depth;
    $myURL = $this
      ->getLink($folderId, "http://docs.oasis-open.org/ns/cmis/link/200908/foldertree");
    $myURL = CMISRepositoryWrapper::getOpUrl($myURL, $hash_values);
    $ret = $this
      ->doGet($myURL);
    $objs = $this
      ->extractObjectFeed($ret->body);
    $this
      ->cacheFeedInfo($objs);
    return $objs;
  }
  function getDescendants() {

    // Nice to have
    throw Exception("Not Implemented");
  }
  function getChildren($objectId, $options = array()) {
    $myURL = $this
      ->getLink($objectId, "down");
    if (count($options) > 0) {
      $myURL .= '&' . urldecode(http_build_query($options));
    }
    $ret = $this
      ->doGet($myURL);
    $objs = $this
      ->extractObjectFeed($ret->body);
    $this
      ->cacheFeedInfo($objs);
    return $objs;
  }
  function getFolderParent($objectId, $options = array()) {

    //yes
    $myURL = $this
      ->getLink($objectId, "up");
    if (count($options) > 0) {
      $myURL .= '&' . urldecode(http_build_query($options));
    }
    $ret = $this
      ->doGet($myURL);
    $obj = $this
      ->extractObjectEntry($ret->body);
    $this
      ->cacheEntryInfo($obj);
    return $obj;
  }
  function getObjectParents($objectId, $options = array()) {

    // yes
    $myURL = $this
      ->getLink($objectId, "up");
    if (count($options) > 0) {
      $myURL .= '&' . urldecode(http_build_query($options));
    }
    $ret = $this
      ->doGet($myURL);
    $objs = $this
      ->extractObjectFeed($ret->body);
    $this
      ->cacheFeedInfo($objs);
    return $objs;
  }
  function getCheckedOutDocs($options = array()) {
    $obj_url = $this->workspace->collections['checkedout'];
    if (count($options) > 0) {
      $myURL .= '&' . urldecode(http_build_query($options));
    }
    $ret = $this
      ->doGet($myURL);
    $objs = $this
      ->extractObjectFeed($ret->body);
    $this
      ->cacheFeedInfo($objs);
    return $objs;
  }

  //Discovery Services
  static function getQueryTemplate() {
    ob_start();
    echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
    ?>
<cmis:query xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/"
xmlns:cmism="http://docs.oasis-open.org/ns/cmis/messaging/200908/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:app="http://www.w3.org/2007/app"
xmlns:cmisra="http://docs.oasisopen.org/ns/cmis/restatom/200908/">
<cmis:statement><![CDATA[{q}]]></cmis:statement>
<cmis:searchAllVersions>{searchAllVersions}</cmis:searchAllVersions>
<cmis:includeAllowableActions>{includeAllowableActions}</cmis:includeAllowableActions>
<cmis:includeRelationships>{includeRelationships}</cmis:includeRelationships>
<cmis:renditionFilter>{renditionFilter}</cmis:renditionFilter>
<cmis:maxItems>{maxItems}</cmis:maxItems>
<cmis:skipCount>{skipCount}</cmis:skipCount>
</cmis:query>
<?php

    return ob_get_clean();
  }
  function query($q, $options = array()) {
    static $query_template;
    if (!isset($query_template)) {
      $query_template = CMISService::getQueryTemplate();
    }
    $default_hash_values = array(
      "includeAllowableActions" => "true",
      "searchAllVersions" => "false",
      "maxItems" => 10,
      "skipCount" => 0,
    );
    $hash_values = array_merge($default_hash_values, $options);
    $hash_values['q'] = $q;
    $post_value = CMISRepositoryWrapper::processTemplate($query_template, $hash_values);
    $ret = $this
      ->doPost($this->workspace->collections['query'], $post_value, MIME_CMIS_QUERY);
    $objs = $this
      ->extractObjectFeed($ret->body);
    $this
      ->cacheFeedInfo($objs);
    return $objs;
  }
  function getContentChanges() {
    throw Exception("Not Implemented");
  }

  //Object Services
  static function getEntryTemplate() {
    ob_start();
    echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
    ?>
<atom:entry xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/"
xmlns:cmism="http://docs.oasis-open.org/ns/cmis/messaging/200908/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:app="http://www.w3.org/2007/app"
xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/">
<atom:title>{title}</atom:title>
{SUMMARY}
{CONTENT}
<cmisra:object><cmis:properties>{PROPERTIES}</cmis:properties></cmisra:object>
</atom:entry>
<?php

    return ob_get_clean();
  }
  static function getPropertyTemplate() {
    ob_start();
    ?>
		<cmis:property{propertyType} propertyDefinitionId="{propertyId}">
			<cmis:value>{properties}</cmis:value>
		</cmis:property{propertyType}>
<?php

    return ob_get_clean();
  }
  function processPropertyTemplates($objectType, $propMap) {
    static $propTemplate;
    static $propertyTypeMap;
    if (!isset($propTemplate)) {
      $propTemplate = CMISService::getPropertyTemplate();
    }
    if (!isset($propertyTypeMap)) {

      // Not sure if I need to do this like this
      $propertyTypeMap = array(
        "integer" => "Integer",
        "boolean" => "Boolean",
        "datetime" => "DateTime",
        "decimal" => "Decimal",
        "html" => "Html",
        "id" => "Id",
        "string" => "String",
        "url" => "Url",
        "xml" => "Xml",
      );
    }
    $propertyContent = "";
    $hash_values = array();
    foreach ($propMap as $propId => $propValue) {
      $hash_values['propertyType'] = $propertyTypeMap[$this
        ->getPropertyType($objectType, $propId)];
      $hash_values['propertyId'] = $propId;
      if (is_array($propValue)) {
        $first_one = true;
        $hash_values['properties'] = "";
        foreach ($propValue as $val) {

          //This is a bit of a hack
          if ($first_one) {
            $first_one = false;
          }
          else {
            $hash_values['properties'] .= "</cmis:values>\n<cmis:values>";
          }
          $hash_values['properties'] .= $val;
        }
      }
      else {
        $hash_values['properties'] = $propValue;
      }

      //echo "HASH:\n";

      //print_r(array("template" =>$propTemplate, "Hash" => $hash_values));
      $propertyContent .= CMISRepositoryWrapper::processTemplate($propTemplate, $hash_values);
    }
    return $propertyContent;
  }
  static function getContentEntry($content, $content_type = "application/octet-stream") {
    static $contentTemplate;
    if (!isset($contentTemplate)) {
      $contentTemplate = CMISService::getContentTemplate();
    }
    if ($content) {
      if (is_resource($content) && get_resource_type($content) == 'stream') {

        // Base64 encode the content on read.
        stream_filter_append($content, 'convert.base64-encode', STREAM_FILTER_READ);
        return CMISRepositoryWrapper::processTemplateAsStream($contentTemplate, array(
          "content" => $content,
          "content_type" => $content_type,
        ));
      }
      else {
        return CMISRepositoryWrapper::processTemplate($contentTemplate, array(
          "content" => base64_encode($content),
          "content_type" => $content_type,
        ));
      }
    }
    else {
      return "";
    }
  }
  static function getSummaryTemplate() {
    ob_start();
    ?>
		<atom:summary>{summary}</atom:summary>
<?php

    return ob_get_clean();
  }
  static function getContentTemplate() {
    ob_start();
    ?>
		<cmisra:content>
			<cmisra:mediatype>
				{content_type}
			</cmisra:mediatype>
			<cmisra:base64>
				{content}
			</cmisra:base64>
		</cmisra:content>
<?php

    return ob_get_clean();
  }
  static function createAtomEntry($name, $properties) {
  }
  function getObject($objectId, $options = array()) {
    $varmap = $options;
    $varmap["id"] = $objectId;
    $obj_url = $this
      ->processTemplate($this->workspace->uritemplates['objectbyid'], $varmap);
    $ret = $this
      ->doGet($obj_url);
    $obj = $this
      ->extractObject($ret->body);
    $this
      ->cacheEntryInfo($obj);
    return $obj;
  }
  function getObjectByPath($path, $options = array()) {
    $varmap = $options;
    $varmap["path"] = $path;
    $obj_url = $this
      ->processTemplate($this->workspace->uritemplates['objectbypath'], $varmap);
    $ret = $this
      ->doGet($obj_url);
    $obj = $this
      ->extractObject($ret->body);
    $this
      ->cacheEntryInfo($obj);
    return $obj;
  }
  function getProperties($objectId, $options = array()) {

    // May need to set the options array default --
    return $this
      ->getObject($objectId, $options);
  }
  function getAllowableActions($objectId, $options = array()) {

    // get stripped down version of object (for the links) and then get the allowable actions?
    // Low priority -- can get all information when getting object
    throw Exception("Not Implemented");
  }
  function getRenditions($objectId, $options = array(
    OPT_RENDITION_FILTER => "*",
  )) {
    return getObject($objectId, $options);
  }
  function getContentStream($objectId, $options = array()) {

    // Yes
    $myURL = $this
      ->getLink($objectId, "edit-media");
    $ret = $this
      ->doGet($myURL);

    // doRequest stores the last request information in this object
    return $ret->body;
  }
  function postObject($folderId, $objectName, $objectType, $properties = array(), $content = null, $content_type = "application/octet-stream", $options = array()) {

    // Yes
    $myURL = $this
      ->getLink($folderId, "down");

    // TODO: Need Proper Query String Handling
    // Assumes that the 'down' link does not have a querystring in it
    $myURL = CMISRepositoryWrapper::getOpUrl($myURL, $options);
    static $entry_template;
    if (!isset($entry_template)) {
      $entry_template = CMISService::getEntryTemplate();
    }
    if (is_array($properties)) {
      $hash_values = $properties;
    }
    else {
      $hash_values = array();
    }
    if (!isset($hash_values["cmis:objectTypeId"])) {
      $hash_values["cmis:objectTypeId"] = $objectType;
    }
    $properties_xml = $this
      ->processPropertyTemplates($objectType, $hash_values);
    if (is_array($options)) {
      $hash_values = $options;
    }
    else {
      $hash_values = array();
    }
    $hash_values["PROPERTIES"] = $properties_xml;
    $hash_values["SUMMARY"] = CMISService::getSummaryTemplate();
    if ($content) {
      $hash_values["CONTENT"] = CMISService::getContentEntry($content, $content_type);
    }
    if (!isset($hash_values['title'])) {
      $hash_values['title'] = preg_replace("/[^A-Za-z0-9\\s.&; ]/", '', htmlentities($objectName));
    }
    if (!isset($hash_values['summary'])) {
      $hash_values['summary'] = preg_replace("/[^A-Za-z0-9\\s.&; ]/", '', htmlentities($objectName));
    }
    $post_value = CMISRepositoryWrapper::processTemplateAsStream($entry_template, $hash_values);
    $ret = $this
      ->doPost($myURL, $post_value, MIME_ATOM_XML_ENTRY);

    // print "DO_POST\n";
    // print_r($ret);
    $obj = $this
      ->extractObject($ret->body);
    $this
      ->cacheEntryInfo($obj);
    return $obj;
  }
  function createDocument($folderId, $fileName, $properties = array(), $content = null, $content_type = "application/octet-stream", $options = array()) {

    // Yes
    return $this
      ->postObject($folderId, $fileName, "cmis:document", $properties, $content, $content_type, $options);
  }
  function createDocumentFromSource() {

    //Yes?
    throw Exception("Not Implemented in This Binding");
  }
  function createFolder($folderId, $folderName, $properties = array(), $options = array()) {

    // Yes
    return $this
      ->postObject($folderId, $folderName, "cmis:folder", $properties, null, null, $options);
  }
  function createRelationship() {

    // Not in first Release
    throw Exception("Not Implemented");
  }
  function createPolicy() {

    // Not in first Release
    throw Exception("Not Implemented");
  }
  function updateProperties($objectId, $properties = array(), $options = array()) {

    // Yes
    $varmap = $options;
    $varmap["id"] = $objectId;
    $objectName = $this
      ->getTitle($objectId);
    $objectType = $this
      ->getObjectType($objectId);
    $obj_url = $this
      ->getLink($objectId, "edit");
    $obj_url = CMISRepositoryWrapper::getOpUrl($obj_url, $options);
    static $entry_template;
    if (!isset($entry_template)) {
      $entry_template = CMISService::getEntryTemplate();
    }
    if (is_array($properties)) {
      $hash_values = $properties;
    }
    else {
      $hash_values = array();
    }
    $properties_xml = $this
      ->processPropertyTemplates($objectType, $hash_values);
    if (is_array($options)) {
      $hash_values = $options;
    }
    else {
      $hash_values = array();
    }
    $fixed_hash_values = array(
      "PROPERTIES" => $properties_xml,
      "SUMMARY" => CMISService::getSummaryTemplate(),
    );

    // merge the fixes hash values first so that the processing order is correct
    $hash_values = array_merge($fixed_hash_values, $hash_values);
    if (!isset($hash_values['title'])) {
      $hash_values['title'] = $objectName;
    }
    if (!isset($hash_values['summary'])) {
      $hash_values['summary'] = $objectName;
    }
    $put_value = CMISRepositoryWrapper::processTemplate($entry_template, $hash_values);
    $ret = $this
      ->doPut($obj_url, $put_value, MIME_ATOM_XML_ENTRY);
    $obj = $this
      ->extractObject($ret->body);
    $this
      ->cacheEntryInfo($obj);
    return $obj;
  }
  function moveObject($objectId, $targetFolderId, $sourceFolderId, $options = array()) {

    //yes
    $options['sourceFolderId'] = $sourceFolderId;
    return $this
      ->postObject($targetFolderId, $this
      ->getTitle($objectId), $this
      ->getObjectType($objectId), array(
      "cmis:objectId" => $objectId,
    ), null, null, $options);
  }
  function deleteObject($objectId, $options = array()) {

    //Yes
    $varmap = $options;
    $varmap["id"] = $objectId;
    $obj_url = $this
      ->getLink($objectId, "edit");
    $ret = $this
      ->doDelete($obj_url);
    return;
  }
  function deleteTree() {

    // Nice to have
    throw Exception("Not Implemented");
  }
  function setContentStream($objectId, $content, $content_type, $options = array()) {

    //Yes
    $myURL = $this
      ->getLink($objectId, "edit-media");
    $ret = $this
      ->doPut($myURL, $content, $content_type);
  }
  function deleteContentStream($objectId, $options = array()) {

    //yes
    $myURL = $this
      ->getLink($objectId, "edit-media");
    $ret = $this
      ->doDelete($myURL);
    return;
  }

  //Versioning Services
  function getPropertiesOfLatestVersion($objectId, $options = array()) {
    throw Exception("Not Implemented");
  }
  function getObjectOfLatestVersion($objectId, $options = array()) {
    throw Exception("Not Implemented");
  }
  function getAllVersions() {
    throw Exception("Not Implemented");
  }
  function checkOut() {
    throw Exception("Not Implemented");
  }
  function checkIn() {
    throw Exception("Not Implemented");
  }
  function cancelCheckOut() {
    throw Exception("Not Implemented");
  }
  function deleteAllVersions() {
    throw Exception("Not Implemented");
  }

  //Relationship Services
  function getObjectRelationships() {

    // get stripped down version of object (for the links) and then get the relationships?
    // Low priority -- can get all information when getting object
    throw Exception("Not Implemented");
  }

  //Multi-Filing Services
  function addObjectToFolder() {

    // Probably
    throw Exception("Not Implemented");
  }
  function removeObjectFromFolder() {

    //Probably
    throw Exception("Not Implemented");
  }

  //Policy Services
  function getAppliedPolicies() {
    throw Exception("Not Implemented");
  }
  function applyPolicy() {
    throw Exception("Not Implemented");
  }
  function removePolicy() {
    throw Exception("Not Implemented");
  }

  //ACL Services
  function getACL() {
    throw Exception("Not Implemented");
  }
  function applyACL() {
    throw Exception("Not Implemented");
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CMISRepositoryWrapper::$authenticated property
CMISRepositoryWrapper::$last_request property
CMISRepositoryWrapper::$namespaces static property
CMISRepositoryWrapper::$password property
CMISRepositoryWrapper::$url property
CMISRepositoryWrapper::$username property
CMISRepositoryWrapper::$workspace property
CMISRepositoryWrapper::connect function
CMISRepositoryWrapper::doDelete function
CMISRepositoryWrapper::doGet function
CMISRepositoryWrapper::doPost function
CMISRepositoryWrapper::doPut function
CMISRepositoryWrapper::doRequest function 1
CMISRepositoryWrapper::doXQuery static function
CMISRepositoryWrapper::doXQueryFromNode static function
CMISRepositoryWrapper::extractObject static function
CMISRepositoryWrapper::extractObjectFeed static function
CMISRepositoryWrapper::extractObjectFeedFromNode static function
CMISRepositoryWrapper::extractObjectFromNode static function
CMISRepositoryWrapper::extractTypeDef static function
CMISRepositoryWrapper::extractTypeDefFromNode static function
CMISRepositoryWrapper::extractWorkspace static function
CMISRepositoryWrapper::extractWorkspaceFromNode static function
CMISRepositoryWrapper::getLastRequest function
CMISRepositoryWrapper::getLastRequestBody function
CMISRepositoryWrapper::getLastRequestCode function
CMISRepositoryWrapper::getLastRequestContentLength function
CMISRepositoryWrapper::getLastRequestContentSent function
CMISRepositoryWrapper::getLastRequestContentType function
CMISRepositoryWrapper::getLastRequestContentTypeSent function
CMISRepositoryWrapper::getLastRequestMethod function
CMISRepositoryWrapper::getLastRequestURL function
CMISRepositoryWrapper::getLinksArray static function
CMISRepositoryWrapper::getOpUrl static function
CMISRepositoryWrapper::processTemplate static function
CMISRepositoryWrapper::processTemplateAsStream static function
CMISService::$_link_cache property
CMISService::addObjectToFolder function
CMISService::applyACL function
CMISService::applyPolicy function
CMISService::cacheEntryInfo function
CMISService::cacheFeedInfo function
CMISService::cacheTypeInfo function
CMISService::cancelCheckOut function
CMISService::checkIn function
CMISService::checkOut function
CMISService::createAtomEntry static function
CMISService::createDocument function
CMISService::createDocumentFromSource function
CMISService::createFolder function
CMISService::createPolicy function
CMISService::createRelationship function
CMISService::deleteAllVersions function
CMISService::deleteContentStream function
CMISService::deleteObject function
CMISService::deleteTree function
CMISService::getACL function
CMISService::getAllowableActions function
CMISService::getAllVersions function
CMISService::getAppliedPolicies function
CMISService::getCheckedOutDocs function
CMISService::getChildren function
CMISService::getContentChanges function
CMISService::getContentEntry static function
CMISService::getContentStream function
CMISService::getContentTemplate static function
CMISService::getDescendants function
CMISService::getEntryTemplate static function
CMISService::getFolderParent function
CMISService::getFolderTree function
CMISService::getLink function
CMISService::getObject function
CMISService::getObjectByPath function
CMISService::getObjectOfLatestVersion function
CMISService::getObjectParents function
CMISService::getObjectRelationships function
CMISService::getObjectType function
CMISService::getObjectTypeDefinition function
CMISService::getProperties function
CMISService::getPropertiesOfLatestVersion function
CMISService::getPropertyTemplate static function
CMISService::getPropertyType function
CMISService::getQueryTemplate static function
CMISService::getRenditions function
CMISService::getRepositories function
CMISService::getRepositoryInfo function
CMISService::getSummaryTemplate static function
CMISService::getTitle function
CMISService::getTypeChildren function
CMISService::getTypeDefinition function
CMISService::getTypeDescendants function
CMISService::moveObject function
CMISService::postObject function
CMISService::processPropertyTemplates function
CMISService::query function
CMISService::removeObjectFromFolder function
CMISService::removePolicy function
CMISService::setContentStream function
CMISService::updateProperties function
CMISService::__construct function Overrides CMISRepositoryWrapper::__construct