AnsweredAssumed Answered

browse the alfresco repository 'windows style'

Question asked by mmariotti on Aug 9, 2007
Latest reply on Sep 12, 2007 by hael
Hi, i post a way to browse the repository that show all the tree while "browsing".(like windows file system)



public function CreateTree($node,$store,$session)
  {
    foreach($node->children as $child)
    {
     
      if($child->child->type == "{http://www.alfresco.org/model/content/1.0}folder")
      {
        $c_uuid = $child->child->id;
        $c_type = "folder";
      }
      else
      {
        $c_content = $child->child->cm_content;
        $c_uuid = $c_content->getUrl();
        $c_type = "content";
      }
     
      $c_title = $child->child->cm_title;
      $c_description = $child->child->cm_description;
      $c_url_name = $child->child->cm_name;
     
      $c_data[] = array('id'=>$c_uuid,'name'=>$c_url_name,'type'=>$c_type, 'title'=>$c_title, 'description'=>$c_description);
    }
         
    foreach($node->parents as $parent)
    {
      $id = $parent->parent->id;
      $parent_name = $parent->parent->cm_name;
     
      while($parent_name != "Company Home")
      {
        $node2 = $session->getNode($store,$id);
        $data = array();
        foreach($node2->children as $child2)
        {
          if($parent->child->cm_name == $child2->child->cm_name)
          {
            $uuid = $child2->child->id;
            $url_name = $child2->child->cm_name;
            if($child2->child->type == "{http://www.alfresco.org/model/content/1.0}folder")
            {
              $uuid = $child2->child->id;
              $type = "folder";
            }
            else
            {
              $content = $child2->child->cm_content;
              $uuid = $content->getUrl();
              $type = "content";
            };
            $title = $child2->child->cm_title;
            $description = $child2->child->cm_description;
            $content = $c_data;
           
            $data[] = array('id'=>$uuid,'name'=>$url_name,'type'=>$type, 'title'=>$title, 'description'=>$description, 'content'=>$content);
          }else{
             
            $uuid = $child2->child->id;
            $url_name = $child2->child->cm_name;
            if($child2->child->type == "{http://www.alfresco.org/model/content/1.0}folder")
            {
              $uuid = $child2->child->id;
              $type = "folder";
            }
            else
            {
              $content = $child2->child->cm_content;
              $uuid = $content->getUrl();
              $type = "content";
            };
            $title = $child2->child->cm_title;
            $description = $child2->child->cm_description;
           
            $data[] = array('id'=>$uuid,'name'=>$url_name,'type'=>$type, 'title'=>$title, 'description'=>$description);
          }
        }
        foreach($node2->parents as $parent2)
        {
          //assegno i nuovi valori per iserire il parent superiore
          $parent_name = $parent2->parent->cm_name;
          $parent->child->cm_name = $parent2->child->cm_name;
          $id = $parent2->parent->id;
          $c_data = $data;
        }
      }
    }
   
    if(empty($data))
      $data = $c_data;
     
    return $data;
  }

It works fine, but maybe can be optimized. Every contribute will be appreciated
thks

Outcomes