111 lines
3.1 KiB
PHP
111 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Pagewidget;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Pagewidget>
|
|
*
|
|
* @method Pagewidget|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Pagewidget|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Pagewidget[] findAll()
|
|
* @method Pagewidget[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class PagewidgetRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Pagewidget::class);
|
|
}
|
|
|
|
public function save(Pagewidget $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->persist($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
public function remove(Pagewidget $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->remove($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
public function getCansee($user, $pagewidget)
|
|
{
|
|
$cansee = false;
|
|
|
|
if (!$pagewidget) {
|
|
return $cansee;
|
|
}
|
|
|
|
$page = $pagewidget->getPage();
|
|
if (!$page) {
|
|
return $cansee;
|
|
}
|
|
|
|
// Si visiteur la page partage avec visitor ?
|
|
if (!$user) {
|
|
if ($page->getRoles() && in_array('ROLE_ANONYME', $page->getRoles())) {
|
|
$cansee = true;
|
|
}
|
|
} else {
|
|
// Si propriétaire de la page il peut voir
|
|
if ($page->getUser() == $user) {
|
|
$cansee = true;
|
|
}
|
|
// Si membre du groupe il peut voir
|
|
else {
|
|
foreach ($page->getGroups() as $group) {
|
|
$usergroup = $this->getEntityManager()->getRepository('App\Entity\UserGroup')->findoneby(['user' => $user, 'group' => $group]);
|
|
if ($usergroup) {
|
|
$cansee = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $cansee;
|
|
}
|
|
|
|
public function getCanadd($user, $pagewidget, $usage)
|
|
{
|
|
$canadd = false;
|
|
|
|
if (!$pagewidget) {
|
|
return $canadd;
|
|
}
|
|
|
|
$page = $pagewidget->getPage();
|
|
if (!$page) {
|
|
return $canadd;
|
|
}
|
|
|
|
if ($user) {
|
|
// Si propriétaire de la page il peut ajouter
|
|
if ($page->getUser() == $user) {
|
|
$canadd = true;
|
|
}
|
|
// Si membre du groupe il peut ajouter
|
|
else {
|
|
foreach ($page->getGroups() as $group) {
|
|
$usergroup = $this->getEntityManager()->getRepository('App\Entity\UserGroup')->findoneby(['user' => $user, 'group' => $group]);
|
|
if ($usergroup and $usergroup->getRolegroup() >= 50) {
|
|
$canadd = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $canadd;
|
|
}
|
|
}
|