php - virtual folders with mongoDB logic -


need bit of logic help. have folder i'll uploading alot of files via http/php/post. i'm going index them collection in mongodb when upload. need organize files different folders, in reality there no folders, when viewing interface i'll putting file tree. i'll setting permissions virtual folders. i've been thinking on , on of how index files virtual folders mongo collection, stuck assigning permissions each user. thinking of indexing file , virtual folders this(sorry long code, trying give idea of how deep file tree go):

$collection->insert(array(     '_id' => new mongoid(),     'type' => 'folder',     'folderorfilenameandlocation' => 'products' )); $collection->insert(array(     '_id' => new mongoid(),     'type' => 'folder',     'folderorfilenameandlocation' => 'products/device' )); $collection->insert(array(         '_id' => new mongoid(),         'type' => 'folder',         'folderorfilenameandlocation' => 'products/device/manuals'     ));  $collection->insert(array(         '_id' => new mongoid(),         'type' => 'file',         'filename' => 'themanual.pdf',         'location' => 'products/device/manuals/'     )); 

my problem how assign permissions folders each user when add user, here's thinking

$collection->insert(array(         '_id' => new mongoid(),         'username' => 'joe',         'password' => '1234', //will 1 way hashed         //store string         'permissiblefolders' => 'products/device/manuals/, software/latest/'     ));      //or should way???      $collection->insert(array(         '_id' => new mongoid(),         'username' => 'joe',         'password' => '1234', //will 1 way hashed         'permissiblefolders' => array(             //do have set key or can add them in?             products/device/manuals/,             software/latest/         )     )); 

now doing way, how query folders allocated user? thinking, how query last part? can make work nested query, that's try never do.

$pulleddata = $collection->find(array('username' => $username, 'password' => $password));         $doesexist = $pulleddata -> count();         if($doesexist == 1){             loguserinandstuff();             foreach($pulleddata $row){                 $accessiblefolders = $row['permissiblefolders'];             }             //how make query proper folders?             $pulleddata = $collection->find(array('foldernameandlocation'=>$accessiblefolders));          } 

sorry if logic stupid, have limited "pull" server , i'm allowed do. given nothing , expected pull through grand. better way of doing me come awesome! i'm pretty new nosql, maybe thinking structure lol.

why not add list of allowed users each file system object

adding permissions user easy

db.collection.update({folderorfilenameandlocation : 'products'}, {$push: {allowedusers: 'joe'}}) 

removing users easy

db.collection.update({folderorfilenameandlocation : 'products'}, {$pull: {allowedusers: 'joe'}}) 

checking permissions easy

db.collection.find({folderorfilenameandlocation : 'products', allowedusers : 'joe'}) 

and listing accessible user easy

db.collection.find({allowedusers: 'joe'}, {folderorfilenameandlocation: 1, _id: 0}) 

one thing might find helpful build out files , folders tree opposed having location string. you'll have

$collection->insert(array(     '_id' => new mongoid(),     'type' => 'folder',     'folderorfilename' => 'products' )); 

then create subfolder:

$collection->find(array('folderorfilename' => 'products')); $collection->insert(array(     '_id' => new mongoid(),     'type' => 'folder',     'folderorfilename' => 'device',     'parent' => $collection['_id'] )); 

there pluses , minuses structure; depending on else need support might find way or tree way easier. recommend assigning user names folders instead of vice versa.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -