Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Allow only one use of a module per period of time

Allow only one use of a module per period of time

Hello,
I am setting up a photo contest with FW Gallery. I am using Easy File Uploader to allow participants to upload their pictures. What I'd like to do is the following with MetaMod: the Easy File Uploader should allow only 3 uploads per month per user. A single user should be able to upload only 3 pictures per month. I have no idea on PHP coding, so detailed help will be really useful.
Thanks,

Dani

acrocephalus
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Allow only one use of a module per period of time

Hi Dani,

That's quite a challenge, and not something I would normally recommend MetaMod to solve. However I guess it's theoretically possible for MetaMod to count the number of uploads that a user has done in the current month, then control whether or not the module for uploading gets displayed for that user.

So you would need to set up the uploader to upload files to folders named with the username, so they can be associated with that person.

Then something like this might work, assuming you want to allow a maximum of 3 uploads in any calendar month (i.e. since midnight at the start of the 1st day of the current month), for any user:

$thismonth = strtotime("first day of 00:00");
if (!$user->guest) {
  $dir = JPATH_SITE . "/path/to/user/folders/here/" . $user->username; // <== edit path here!
  $count = 0;
  if ($handle = opendir($dir)) {
    while (( $file = readdir($handle)) !== false ) {
      if ( $file == '.' || $file == '..' || is_dir($dir.'/'.$file) ) {
        continue;
      }
      if ( filemtime( $dir.'/'.$file ) > $thismonth ) {
        $count++;
      }
    }
    closedir($handle);
  }
  if ($count < 3) return XXX;
  // replace XXX with the module id of the uploader module.
}


Note that the path to the user folders has got to be to the folder that encloses the user folders.

e.g. if you have folders for the easy file uploader set up like this:
/home/mysite/www/userfolders/bob/image1.jpg
/home/mysite/www/userfolders/mary/image1.jpg
/home/mysite/www/userfolders/karen/image1.jpg

then the line in the PHP above should be:
  $dir = JPATH_SITE . "/userfolders/" . $user->username;

I hope that helps (and works!)
Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
8
User Info:
 
Total Users:
5378
Newest User:
gary9131
Members Online:
0
Guests Online:
169

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked