Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

User that loged in to see only info they submeted 29 Feb 2012 23:05 #1485

I'm trying to have this component to submit personal info and be able to see it.
The problem I have is, any user can see this info. I want it to show user spastic. So if Tom is loges in I want hem to see only info he submitted.

Please Log in or Create an account to join the conversation.

Re: User that loged in to see only info they submeted 14 Mar 2012 07:48 #1595

UP, having same problem. thanks!

Please Log in or Create an account to join the conversation.

Re: User that loged in to see only info they submeted 17 Mar 2012 01:23 #1635

I have a number of tables that reference Joomla 'users' table and want all results to be filtered by user. What I did was:

1. Added new class under administrator/components/com_test/classes/ :

class UserAwareTestModelList extends TestModelList
{
/**
* Default implementation - ensures WHERE condition
* includes ' user_id = [id]' clause (assuming the field is named 'user_id')
*/
// @Override
function _buildQueryWhere($where = array())
{
$curUser = & JFactory::getUser();
$where[] = ' user_id = ' . $curUser->id;
return parent::_buildQueryWhere($where);
}
}

2. Changed all relevant model classes to extend this class:

...
class TestModelApples extends UserAwareTestModelList
...


Comments?

Michael
The following user(s) said Thank You: edwardcox

Please Log in or Create an account to join the conversation.

Re: User that loged in to see only info they submeted 18 Mar 2012 16:39 #1637

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Nice.

I didn't thought to use a Class extension to do this, and I recognize it is clever.

Only a comment :
What about administrator ?
Using this method should integrate the possibility to open access to the admin for example. (But it can be in back-end)

Thank you for your contribution.
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

Re: User that loged in to see only info they submeted 18 Mar 2012 22:30 #1638

Thank you Michael,

On behalf of myself and other J-Cook 'dummies' is there any possibility that, if you have time, you might show us a more complete example of how this is implemented and how it works? Unfortunately I am a PHP novice and can read the code just fine, but need to understand how to put this in to action.

Thank you once again, I've been searching for this functionality for so long.

Kind Regards,

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.

Please Log in or Create an account to join the conversation.

Re: User that loged in to see only info they submeted 19 Mar 2012 00:16 #1639

In my case admin should be able to see all records from all users, so administrator-side models keep extending TestModelList class. I am using text filter by username for admin to narrow the search if needed.
The following user(s) said Thank You: BTB300

Please Log in or Create an account to join the conversation.

Re: User that loged in to see only info they submeted 19 Mar 2012 00:28 #1640

There is not much to add actually. Create the new class, you can copy/paste the above example, just make sure you use the correct name for "user id" field (the one you used when building your table). Then open your model class (it will most likely be on "site" side, so something like <joomla root>/components/com_<yourcomponent>/models/<your_table_alias>.php), go to class declaration line and change the name of the class it extends to the name of the new class. Now, based on inheritance laws, whenever "_buildQueryWhere" is called, your new class will add "user id" clause to WHERE condition.

Hope this helps,

Michael
The following user(s) said Thank You: edwardcox

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.065 seconds

Let me first state that this is an amazing and fascinating product exactly what I was looking for. In just a few hours (listening to the very well made and clearly understandable videos learning doing) I completed and installed my first component. I am now in the second refining phase. I will make a recommenation in JED. Thanks for the effort in creating such a great product. Incidentally some of the best Joomla extension I use are of French origin !
Giori (Forum)

Get Started