vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help: Time Var (Edit - Reputation Modify Not Working) (https://vborg.vbsupport.ru/showthread.php?t=193458)

Kiros72 10-12-2008 07:39 PM

Help: Time Var (Edit - Reputation Modify Not Working)
 
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 [DATE]1223915141[/DATE] at [TIME]1223915141[/TIME] ---------------

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 [DATE]1223918858[/DATE] at [TIME]1223918858[/TIME] ---------------

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.

PHP Code:

if ( $vbulletin->userinfo['usergroup'] == OR $vbulletin->userinfo['usergroup'] > )
{
    if (
TIMENOW $vbulletin->userinfo['lastrepadd'] >= 86400)
    {
        
$reputationlevel $db->query_first_slave("
            SELECT reputationlevelid
            FROM " 
TABLE_PREFIX "reputationlevel
            WHERE " 
$vbulletin->userinfo['reputation'] + " >= minimumreputation
            ORDER BY minimumreputation
            DESC LIMIT 1
        "
);

        
$userdata =& datamanager_init('User'$vbulletinERRTYPE_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.

PHP Code:

if ( $vbulletin->userinfo['usergroup'] == OR $vbulletin->userinfo['usergroup'] > 

    if (
TIMENOW $vbulletin->userinfo['lastrepadd'] >= 86400
    { 
        
$reputationlevel $db->query_first_slave(
            SELECT reputationlevelid 
            FROM " 
TABLE_PREFIX "reputationlevel 
            WHERE " 
$vbulletin->userinfo['reputation'] + " >= minimumreputation 
            ORDER BY minimumreputation 
            DESC LIMIT 1 
        "
); 

        
$userdata =& datamanager_init('User'$vbulletinERRTYPE_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:

PHP Code:

        '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
PHP Code:

        // time fields
        
foreach (array('joindate''lastvisit''lastactivity''lastrepadd') AS $datefield)
        {
            if (!isset(
$this->user["$datefield"]))
            {
                
$this->set($datefieldTIMENOW);
            }
        } 


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.


All times are GMT. The time now is 04:36 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01172 seconds
  • Memory Usage 1,761KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete