0

In sfDoctrineGuardPlugin is:

sfGuardUser:
  actAs: [Timestampable]
  columns:
    first_name: string(255)
    last_name: string(255)
    //
  indexes:
    is_active_idx:
      fields: [is_active]
  relations:
    Groups:
      class: sfGuardGroup
      local: user_id
      foreign: group_id
      refClass: sfGuardUserGroup
      foreignAlias: Users



sfGuardGroup:
  actAs: [Timestampable]
  columns:
    name:
      type: string(255)
      unique: true
    description: string(1000)
  relations:
    Users:
      class: sfGuardUser
      refClass: sfGuardUserGroup
      local: group_id
      foreign: user_id
      foreignAlias: Groups

sfGuardUserGroup:
  options:
    symfony:
      form:   false
      filter: false
  actAs: [Timestampable]
  columns:
    user_id:
      type: integer
      primary: true
    group_id:
      type: integer
      primary: true
  relations:
    User:
      class: sfGuardUser
      local: user_id
      onDelete: CASCADE
    Group:
      class: sfGuardGroup
      local: group_id
      onDelete: CASCADE

This is relation many to many and how can i get all groups of User?

  • @method Doctrine_Collection
    getGroups() Returns the current record's "Groups" collection

i make:

$this->groups = $this->getUser()->getGuardUser()->getGroups();

this return:

 Doctrine_Collection data : Array( ) 

how can i check whether the user is on group TEST?

Thanks for help!

2 Answers2

1

you may try using a query to find groups of your user:

$user_id = $this->getUser()->getGuardUser()->getId();
$groups = Doctrine_core::getTable('sfGuardGroup')->create_query('g')->innerJoin('g.users u with u.id= ?', $user_id);
dxb
  • 931
  • 5
  • 7
1

See the sfGuardSecurityUser class: https://github.com/Garfield-fr/sfDoctrineGuardPlugin/blob/master/lib/user/sfGuardSecurityUser.class.php

if ($this->getUser()->hasGroup('TEST')) {
    //if user is on group TEST
}//end if

// get all groups

$userGroups = $this->getUser()->getGroups();
turbod
  • 1,988
  • 2
  • 17
  • 31
  • thanks, but i use $userGroups then i have: "
     Doctrine_Collection data : Array( 0 : Object(sfGuardGroup) ) 
    " how can i show it? :) foreach and .. ?
    – Tony Oriondo Jul 01 '11 at 18:02
  • @Tony Oriondo: If you not not set groups to your user, the getGroups method return an empty array. Are you sure you set group to your user? – turbod Jul 03 '11 at 08:15