Пример #1
0
 public function getChilds()
 {
     if ($this->childs === null) {
         $childs = parent::getChilds();
         $hardLink = $this->getHardLinkSource();
         if ($hardLink->getChildsFromSource() && $hardLink->getSourceDocument() && !Pimcore::inAdmin()) {
             foreach ($childs as &$c) {
                 $c = Document_Hardlink_Service::wrap($c);
                 $c->setHardLinkSource($hardLink);
                 $c->setPath(preg_replace("@^" . preg_quote($hardLink->getSourceDocument()->getFullpath()) . "@", $hardLink->getFullpath(), $c->getPath()));
             }
         }
         $this->setChilds($childs);
     }
     return $this->childs;
 }
Пример #2
0
 /**
  * this is used to get childs below a hardlink by a path
  * for example: the requested path is /de/service/contact but /de/service is a hardlink to /en/service
  * then $hardlink would be /en/service and $path /de/service/contact and this function returns then /en/service/contact
  * @static
  * @param Document_Hardlink $hardlink
  * @param $path
  */
 public static function getChildByPath(Document_Hardlink $hardlink, $path)
 {
     if ($hardlink->getChildsFromSource() && $hardlink->getSourceDocument()) {
         $hardlinkRealPath = preg_replace("@^" . preg_quote($hardlink->getRealFullPath()) . "@", $hardlink->getSourceDocument()->getFullpath(), $path);
         $hardLinkedDocument = Document::getByPath($hardlinkRealPath);
         if ($hardLinkedDocument instanceof Document) {
             $hardLinkedDocument = Document_Hardlink_Service::wrap($hardLinkedDocument);
             $hardLinkedDocument->setHardLinkSource($hardlink);
             $_path = $path != "/" ? $_path = dirname($path) : $path;
             $_path = str_replace("\\", "/", $_path);
             // windows patch
             $_path .= $_path != "/" ? "/" : "";
             $hardLinkedDocument->setPath($_path);
             return $hardLinkedDocument;
         }
     }
     return null;
 }
Пример #3
0
 /**
  * @param string $path
  * @return void
  */
 protected function getNearestDocumentByPath($path, $ignoreHardlinks = false)
 {
     if ($this->nearestDocumentByPath instanceof Document) {
         $document = $this->nearestDocumentByPath;
     } else {
         $pathes = array();
         $pathes[] = "/";
         $pathParts = explode("/", $path);
         $tmpPathes = array();
         foreach ($pathParts as $pathPart) {
             $tmpPathes[] = $pathPart;
             $t = implode("/", $tmpPathes);
             if (!empty($t)) {
                 $pathes[] = $t;
             }
         }
         $pathes = array_reverse($pathes);
         foreach ($pathes as $p) {
             if ($document = Document::getByPath($p)) {
                 $this->nearestDocumentByPath = $document;
                 break;
             }
         }
     }
     if ($document) {
         if (!$ignoreHardlinks) {
             if ($document instanceof Document_Hardlink) {
                 if ($hardLinkedDocument = Document_Hardlink_Service::getChildByPath($document, $path)) {
                     $document = $hardLinkedDocument;
                 } else {
                     $document = Document_Hardlink_Service::wrap($document);
                 }
             }
         }
         return $document;
     }
     return null;
 }