Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Allow only one use of a module per...
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
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
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Allow only one use of a module per...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 1
- User Info:
- Total Users:
- 7667
- Newest User:
- humble2601
- Members Online:
- 0
- Guests Online:
- 94
- 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