View Full Version : Help: Time Var (Edit - Reputation Modify Not Working)
Kiros72
10-12-2008, 07:39 PM
I would like to add a variable to the $userinfo array within $vbulletin. For reference, the variable would probably be called $lastmodify (i.e. $vbulletin->userinfo['lastmodify']).
This variable would be just like $lastvisit or $lastactivity (an integer that holds a time).
I know that I would put this in the physical files. What I don't know is how I would go about setting and checking it.
See, I want vBulletin to add something to a user every 24 hours if they are logged in (or if they login 24 hours after the last time something was added). So that's why I need to add this additional variable - to define the last time that their account was modified.
Refer to next post for problem vvv
Thanks in advance :)
--------------- Added 1223915141 at 1223915141 ---------------
I've gotten the time thing worked out, I believe. I added the new variable to the $userinfo array, but it's not working. I'm thinking that this might be because it's in the PHP files but it's not in the user table in the SQL database.
I'm not quite sure how to create another row in the MySQL database that is similar to lastvisit. I've checked out the Insert option in phpMyAdmin, but that's just becoming confusing. Can anyone give me some basic instruction?
Guest190829
10-13-2008, 03:48 PM
I'm not sure exactly what you are trying to do, but you need to add another column to the usertable to store this new variable. Then you need to work out how to update the value and when.
Kiros72
10-13-2008, 03:57 PM
Thanks for the response!
I've worked out how to update the variable, but it hasn't been updating because it wasn't in the database. I thought that what I needed was a new row, not a new column. Aren't lastvisit and lastactivity rows? If so, then I need a new row, because I need to store a time like those values. I wouldn't know how to add a row - if it is a row. Hopefully, I've just got the two terms confused.
--------------- Added 1223918858 at 1223918858 ---------------
Well, I managed to figure out how to just add a row. I added the row lastrepadd to the user table. It has the properties of the other time variables, like lastvisit.
This is the PHP code that I've got planted in the index.php file. I can't figure out why it's not working.
if ( $vbulletin->userinfo['usergroup'] == 2 OR $vbulletin->userinfo['usergroup'] > 3 )
{
if (TIMENOW - $vbulletin->userinfo['lastrepadd'] >= 86400)
{
$reputationlevel = $db->query_first_slave("
SELECT reputationlevelid
FROM " . TABLE_PREFIX . "reputationlevel
WHERE " . $vbulletin->userinfo['reputation'] + 1 . " >= minimumreputation
ORDER BY minimumreputation
DESC LIMIT 1
");
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('lastrepadd', TIMENOW);
$userdata->set('reputation', $vbulletin->userinfo['reputation'] + 1);
$userdata->set('reputationlevelid', intval($reputationlevel['reputationlevelid']));
$userdata->save();
}
}
What I'm trying to do with this is give a user 1 reputation point every day as long as they login (or are already logged in and just visit). Any ideas as to why this isn't working?
Marco van Herwaarden
10-14-2008, 07:40 AM
Column = a field in a table
Row = is a record (row) in a table.
Kiros72
10-15-2008, 04:02 AM
Yeah, that's what I thought, but now I have a new problem. I made the new row and everything, but it's not really saving... Here's the PHP code I put in the index.php.
if ( $vbulletin->userinfo['usergroup'] == 2 OR $vbulletin->userinfo['usergroup'] > 3 )
{
if (TIMENOW - $vbulletin->userinfo['lastrepadd'] >= 86400)
{
$reputationlevel = $db->query_first_slave("
SELECT reputationlevelid
FROM " . TABLE_PREFIX . "reputationlevel
WHERE " . $vbulletin->userinfo['reputation'] + 1 . " >= minimumreputation
ORDER BY minimumreputation
DESC LIMIT 1
");
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('lastrepadd', TIMENOW);
$userdata->set('reputation', $vbulletin->userinfo['reputation'] + 1);
$userdata->set('reputationlevelid', intval($reputationlevel['reputationlevelid']));
$userdata->save();
}
}
I have added lastrepadd to the $userinfo array. I added a row in the vb_user table called lastrepadd. Why isn't that saving the lastrepadd variable? What am I doing wrong?
Guest190829
10-15-2008, 04:04 AM
Have you added the lastrepadd to the datamanager? It won't allow you to save unless you do so.
Kiros72
10-15-2008, 04:18 AM
Yes, here's the little bit that I added it in:
'joindate' => array(TYPE_UNIXTIME, REQ_AUTO),
'lastvisit' => array(TYPE_UNIXTIME, REQ_NO),
'lastactivity' => array(TYPE_UNIXTIME, REQ_NO),
'lastrepadd' => array(TYPE_UNIXTIME, REQ_NO),
'lastpost' => array(TYPE_UNIXTIME, REQ_NO),
'lastpostid' => array(TYPE_UINT, REQ_NO)
.....
and
// time fields
foreach (array('joindate', 'lastvisit', 'lastactivity', 'lastrepadd') AS $datefield)
{
if (!isset($this->user["$datefield"]))
{
$this->set($datefield, TIMENOW);
}
}
Guest190829
10-15-2008, 04:35 AM
Okay, do a pre_save() check with the manager and see if there are errors popping up.
Marco van Herwaarden
10-15-2008, 08:00 AM
You should not edit any files to add a field to the allowed fields list.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.