Jump to content

Recommended Posts

Hey all... I am working on a little script in Joomla that will allow users to submit 10 articles every 30 days. I have successfully created the part that increments the user's amount of posts after submission and check them before the submission page loads, but I am currently unable to think of a way to get the value to reset every thirty days. I am stumped, but I believe the key lies in the fact that their date of registration is in the database. I'm just new to programming and can't think of how to use this data.

 

Thanks for the help

If you record the datetime of submission (with each submission, which you probably already do), rather than attempt to keep a count, you can simply do a query that counts the number of submissions over a datetime range that you pick.

Thanks for the reply... this always seems to happen, but in the time that I was waiting I came up with a great working solution. For posterity's sake, here it is:

 


// Getting Current User ID
$user =& JFactory::getUser();
$usr_id = $user->get('id');
// dbg: echo $usr_id;


$query = "SELECT * FROM jos_users WHERE id='$usr_id'";
$result = mysql_query($query) or die ("Could not execute query.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
extract($row);

$strRegDate = strtotime ($registerDate);
$strCheckDate = strtotime ($checkdate);
$todayDate = date("Y-m-d");
$strTodayDate = strtotime ($todayDate);

/* DEBUG CODE
$strTodayDate = strtotime("March 28 2010");
echo $strRegDate . '<br />';
echo $todayDate . '<br />';
echo $strTodayDate . '<br />';
echo $strCheckDate . '<br />';
*/

// TESTS BEGIN

if($strCheckDate == '18000') {
// make checkDate in db == regDate + 1 month
$tempStrDate = strtotime ( '+1 month' , $strRegDate ) ;
$updateDate = date ( 'Y-m-j' , $tempStrDate );
// write it to the database
$query_update = "UPDATE jos_users SET checkdate='$updateDate' WHERE id='$usr_id'"; 
mysql_query($query_update) or die ("Could not execute query.");
}
else if($strTodayDate > $strCheckDate) {
// make checkDate in db == checkDate + 1 month
$tempStrDate = strtotime ( '+1 month' , $strCheckDate ) ;
$updateDate = date ( 'Y-m-j' , $tempStrDate );
// reset submissions to zero (UPDATE)
$query_update = "UPDATE jos_users SET checkdate='$updateDate', submissions='0'  WHERE id='$usr_id'";
// write it to the database
mysql_query($query_update) or die ("Could not execute query.");
// dbg: echo "today was later than checkDate";
// dbg: echo $submissions;
}


// Defining SQL query for testing submission vs submitlimit
$query = "SELECT * FROM jos_users WHERE id='$usr_id'";

// Storing query into result variable
$result = mysql_query($query) or die ("Could not execute query.");

// Dropping returned data into array
$row = mysql_fetch_array($result,MYSQL_ASSOC);

// Extracting data into variables that have the same name as the key
extract($row);

// Performing test
if($submissions >= $submitlimit) {
die ('Sorry! You are over your quota for submissions this month. Please return to <a href="http://testbed.delabelled.com/">IKIT Home Page.</a>');
}	

 

Basically, I made a DATETIME and set it to default as 1970-01-01, which converts to 18000 with strtotime. Then it updates that entry to the registration date plus one month if it is still set to 18000. If today's date is greater than the date of checkDate in the db, it adds another month and stores that value back, and also resets the submission count.

 

I just started PHP yesterday, so this may not be the best method and please criticize as you see fit - I am eager to learn correct coding practice.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.