Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
420 views
in Q2A Core by
I'm hoping that someone can help with this. Its just to complex for my brain to handle. I've managed to populate users table with a 'defaultcategory' column. I'd like to amend core so that when the user logs in, the go immediately to their default category. I'm OK with required SQL commands, but I can't work out which code to amend. Can someone please help! Many thanks - Melissa.
Q2A version: the latest

2 Answers

0 votes
by

You should look at Plugins instead of modifying the core. In particular, an Event Plugin would allow you to detect when a user logs in, then you can check their default category and should be able to redirect them.

What you have done with the database will probably work fine, but it's usually better for a plugin to create its own table. It can simply be a table of userid and defaultcategory.

+1 vote
by

Why don't you create a plugin as Scott says. Below logic may help you to get started with that.

Instead of adding a column to the user table, I would suggest to create a table user_category containing columns userid and default_categoryid than you may set userid as a primary key and set foreign key to the userid of the qa_users table using cascade.

Then you can use the event module in plugin to check if new user registered and assign a default category to the user by inserting row with value of userid and categoryid to the user_category table

With this you may not need to JOIN any table to get userid or categoryid since it is already in data. You may need to write few code to create new category (if needed) while checking the user register event.

Hope this will help you J

by
Thanks for the reply. I'm OK with the process behind populating the table/column with a default category for the user (as part of registration), but its more about how do I show the user logging in questions from their default category. I'll take a look at Scotts idea for an event plugin to see if I can work that out. My heads still hurting though! Mel.
by
I am sorry but bit confused. Do you mean to redirect logged in user to the specific category (defined for the user)?
...