如何使用symfony原则中的查询生成器来检查与权限连接表进行检查的文档?

问题描述 投票:0回答:1

我很好奇如何使用Symfony中的查询构建器构建一个学说查询,它可以基于相当标准化的权限连接表排除项目。

就我而言,

User实体

Template实体

userTemplatePermissionTable

在userTemplatePermissions实体中,我们具有以下属性:

[userToChecktemplatereadwritedelete

而且我想要的东西等同于:

return $this->createQueryBuilder('t')
[where count of t.userDocumentPermissions > 0
  where canRead = true, canWrite = true, canDelete = true
AND userDocumentpermissions.user = :user]
php symfony doctrine doctrine-query
1个回答
0
投票

这最终是一个相当简单的左联接和排除检查设置,我在TemplateRespository.php中总结了以下内容:>

public function findUserAuthorized($user, $read = null, $write = null, $delete = null)
{
    $query = $this->createQueryBuilder('t')
    ->leftJoin('t.userTemplatePermissions', 'utp')
    ->where('utp.userToCheck = :user')
    ->setParameter('user',$user);

    if ($read !== null) {
        $query->andWhere('utp.read = :read')
        ->setParameter('read',$read);
    }
    if ($write !== null) {
        $query->andWhere('utp.write = :write')
        ->setParameter('write',$write);
    }
    if ($delete !== null) {
        $query->andWhere('utp.delete = :delete')
        ->setParameter('delete',$delete);
    }
    return $query->getQuery()->getResult();
}
    
© www.soinside.com 2019 - 2024. All rights reserved.