Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » File upload quotas

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1238 Views
  • Motoma
    Avatar
    Community Member
    7 Posts

    File upload quotas Link to this post

    Hello all.

    I'm looking to implement quotas that are given to individual users at the group level. I'm hoping someone would have some insight into the intricacies of this task.

    My initial thoughts:

    Create a DataObjectDecorator to extend the Group class
    - Add a UserQuota field
    - Add a userQuota() method

    Create a DataObjectDecorator to extend the File class
    - Add a CreatedBy field

    Create a DataObjectDecorator to extend the Member class
    -Add a withinQuota() method

    My questions:
    Will an Extension to the File class be inherited by other classes? Namely the Image class?
    How can I set the CreatedBy field to the current user when files are uploaded?
    Additionally, file uploads will need to check the member's withinQuota() method, how can this be accomplished?
    Inside the withinQuota(), I will need to pull all Files owned by that user, how should this be done?

    Thank you in advance for any insight you can provide.

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: File upload quotas Link to this post

    Will an Extension to the File class be inherited by other classes? Namely the Image class?

    Yes I believe it should be as long as no methods / field names clash with ones in Image.

    How can I set the CreatedBy field to the current user when files are uploaded?

    Files already have a OwnerID field which stores the value of who uploaded the file. I'm guessing that is the same as want you want to do with CreatedBy so you probably don't need to add that field

    Additionally, file uploads will need to check the member's withinQuota() method, how can this be accomplished?

    You can set limits on a per filefield basis by setting setAllowedMaxFileSize(). Not completely sure how to set it globally, there must be a way to do so but I can't seem to find it. Using setAllowedMaxFileSize() however you could set it like

    $field->setAllowedMaxFileSize($member->withinQuota);

    Inside the withinQuota(), I will need to pull all Files owned by that user, how should this be done?

    Well because File has a OwnerID you can run a simple DataObject::get('File', "OwnerID = '$this->ID'"); which will return a set of files for that owner.

  • Motoma
    Avatar
    Community Member
    7 Posts

    Re: File upload quotas Link to this post

    Thank you for the excellent response Willr. I will get to work on this right now.

    1238 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.