SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    find if a folder belongs to other

    I want to make a function that check the permisions at a folder of a user.
    That means that this folder must be a subfolder of the default (from db) folder that belongs to user.
    Is there a simpler method than making a loop at subfolders of 'default' folder?

  2. #2
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are these folders nested?! In a database you can have a flat layout. But through recursion, pad this out to give the impression of nested folders. Checking permissions is easy, just add a permission column in.

    PHP Code:
    function printParentFolders(){
            
    $folders selectAssocQuery("SELECT * FROM `folders` WHERE ...");
            foreach(
    $folders as $folder){
                    
    $currentParent $folder;
                    
    $currentPath '/'.$currentParent['PNAME'];
                    if(
    $currentParent['PPARENT']==0){
                            echo 
    '<div tier="1"><div>'.$currentParent['PNAME'].'</div></div>';
                            
    printChildFolders($currentParent,$folders,$currentPath,2);
                            echo 
    '</div>';
                    }
            }
            unset(
    $folders);
    }

    function 
    printChildFolders($currentParent,$folders,$currentPath,$currentTier){
            global 
    $visibleTierLevel;
            
    $display 'none';
            if(
    $currentTier<=$visibleTierLevel){
                    
    $display 'block';
            }
            foreach(
    $folders as $folder){
                    if(
    $currentParent['PID']==$folder['PPARENT']){
                            
    $tPath $currentPath;
                            
    $currentPath .= '/'.$folder['PNAME'];
                            echo 
    '<div class="menuItemContainer" style="display:'.$display.'" tier="'.$currentTier.'"><div>'.$folder['PNAME'].'</div></div>';
                            
    printChildFolders($folder,$folders,$currentPath,($currentTier+1));
                            echo 
    '</div>';
                            
    $currentPath $tPath;
                    }
            }

    The MySQL query used, the assoc stuff is from:

    http://www.openzu.com/Code-Samples/P...-Queries/p-18/

    Hope that helps,


    C.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •