/**
  * @param AJXP_Node $node
  * @param string $scope
  * @return CompositeShare[]
  */
 protected function compositeShareFromMetaWithScope($node, $scope = "private")
 {
     if ($scope !== AJXP_METADATA_ALLUSERS) {
         $scope = $scope == "private";
     }
     $meta = $node->retrieveMetadata(AJXP_SHARED_META_NAMESPACE, $scope, AJXP_METADATA_SCOPE_REPOSITORY, true);
     $shares = array();
     $composites = array();
     if (!isset($meta["shares"])) {
         return $shares;
     }
     foreach ($meta["shares"] as $id => $shareData) {
         $type = $shareData["type"];
         if ($type == "repository") {
             if (!isset($shares[$id])) {
                 $shares[$id] = array("repository" => $id, "links" => array());
             }
         } else {
             if ($type == "minisite" || $type == "ocs_remote") {
                 $link = $this->shareStore->loadShareObject($id);
                 if (!empty($link)) {
                     $link->setAdditionalMeta($shareData);
                     $linkRepoId = $link->getRepositoryId();
                     if (empty($linkRepoId)) {
                         continue;
                     }
                     if (!isset($shares[$linkRepoId])) {
                         $shares[$linkRepoId] = array("repository" => $linkRepoId, "links" => array());
                     }
                     $shares[$linkRepoId]["links"][] = $link;
                 }
             }
         }
     }
     foreach ($shares as $repoId => $repoData) {
         $composite = new CompositeShare($node, $repoId);
         foreach ($repoData["links"] as $link) {
             $composite->addLink($link);
         }
         $composites[] = $composite;
     }
     return $composites;
 }
 /**
  * @param CompositeShare $compositeShare
  * @return array
  */
 public function compositeShareToJson($compositeShare)
 {
     $repoId = $compositeShare->getRepositoryId();
     $repo = $compositeShare->getRepository();
     $messages = ConfService::getMessages();
     $notExistsData = array("error" => true, "repositoryId" => $repoId, "users_number" => 0, "label" => "Error - Cannot find shared data", "description" => "Cannot find repository", "entries" => array(), "element_watch" => false, "repository_url" => "");
     if ($repoId == null || $repo == null) {
         //CLEAR AND ASSOCIATED LINKS HERE ?
         //$this->getShareStore()->getMetaManager()->removeShareFromMeta($node, $shareId);
         return $notExistsData;
     }
     try {
         $this->getShareStore()->testUserCanEditShare($compositeShare->getOwner(), array("SHARE_ACCESS" => $compositeShare->getVisibilityScope()));
     } catch (Exception $e) {
         $notExistsData["label"] = $e->getMessage();
         return $notExistsData;
     }
     $jsonData = $compositeShare->toJson($this->watcher, $this->getRightsManager(), $this->getPublicAccessManager(), $messages);
     if ($jsonData === false) {
         return $notExistsData;
     }
     return $jsonData;
 }