예제 #1
0
파일: util.php 프로젝트: saintyk/yndl_2
function backtrack_recursive($cur_folder, $nodes = array(), $temp = array(), $cur_file = '')
{
    //get_node_path( $nodes ,  $cur_folder->id ,  $retv );
    //$folder_path =  $retv[0]['path'];
    //$folder_path = get_folder_path( $nodes , $cur_folder->id );
    get_folder_path($nodes, $cur_folder->id, array(), $folder_path);
    //debug( $folder_path );
    if (!empty($folder_path)) {
        //
        if (empty($temp) && $cur_file && $cur_file->folder_id == $cur_folder->id) {
            $temp = array('id' => $cur_file->id, 'name' => $cur_file->name . ' (' . count($cur_file->units) . ')', 'isParent' => count($cur_file->units) ? true : false, 'type' => 'file', 'icon' => get_path('/webroot/css/img/diy/3.png', true), 'children' => array());
        }
        $nodes = update_nodes($folder_path, $nodes, $temp);
    } else {
        // create folder
        $new_node = array('id' => $cur_folder->id, 'name' => $cur_folder->name, 'type' => 'folder', 'iconOpen' => get_path('/webroot/css/img/diy/folder-open.jpg'), 'iconClose' => get_path('/webroot/css/img/diy/folder-close.jpg'), 'children' => array());
        // append folder's file
        if ($cur_file) {
            $new_node['children'][$cur_file->id] = array('id' => $cur_file->id, 'name' => $cur_file->name . ' (' . count($cur_file->units) . ')', 'isParent' => count($cur_file->units) ? true : false, 'type' => 'file', 'icon' => get_path('/webroot/css/img/diy/3.png', true), 'children' => array());
        }
        if (!empty($temp)) {
            $new_node['children'][$temp['id']] = $temp;
            $temp = array();
        }
        // add new_node to nodes
        $nodes[$new_node['id']] = $new_node;
        // 递归
        $parent = $cur_folder->parent_folder;
        if ($parent) {
            $temp = $new_node;
            unset($nodes[$new_node['id']]);
            return backtrack_recursive($parent, $nodes, $temp);
        }
    }
    return $nodes;
}
예제 #2
0
파일: Files.php 프로젝트: saintyk/yndl_2
 function search_by_graphic_num($num)
 {
     $files = File::find('all', array('conditions' => array(" graphic_num LIKE '%{$num}%' "), 'order' => 'id desc'));
     $nodes = array();
     foreach ($files as $count => $file) {
         if (!$count) {
             $nodes = backtrack_recursive($file->folder, array(), array(), $file);
         } else {
             $nodes = backtrack_recursive($file->folder, $nodes, array(), $file);
         }
     }
     echo json_encode(strip_keys($nodes));
 }