Example #1
0
 /**
  * layout sub-level of tree hierarchy
  * with a recursive search
  * 
  * @param object $entity an containning anchor (section or category)
  */
 private function get_sub_level($entity, $no_folders = false)
 {
     // we return a string
     $sub = '';
     // data of subelements of this entity
     $data = array();
     // html formated sub elements
     $details = array();
     if (!$no_folders) {
         $sub .= "\n" . '<ul class="tm-sub_elems">' . "\n";
     }
     $class = $this->listed_type;
     if (!$no_folders) {
         // look for sub-containers, should be either categories or sections
         $data = $entity->get_childs($class, 0, TM_MAX_ITEM, 'raw');
         // layout hierarchy
         if (isset($data[$class])) {
             foreach ($data[$class] as $elem) {
                 // transform data to obj interface
                 $elem = new $class($elem);
                 // go deeper in tree hierarchy with a recursive call
                 $deeper = $this->get_sub_level($elem);
                 // build commands menu
                 $cmd = $this->get_interactive_menu();
                 // layout sub container
                 $details[] = '<li class="tm-drag tm-drop" data-ref="' . $elem->get_reference() . '"><a class="tm-zoom" href="' . $elem->get_permalink() . '">' . '<span class="tm-folder">' . $elem->get_title() . '</span></a>' . "\n" . $cmd . $deeper . '</li>';
             }
         }
     }
     // look for section as pages, but only for categories browsing
     if ($this->listed_type == 'category' && !$this->tree_only) {
         $data = $entity->get_childs('section', 0, TM_MAX_ITEM, 'raw');
         // layout sections
         if (isset($data['section'])) {
             foreach ($data['section'] as $sec) {
                 // transform data to obj interface
                 $sec = new Section($sec);
                 // build commands menu
                 $cmd = $this->btn_delete();
                 $cmd = $this->build_menu($cmd);
                 // layout articles
                 $details[] = '<li class="tm-drag" data-ref="' . $sec->get_reference() . '"><a href="' . $sec->get_permalink() . '" class="tm-page details">' . $sec->get_title() . '</a>' . $cmd . '</li>';
             }
         }
     }
     // look for articles and users of this level
     if (!$this->tree_only) {
         $data = $entity->get_childs('article, user', 0, TM_MAX_ITEM, 'raw');
         // layout articles
         if (isset($data['article'])) {
             foreach ($data['article'] as $art) {
                 // transform data to obj interface
                 $art = new Article($art);
                 // build commands menu
                 $cmd = $this->btn_delete();
                 $cmd = $this->build_menu($cmd);
                 // layout articles
                 $details[] = '<li class="tm-drag" data-ref="' . $art->get_reference() . '"><a href="' . $art->get_permalink() . '" class="tm-page details">' . $art->get_title() . '</a>' . $cmd . '</li>';
             }
         }
         // layout users
         if (isset($data['user'])) {
             foreach ($data['user'] as $usr) {
                 // transform data to obj interface
                 $usr = new User($usr);
                 // build commands menu
                 $cmd = $this->btn_delete();
                 $cmd = $this->build_menu($cmd);
                 // layout articles
                 $details[] = '<li class="tm-drag" data-ref="' . $usr->get_reference() . '"><a href="' . $usr->get_permalink() . '"class ="tm-user details">' . $usr->get_title() . '</a>' . $cmd . '</li>';
             }
         }
     }
     // combine all sub elements
     if (count($details)) {
         $sub .= implode("\n", $details);
     }
     if (!$no_folders) {
         $sub .= '</ul>' . "\n";
     }
     return $sub;
 }