Welcome, Guest
Username: Password: Remember me

TOPIC: User that loged in to see only info they submeted

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

  • pavelxp
  • pavelxp's Avatar
  • Offline
  • New Member
  • Posts: 5
  • Karma: 0
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.
The administrator has disabled public write access.

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

UP, having same problem. thanks!
The administrator has disabled public write access.

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

  • bmk028
  • bmk028's Avatar
  • Offline
  • New Member
  • Posts: 10
  • Thank you received: 4
  • Karma: 0
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 administrator has disabled public write access.
The following user(s) said Thank You: edwardcox

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
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
The administrator has disabled public write access.

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

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
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.
The administrator has disabled public write access.

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

  • bmk028
  • bmk028's Avatar
  • Offline
  • New Member
  • Posts: 10
  • Thank you received: 4
  • Karma: 0
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 administrator has disabled public write access.
The following user(s) said Thank You: BTB300

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

  • bmk028
  • bmk028's Avatar
  • Offline
  • New Member
  • Posts: 10
  • Thank you received: 4
  • Karma: 0
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 administrator has disabled public write access.
The following user(s) said Thank You: edwardcox
Time to create page: 0.066 seconds

Get Started