1
shibiru_mato
getting values from xoops "users" table

Hi

i would like to make some of the users information private on users profile. currently we can make email addresses private by unchecking the checkbox. the same thing i would like to do with other personal information such as telephone and address.

I added a column in "users" table called "user_viewtel" for making telephone number private and made it NOT NULL with default value of 1(for make public)

I tried editing the user_edituser.html and tried accessing the value of the "user_viewtel" by using codes like
$thisUser->getShow('user_viewtel') and $actionForm->get('user_viewtel') but it doesnt display anything

can anybody have idea what other things i can do so i can access the new field on the page?

any help would be very appreciated

2
zyspec
Re: getting values from xoops "users" table
  • 2012/9/28 16:16

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


I'm not sure where you created the telephone value (was this using profile?). But to answer your specific question.

1) You need to add the 'user_viewtel' as a variable in the XoopsUser class (see ./kernel/user.php) starting at line 59. You'll want to add:

$this->initVar('user_viewtel'XOBJ_DTYPE_INT1false);


You can add it anywhere between lines 59 - 90 but I'd probably put it just after the initialization for the 'user_viewemail' variable.

Then to retrieve the value from the database you'll use:

$thisUser->getVar('user_viewtel');


Similarly when you want to set the value in the XoopsUser class object to whatever is contained in $value, you would using something like:

$thisUser->setVar('user_viewtel'$value);


Doing this will probably require that you change forms, etc... too. This hack will also have to be re-applied if you ever upgrade your XOOPS installation. There's probably a better way to handle this than hacking core files.

3
shibiru_mato
Re: getting values from xoops "users" table

yeah i added another column on users table to toggle whether to show or not the telephone number... just like what is happening on email field. and yes I want to add it on edit profile... when viewing profiles i would read this value to see if it is public or not, if its not public then i would not display it.

so i need to edit the core files right? as of now i only have access on the editing templates on the admin menu... so i needed to go to the file directly right?

anyway, i greatly appreciate your help man! thank you! i will definitely try this and inform you if it did well

4
shibiru_mato
Re: getting values from xoops "users" table

hi zyspec,

i tried editing the /html/xoops/kernel/user.php and added the $this->initVar('user_viewtel', XOBJ_DTYPE_INT, 1, false); just as you said but i cant get the value still. to make things weird.... i made some experiment and edited the file like renaming the valid rows like 'user_viewemail' to 'user_viewemailtest' and i should expect that i cant get that value to the database on the user_editinfo.php but to my surprise, i can get the value of 'user_viewemail' though i renamed all of the appearances of that word on the file... so do you think i need to restart the server or what im doing is wrong?

5
kerkyra
Re: getting values from xoops "users" table
  • 2012/10/11 13:58

  • kerkyra

  • Just can't stay away

  • Posts: 553

  • Since: 2005/2/14


for the user manipulation php-side you can create a new user class to extend the core user class.

this is part of something i have done to correct the avatar location issue with newer versions of xoops

I added your var in there so you could try it out of the box. Hopefully.

Quote:

include_once $GLOBALS['xoops']->path('kernel/user.php');


class myUser extends XoopsUser
{

private $db;
private $id;
function __construct($id=null)
{
parent::__construct($id);
$this->initVar('user_viewtel', XOBJ_DTYPE_INT, 1, false);


if($id>0)
{
$this->id = $id;


if(file_exists(XOOPS_ROOT_PATH."/uploads/".$this->getVar('user_avatar')))
$avatar="/uploads/".$this->getVar("user_avatar");
else
$avatar="/uploads/avatars/".$this->getVar("user_avatar");

$this->setVar('user_avatar',$avatar);

$this->db = Database::getInstance();


}
}



}


If you need new fields I would suggest creating a new table and store them in there seperatelly from xoops core db tables.

Then extend the class to store the extra values with a new method in it.

Make that a small module (just for the sake of neatness) or implement it in your module, and you dont have to worry about messing with the core :) hope it helps

6
shibiru_mato
Re: getting values from xoops "users" table

thank you this is very interesting.

however, i am a newbee in php, xoops and module creation. but i want to consider this. how about the usage of this class? if i want to use this on user_editprofile.php how can i get and set the values? is it the same? and more importantly, do i need to restart the server to apply this new class?

thank you again

7
shibiru_mato
Re: getting values from xoops "users" table

hi zyspec,

i tried editing the /html/xoops/kernel/user.php and added the $this->initVar('user_viewtel', XOBJ_DTYPE_INT, 1, false); just as you said but i cant get the value still. to make things weird.... i made some experiment and edited the file like renaming the valid rows like 'user_viewemail' to 'user_viewemailtest' and i should expect that i cant get that value to the database on the user_editinfo.php but to my surprise, i can get the value of 'user_viewemail' though i renamed all of the appearances of that word on the file... so do you think i need to restart the server or what im doing is wrong?

Login

Who's Online

194 user(s) are online (31 user(s) are browsing Support Forums)


Members: 0


Guests: 194


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