This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Display Group Name on SfGuardUser list

Questions relating to sfGuardPlugin or other user management plugins

Display Group Name on SfGuardUser list

by pixworld » Thu Apr 14, 2011 8:23 pm

Hi, I would like to display on my User List the name of the current group of each person.

I use SF 1.4 and sfDoctrineGuardPlugin.

So this is my generator.yml in sfGuardUser, I've added sfGuardUserGroup to display user's group.

Code: Select all
generator:
  class: sfDoctrineGenerator
  param:
    model_class:           sfGuardUser
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          sf_guard_user
    with_doctrine_route:   true

    config:
      list:
       #titre de la liste    
        title: Users List
       #ordre et element a afficher      
        display: [id, =Utilisateur, sfGuardUserGroup, last_login, is_active]
       #nb par page
        max_per_page: 15
       #ordonner la liste
        sort: [username, asc]
        #Intitule des colonnes
        fields:
          is_active:
             label: Active
          Utilisateur:
             label: User   
          sfGuardUserGroup:
             label: Group         
          last_login:
            label: Last login
          is_active:
            label: Active         
       #action possibles
        batch_actions:
          _delete: ~
          pdfexport: {label: Export to PDF, action: pdfexport}
          csvexport: {label: Export to CSV, action: csvexport}   
      filter:
        #elements de filtre    
        display: [is_active, last_login, groups_list]       
      form:
        class: sfGuardUserAdminForm
        display:
          "NONE":                   [username, password, utilisateur]
          "Permissions and groups": [is_active, permissions_list]
      edit:
        title: Edit an user

      new:
        title: Add an user


And I think I need to modify /lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUserGroup.class.php

This my function do display the name of the group for a user :

Code: Select all
      //Fonction qui permet le nom du group du user
   public function __toString()
   {
         if($this->getId()!= '') {
            //Recherche du groupe lie utilisateur
            $usergroup = Doctrine::getTable('sfGuardUserGroup')
                        ->createQuery('a')
                        ->where('a.user_id = ?',$this->getId())
                        ->execute();
                   
            $group = Doctrine::getTable('sfGuardGroup')
                        ->createQuery('g')
                        ->where('g.id = ?',$usergroup->getGroupId())
                        ->execute();             
            
               return sprintf('%s', $group->getName());
         }   
   }


Symfony return me the code below in td_tabular without error :
Code: Select all
<pre> Doctrine_Collection data : Array( 0 : Object(sfGuardUserGroup) ) </pre>



What is wrong in my code, if you can help me to display the User's Group.

Thanks.
pixworld
Junior Member
 
Posts: 27
Joined: Fri Jul 16, 2010 3:28 pm
Location: Le Mans

Re: Display Group Name on SfGuardUser list

by Kerni » Thu Oct 27, 2011 8:55 am

You probably copied generator.yml from plugins to your app directory and editing the latter. This is a known issue. Symfony will still read generator.yml in plugin's dir. So you have to either delete the file in the plugin's dir (the easiest way), or read here for some more involved solutions: oldforum.symfony-project.org/index.php/m/43279/
Kerni
Junior Member
 
Posts: 1
Joined: Thu Oct 27, 2011 8:49 am