1
DrSane
Hacking Extra DB Column
  • 2007/8/8 18:58

  • DrSane

  • Just popping in

  • Posts: 9

  • Since: 2007/8/8 1


I'm currently extending the xoop script to allow additional information to be stored for each user.

For example, I could have a "Profile Views" column for each user, that keeps track of how many times the profile has been viewed.

Initially, I was going to use a separate database all together for the additional data. But is there already support? I tried scanning the docs, but can not find anything.

Can someone give me a point in the right direction?

2
zyspec
Re: Hacking Extra DB Column
  • 2007/8/8 19:41

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


I'd recommend you look at some of the 'other' profile work that's already been done first - to see if any of what currently exists meets your needs.

You might start with SmartProfile and you could also follow this thread to see ongoing development of some hacks that might get you what you want when it's completed.

3
DrSane
Re: Hacking Extra DB Column
  • 2007/8/8 20:35

  • DrSane

  • Just popping in

  • Posts: 9

  • Since: 2007/8/8 1


Well, my profile example was just some random example I threw out there. Although it may be connected to how the user profile works, all I need to be able to do is add an extra field to the $thisUser / $xoopsUser object.

I guess I'll do some reading around the object.php code. Maybe I will find something there.

Edit:

I think I found it. "kernel/user.php".

It looks to me like I have to update the "insert" function and the "XoopsUser" function to handle the extra fields.

But as easy as this sounds, I think it's pretty dangerous. I don't want to try it. MySQL databases can't just suddenly gain an extra column, right? They have to be installed a certain way?

Any suggestions?

4
DrSane
Re: Hacking Extra DB Column
  • 2007/8/8 23:44

  • DrSane

  • Just popping in

  • Posts: 9

  • Since: 2007/8/8 1


Okay, I've decided it's too risky to add columns to the MySQL database.

I will just store the additional columns in text files, and handle them through methods in kernel/user.php.

5
iHackCode
Re: Hacking Extra DB Column

i think 'insert' is for the creation of new users.

i would create a new column/field with phpmyadmin w/ a set default value of zero. and then use the features of the XoopsUser class to retreive/increment the field.

an example: look in userinfo.php (retreiving data for that user)
$somevariable = $thisUser->getVar('field_name in the users table'); //$somevariable will be assigned the value in that field

and maybe add a method to the xoopsuser class to increment profile views..

userinfo.php (retriving data) and edituser.php (setting data) ..good examples on how XOOPS works.

and then maybe make it more modular and instead of constantly adding lines to you files when you want another field.you can just add a few include statement that run the selected functions so you don't have to worry about your modifications getting overwritten when you update the files.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

6
DrSane
Re: Hacking Extra DB Column
  • 2007/8/9 8:39

  • DrSane

  • Just popping in

  • Posts: 9

  • Since: 2007/8/8 1


That really wasn't at all what I was worried and or talking about. >_>

Regardless!

To anyone who happens to search for this thread, I found an answer! It was very simple. For example, if I wanted to add a new field for every user called "user_level", I would do the following:

mysql_query('ALTER TABLE xoops_users ADD user_level INT;');
return 
mysql_error();


I shoved that into some arbitrary core function that's accessed on a common page. Accessed the page. And then took the code out again.

Then I placed this snippet inside the "XoopsUser" function in "kernel/user.php".

$this->initVar('user_level'XOBJ_DTYPE_INTDEFAULT_LEVELfalse);


Instant extra column. What I was worried about was that this may create malformed MySQL queries for the insertion of new rows, but that is not the case.

Then the variable can be instantly accessed through "getVar('user_level')", without any additional preparation. It just defaults to DEFAULT_LEVEL. Surprisingly, no harm was done to the rest of the table.

7
iHackCode
Re: Hacking Extra DB Column

Quote:

DrSane wrote:
That really wasn't at all what I was worried and or talking about. >_>


ohh....
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

Login

Who's Online

364 user(s) are online (296 user(s) are browsing Support Forums)


Members: 0


Guests: 364


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits