As usual, I was forgetting basic stuff. Notably the 'joins' option.
Also, in my confused pecking away at this, I was trying to join the
Aro also, but that query couldn't work (this was just the latest of
various things I'd tried). Here's how I got it to work after the clue
fairy dropped in:
groups controller:
$group_aro = $this->Acl->Aro->find(
'first',
array(
'conditions' => array(
'model' => 'Group',
'foreign_key' => $group_id
),
'recursive' => -1
)
);
$volume_nodes =
ClassRegistry::init('Volume')->threadedWithGroupPerms($group_aro['Aro']['foreign_key']);
Volume.php:
public function threadedWithGroupPerms($group_aro_id)
{
return $this->find(
'threaded',
array(
'recursive' => 1,
'fields' => array('*'),
'joins' => array(
array(
'table' => 'acos',
'alias' => 'Aco',
'type' => 'inner',
'conditions'=> array(
'Aco.model' => 'Volume',
'Aco.foreign_key = Volume.id'
)
),
array(
'table' => 'aros_acos',
'alias' => 'Permission',
'type' => 'inner',
'conditions'=> array(
'Permission.aco_id = Aco.id',
"Permission.aro_id =
${group_aro_id}"
)
)
)
)
);
}
This works great. I now have a nicely-formatted Volume tree (a
thousand thank-yous to ad7six for the TreeHelper, which is far better
than my own pokey version) that includes the Group's permissions for
each.
As I said earlier, this is for an admin view, and won't be seeing a
lot of action, so I'm not very concerned about performance. It works a
treat, in any case. The entire Volume tree is displayed, with controls
for grant/deny. My app only requires Acl betwen these 2 Models, so
this is probably sufficient for my needs, but this could probably be
abstracted somewhat.
On Mon, Apr 6, 2009 at 11:32 PM, brian <[email protected]> wrote:
> I have a model, Volume, for which I want to limit access from Group,
> using record-level ACL. Volume is also stored using MPTT
> (TreeBehavior). So far, I've been able to create the entries in aros,
> acos, & aros_acos.
>
> Now, what I need to do is figure out a way to display the Volume tree
> (easy) but, along with the Volume threaded data, fetch each Volume's
> permissions wrt a specific Group. This is so that an admin can see at
> a glance which Volumes a Group has access to by queerying against a
> specific Group. I plan on using this tree to grant/deny access.
>
> I can grab the Aco key for each Volume but can't figure out how to get
> from that to the Group's permissions. The following code leaves me
> with the proper tree and, for each Volume, its Aco. But there's no
> join applied for Permission (aros_acos) nor Aro.
>
> Anyone have any ideas?
>
> $this->bindModel(
> array(
> 'belongsTo' => array(
> 'Aco' => array(
> 'foreignKey' => false,
> 'conditions' => array(
> 'Aco.model' => 'Volume',
> 'Aco.foreign_key = Volume.id'
> )
> )
> )
> )
> );
>
> $filters = array(
> 'fields' => array(
> 'Volume.id',
> 'Volume.parent_id',
> 'Volume.lft',
> 'Volume.rght',
> 'Volume.name',
> ),
> 'contain' => array(
> 'Aco' => array(
> 'fields' => array('Aco.id'),
> 'Permission' => array(
> 'Aro' => array(
> 'conditions' => array(
> 'Aro.model' => 'Group',
> "Aro.foreign_key = ${group_id}"
> )
> )
> )
> )
> )
> );
>
> return $this->find('threaded', $filters);
>
> The returned array is like:
>
> Array
> (
> [0] => Array
> (
> [Volume] => Array
> (
> [id] => 1
> [parent_id] =>
> [lft] => 1
> [rght] => 171
> [name] =>
> )
>
> [Aco] => Array
> (
> [id] => 2
> )
>
> [children] => Array
> (
> ...
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---