Get user's file set

Permalink
Hi all

I'm creating a file set when a user is created like this:

Events::extend('on_user_add', function($arg){
    FileSet::createAndGetSet($arg->uName, FileSet::TYPE_PUBLIC, $arg->uID);
});


The last argument is the user's ID, which makes them the owner of the file set. How do I then get all filesets that are owned by that user?

I've tried FileSet::getMySets($user_id) but that returns both the filesets owned by the user (which is what I want) and any public sets, which I don't want.

Is there any way to show only the sets owned by the user, ignoring the public ones? The getMySets method seems pretty useless if it includes public sets.

melat0nin
 
melat0nin replied on at Permalink Reply
melat0nin
I managed to do this by creating a new method in the file_set model:

/models/file_set.php

class FileSetList extends Concrete5_Model_FileSetList {}
class FileSet extends Concrete5_Model_FileSet {
    // Replacement getMySets which doesn't return public sets
    public function getUserSets($uid) {
        $db = Loader::db();
        $sets = array();
        $r = $db->Execute('select * from FileSets where uID = ? order by fsName asc', array($uid));
        while ($row = $r->FetchRow()) {
            $fs = new FileSet();
            $fs->Set($row);
            $fsp = new Permissions($fs);
            if ($fsp->canSearchFiles()) {
                $sets[] = $fs;
            }
        }


The database query just looks for filesets with the uID field the same as the passed user ID, so only sets belonging to them are returned.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.