Having a hard time with a File Up/Download Single Page

Permalink
I'm still a newb, with limited PHP experience... so please bear with me!

I'm trying to create a login page with a list of files (from a particular set) to download. Ultimately, then, there should also be the "add a file" function where any files uploaded will be added to the file set specified in the File Manager (being available to administrators, and also available on that same page for downloading.)

I'm using the 'Document Library' add-on, and have hit a brick wall on implementing this.

First, I'm using the following code on my single_page.php:
$bt_main = BlockType::getByHandle('document_library'); 
 $bt_main->controller->displayLimit=20;
 $bt_main->controller->font_face='inherit';
 $bt_main->controller->font_size='inherit';
 $bt_main->controller->header_background_color = '#eeeeee';
 $bt_main->controller->header_font_color = '#333333';
 $bt_main->controller->even_bg_color = '#fafafa';
 $bt_main->controller->odd_bg_color = '#ffffff';
 $bt_main->controller->overlay_bg_color = '#ffffff';
 $bt_main->controller->even_font_color = '#333333';
 $bt_main->controller->odd_font_color = '#333333';
 $bt_main->controller->overlay_font_color = '#333333';
 $bt_main->controller->alternate_rows=1;
 $bt_main->controller->maxThumbWidth=100;
 $bt_main->controller->maxThumbHeight=150;

Unfortunately, I don't know how to specify the specific file set for the files that are available. Can anyone tell me how to add that in there, for the controller to do that?

I would like it, though, to recognize the user, determine what file set they have permission to read and write to, and ONLY display those!

Can anyone give me some direction? Thanks!

dihakz
 
johndorsay replied on at Permalink Reply
johndorsay
Here is the code for getting a fileset to display

$fileSetSelected = 'some_fileset_name';
if ($fileSetSelected == true) {
   Loader::model('file_list');
   Loader::model('file_set');
   $fs = FileSet::getByName($c->getAttribute('fileset_selected'));
   $fileList = new FileList();  
   $fileList->filterBySet($fs);
   $files = $fileList->get(20,0);
   foreach ($files as $f) {
      //print_r($f);
      // i'm creating 3 array sets, but you'll only really need the $mediaPath array
      $mediaExt[] = $f->getExtension();
      $mediaPath[] = $f->getRelativePath();
      $mediaAttribute[] = $f->getAttribute('file_rating');
   }


Now for the which filesets the user can access, you'll need another page to view and associate the sets to the user.

Hope this gets you started!
ryan replied on at Permalink Reply
ryan
Here's a thought on how you might approach modifying the document library to show files for only the current user:


Extend the FileList class:

Create a new file: /models/user_file_list.php
Loader::model('file_list');
class UserFileList extends FileList {
  public function filterByAuthorUID($uID) {
   $this->filter('fv.fvAuthorUID', $uID, '=');
  }
}


Then in the document library block's controller.php file on line 181 where it creates the new FileList Object:

Loader::model('user_file_list');
$fileList = new UserFileList();
$u = new User();
$fileList->filterByAuthorUID($u->getUserID());


Then you'd essentially have a personal document library
dihakz replied on at Permalink Reply
dihakz
Ok, this works. However, it only outputs the files the user "owns" (that is, files they themselves have uploaded.)

That is all well and good -- however, administrators will want to supply files TO the users, and be seen ONLY by those users!

So, I do need it to be based on fileset, and not by files "owned" by the user. Any ideas?
dihakz replied on at Permalink Reply
dihakz
From what I can tell, this function does exist... I just don't know how to code a function (like you did, here, for filtering by user file list) that will return the user's file *set*.

Do you have any suggestions?