Welcome, Guest
Username: Password: Remember me

TOPIC: Frontend grid to only show my records

Frontend grid to only show my records 20 Nov 2012 13:45 #5500

  • nvgogh
  • nvgogh's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 2
  • Karma: 0
Hey

Maybe a newby question

I have a frontend grid and I only want to show the records of the person logged in (and a controller person must see all records)

I have the published and authorised fields in there but the grid didn't show my rows

When I checked what the ACL was (by doing a dump of acl) I saw that I didn't have any rights (the whole acl array contained the rights but no values were assigned)

Can you set rights on frontend grids/lists?

If so, where?

Thanks in advance!!!

Natalie
The administrator has disabled public write access.

Re: Frontend grid to only show my records 20 Nov 2012 14:33 #5503

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Natalie,

It's been discussed a few times before to meet slightly different requirements to one another so these posts should be a good start:
  1. www.j-cook.pro/forum/7-design-your-appli...ecords-without-admin
  2. www.j-cook.pro/forum/9-coding-inside-you...s-from-the-front-end
The key is in the inclusion of author wizards which I believe from your post you have instanced on the table.nvgogh wrote:
When I checked what the ACL was (by doing a dump of acl) I saw that I didn't have any rights (the whole acl array contained the rights but no values were assigned)
The ACL is set in the configuration tab of your component (options button). There's an example o the ACL config to achieve this in the first linked thread above.

Regarding the publishing wizard, you only really need this if you require 'public' viewing of the records to be switchable.

The one way to achieve this would be by adding an explicit where clause in your prepareQuery() function of the concerned model to only return records where $user_id = a.author (where a is the alias of your table in the query).

Hope it helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
The following user(s) said Thank You: nvgogh

Re: Frontend grid to only show my records 20 Nov 2012 14:40 #5504

  • nvgogh
  • nvgogh's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 2
  • Karma: 0
I was overthinking the issue and it must be something I missed. I will review the forum items you mention and look at the setup again.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Frontend grid to only show my records 20 Nov 2012 14:41 #5505

  • smarano
  • smarano's Avatar
  • Offline
  • Junior Member
  • Posts: 33
  • Thank you received: 1
  • Karma: 1
for allowing a user logged in to see their records you need to add a where condition to the query.

Add in "com_***t\site\models\****.php" in prepareQuery() function the condition:
// Filter by user logged
$where[] = "a.created_by = ". (int)JFactory::getUser()->get('id');
Last Edit: 20 Nov 2012 14:44 by smarano.
The administrator has disabled public write access.

Re: Frontend grid to only show my records 20 Nov 2012 14:48 #5507

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Don't be hard on yourself! ;) There are lots of things to think about when cooking - so many ingredients!

@smarano k+1 - yes this is precisely what I meant in:audibleid wrote:
The one way to achieve this would be by adding an explicit where clause in your prepareQuery() function of the concerned model to only return records where $user_id = a.author (where a is the alias of your table in the query).

hope you find the right recipe!

Gez

PS. Please post back any issues if you have any!
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Frontend grid to only show my records 20 Nov 2012 20:37 #5518

  • nvgogh
  • nvgogh's Avatar
  • Offline
  • Junior Member
  • Posts: 22
  • Thank you received: 2
  • Karma: 0
I continued the question in this thread

What it comes down to is that I am puzzled why the $acl is empty for a (non super/root) user when using the model in the frontend. If the $acl was correctly filled then the functionality would work flawlessly.
The administrator has disabled public write access.

Re: Frontend grid to only show my records 23 Dec 2012 03:21 #6256

thanks for this thread
Last Edit: 23 Dec 2012 04:05 by jasonsevilla.
The administrator has disabled public write access.

Re: Frontend grid to only show my records 27 Dec 2012 02:16 #6284

Please help where to add
// Filter by user logged
$where[] = "a.created_by = ". (int)JFactory::getUser()->get('id');

on my code
	/**
	* Preparation of the list query.
	*
	* @access	protected
	* @param	object	&$query	returns a filled query object.
	* @return	void
	*/
	protected function prepareQuery(&$query)
	{
		$user = JFactory::getUser();
		$acl = EjuiceHelper::getActions();

		//FROM : Main table
		$query->from('#__ejuice_userprodreg AS a');



		//IMPORTANT REQUIRED FIELDS
		$this->addSelect(	'a.id,'
						.	'a.access,'
						.	'a.created_by');

		switch($this->getState('context'))
		{
			case 'userprodreg.default':

				//BASE FIELDS
				$this->addSelect(	'a.active,'
								.	'a.date_created,'
								.	'a.flavor_name,'
								.	'a.product_code');

				//SELECT
				$this->addSelect('_created_by_.name AS `_created_by_name`');
				$this->addSelect('_flavor_name_.flavor_name AS `_flavor_name_flavor_name`');

				//JOIN
				$this->addJoin('`#__users` AS _created_by_ ON _created_by_.id = a.created_by', 'LEFT');
				$this->addJoin('`#__ejuice_flavorlist` AS _flavor_name_ ON _flavor_name_.id = a.flavor_name', 'LEFT');

				break;
			default:
				//SELECT : raw complete query without joins
				$this->addSelect('a.*');

				// Disable the pagination
				$this->setState('list.limit', null);
				$this->setState('list.start', null);
				break;
		}

		//WHERE - FILTER : Flavor Name
		if($this->getState('filter.flavor_name') != null)
			$this->addWhere('a.flavor_name = '. (int)$this->getState('filter.flavor_name'));

		// WHERE : Implement View Level Access
		if (!$acl->get('core.admin'))
		{
		    $groups	= implode(',', $user->getAuthorisedViewLevels());
			$query->where('a.access IN ('.$groups.')');
		}

		//Populate only uniques strings to the query
		//SELECT
		foreach($this->getState('query.select', array()) as $select)
			$query->select($select);

		//JOIN
		foreach($this->getState('query.join.left', array()) as $join)
			$query->join('LEFT', $join);

		//WHERE
		foreach($this->getState('query.where', array()) as $where)
			$query->where($where);

		//ORDER
		foreach($this->getState('query.groupby', array()) as $groupby)
			$query->order($groupby);

		//ORDER
		foreach($this->getState('query.order', array()) as $order)
			$query->order($order);

		//ORDER
		$orderCol = $this->getState('list.ordering');
		$orderDir = $this->getState('list.direction', 'asc');

		if ($orderCol)
			$query->order($orderCol . ' ' . $orderDir);
	}


}

I was able to make this work on Cook 1.5.. but I cant figure it out on cook 2.0

Thanks
Last Edit: 27 Dec 2012 02:18 by jasonsevilla.
The administrator has disabled public write access.

Re: Frontend grid to only show my records 27 Dec 2012 15:00 #6293

Found Solution
On prepareQuery(&$query)

find code
		//WHERE
		foreach($this->getState('query.where', array()) as $where)
			$query->where($where);
and add below it
                $query->where ("a.created_by = ". (int)JFactory::getUser()->get('id'));
Last Edit: 27 Dec 2012 15:01 by jasonsevilla.
The administrator has disabled public write access.
Time to create page: 0.125 seconds

Get Started