0

モジュールに管理ジェネレーターを使用していsfGuardUserます。ファイルの編集部分はgenerator.yml次のようになります。

edit:
  title: Editing User "%%username%%"
  display:
    "User":  [first_name, last_name, email_address, username, password, password_again]
    "Permissions and groups": [is_active, groups_list, sites_list]

現在、すべてのユーザーがこのフォームにアクセスできるわけではありません。サイト管理者のみが、サイト管理者が自分のユーザーを作成および更新できるようになっています。と の間には多対多の関係がUserありSiteます。各サイト管理者もユーザーであり、関連付けられた一連のサイトを持っています。

sites_listすべてのサイトを表示するのではなく、サイト管理者が関連付けられているサイトのみを表示して、サイト管理者が自分のユーザーの 1 人を管理者が関連付けられていないサイトに配置できないようにしたいと考えています。

これを行うには別のものに置き換える必要があるように思えsites_listますが、この変更をどこでどのように行うべきかわかりません。

4

1 に答える 1

0

私が考える唯一の方法は、sites_lists ウィジェットを自動生成フォームから変更することです。たとえば、あなたの場合、次のようなことができます。

<!-- SitesTable -->
public function getByUser($userId){
     //create your query to find all sites from that user
      $userSites = $this->createQuery()->...
                        ->where('user_id = ?', $userId);

      //create the array
      $choices = array();
      foreach ( $userSites as $site ) {
          $choices[$site->getId()] = $site->getName();
      }

      return $choices;
}

<!-- sfGuardUserForm -->
class sfGuardUserForm extends BaseSfGuardUserForm{
    public function configure() {
      //unset the old sites_list
      unset($this['sites_list']);

      //obtain the user id (depends on how it's implemented, i'm not using sfGuard)
      $userId = sfContext::getInstance()->getUser()->getId(); 

      $choices = Doctrine::getTable('Sites')->getByUser($userId);

      //set the new widget filtered
      $this->setWidget('sites_list', new sfWidgetFormChoice(array('choices' => $choices)));
      $this->setValidator('sites_list', new sfValidatorChoice(array('choices' => array_keys($choices))));

}
于 2011-04-17T00:54:19.010 に答える