Skip to content

Instantly share code, notes, and snippets.

@kovenko
Last active April 30, 2020 14:19
Show Gist options
  • Select an option

  • Save kovenko/dfab1524397d65f8a94e64f4283ad458 to your computer and use it in GitHub Desktop.

Select an option

Save kovenko/dfab1524397d65f8a94e64f4283ad458 to your computer and use it in GitHub Desktop.
<?php
namespace Rgkh\Ais\Application\Controller;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Query\Expr\Join;
use Rgkh\Common\Authorization\Entity\User;
use Rgkh\Common\Authorization\Repository\UserRepository;
use Rgkh\Common\House\Entity\Houses;
use Rgkh\Common\House\Repository\HouseRepository;
use Rgkh\Common\Main\Entity\EPD\EPDHousePassport;
class TestController extends AbstractAisController
{
public function indexAction()
{
/** @var UserRepository $userRepository */
$userRepository = $this->getDoctrine()->getRepository(User::class);
$user = $userRepository->find($this->identity());
/** @var HouseRepository $houseRepository */
$houseRepository = $this->getDoctrine()->getRepository(Houses::class);
// // Добавление/удаление дома в избранное пользователя
// $house = $houseRepository->findBy(['id' => [6910410, 6851628]]);
// $user->addFavoriteHouses(new ArrayCollection($house));
// $user->removeFavoriteHouses(new ArrayCollection($house));
// $this->getDoctrine()->persist($user);
// $this->getDoctrine()->flush();
// // Поиск дома в избранном пользователя
// $house = $houseRepository->findOneBy(['id' => 6851628]);
// $query = $this->getDoctrine()->createQueryBuilder();
// $query->select('u.id AS userId, ISNOTNULL(u.id) AS isFavorite');
// $query->from(Houses::class, 'h')
// ->leftJoin('h.users', 'u', Join::WITH, 'u.id = :userId')
// ->where('h.id = :houseId');
// $query->setParameter('userId', $user->getId());
// $query->setParameter('houseId', $house->getId());
// $result = $query->getQuery()->getSingleResult();
// Список домов в избранном пользователя
$houses = $user->getFavoriteHouses()->toArray();
die('success');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment