cancel
Showing results for 
Search instead for 
Did you mean: 

browse the alfresco repository 'windows style'

mmariotti
Champ in-the-making
Champ in-the-making
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
4 REPLIES 4

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

I've not had chance to try this, but it looks good.

If you're willing, I'll see if i can roll this into the PHP library as an example script.

Thanks for your efforts on this,
Roy

mmariotti
Champ in-the-making
Champ in-the-making
hi
sure.

here's the code to show the arraydata-result from the function  CreateTree()


class Common{
   public function ShowTree($contentdata)
  {
    echo "<ol>";
   
    foreach($contentdata as $content)
    {
      if($content['type'] == 'folder')
        echo "<li><img src='" . IMG_DIR . "/fold.gif'><a href='". BOOT_URL ."/view/index/id/" . $content['id'] . "'>" . $content['name']."</a></li>";
      else
        echo "<li><img src='" . IMG_DIR . "/post.gif'><a href='". BOOT_URL ."/view/index/url/" . str_replace("/","-.-",$content['id']) . "'>" . $content['name']."</a></li>";
   
      if($content['content'])
        $this->ShowTree($content['content']);
    echo "</ol>";
  }

}

….
….

<div id="left_menu">
       <?php
            echo "<ul>";
            foreach ($this->data_array as $data)
            {
              echo "<li>";
             
              if($data['type']=='folder')
                echo "<img src='" . IMG_DIR . "/fold.gif'><a href='". BOOT_URL ."/view/index/id/" . $data['id'] . "'>" . $data['name']."</a></li>";
              else
                echo "<img src='" . IMG_DIR . "/post.gif'><a href='". BOOT_URL ."/view/index/url/'" . str_replace("/","-.-",$data['id']) . "''>" . $data['name'] ."</a></li>";
             
              if($data['content'] && is_array($data['content']) && !empty($data['content']))
              {
                $common=new Common();
                $common->ShowTree($data['content']);
              }
            }
            echo "</ul>";
         ?>
</div>

cheers
mirko

rwetherall
Confirmed Champ
Confirmed Champ
Great .. ty Smiley Happy

hael
Champ in-the-making
Champ in-the-making
i tried it.
it works fine if you put  "}"  before echo "</ol>";