mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 04:48:55 +00:00
added video entity
This commit is contained in:
parent
0af4d76bcb
commit
f3d856c2c1
7 changed files with 272 additions and 7 deletions
50
migrations/Version20210105205256.php
Normal file
50
migrations/Version20210105205256.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20210105205256 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE TABLE video (id BLOB NOT NULL, uploader_id BLOB NOT NULL, uploaded DATETIME NOT NULL --(DC2Type:datetime_immutable)
|
||||||
|
, name VARCHAR(255) NOT NULL, description VARCHAR(1024) NOT NULL, tags CLOB NOT NULL --(DC2Type:array)
|
||||||
|
, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('CREATE INDEX IDX_7CC7DA2C16678C77 ON video (uploader_id)');
|
||||||
|
$this->addSql('DROP INDEX UNIQ_8D93D6495E237E06');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, password, name, roles FROM user');
|
||||||
|
$this->addSql('DROP TABLE user');
|
||||||
|
$this->addSql('CREATE TABLE user (id BLOB NOT NULL, password VARCHAR(255) NOT NULL COLLATE BINARY, name VARCHAR(180) NOT NULL COLLATE BINARY, roles CLOB NOT NULL COLLATE BINARY --(DC2Type:json)
|
||||||
|
, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('INSERT INTO user (id, password, name, roles) SELECT id, password, name, roles FROM __temp__user');
|
||||||
|
$this->addSql('DROP TABLE __temp__user');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6495E237E06 ON user (name)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('DROP TABLE video');
|
||||||
|
$this->addSql('DROP INDEX UNIQ_8D93D6495E237E06');
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__user AS SELECT id, name, roles, password FROM user');
|
||||||
|
$this->addSql('DROP TABLE user');
|
||||||
|
$this->addSql('CREATE TABLE user (id BLOB NOT NULL, name VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, password VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
|
||||||
|
$this->addSql('INSERT INTO user (id, name, roles, password) SELECT id, name, roles, password FROM __temp__user');
|
||||||
|
$this->addSql('DROP TABLE __temp__user');
|
||||||
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_8D93D6495E237E06 ON user (name)');
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use App\Repository\VideoRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
@ -11,6 +13,15 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||||
class HomeController extends AbstractController
|
class HomeController extends AbstractController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private $userRepository;
|
||||||
|
private $videoRepository;
|
||||||
|
|
||||||
|
public function __construct(UserRepository $userRepository, VideoRepository $videoRepository)
|
||||||
|
{
|
||||||
|
$this->userRepository = $userRepository;
|
||||||
|
$this->videoRepository = $videoRepository;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/", name="app_home")
|
* @Route("/", name="app_home")
|
||||||
*/
|
*/
|
||||||
|
@ -21,6 +32,11 @@ class HomeController extends AbstractController
|
||||||
return $this->redirectToRoute("app_login");
|
return $this->redirectToRoute("app_login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user = $this->userRepository->findOneByName($this->getUser()->getUsername());
|
||||||
|
$videos = $this->videoRepository->findByUploader($user);
|
||||||
|
|
||||||
|
dump($videos);
|
||||||
|
|
||||||
return $this->render("home/dashboard.html.twig");
|
return $this->render("home/dashboard.html.twig");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,8 +24,8 @@ class UserFixtures extends Fixture
|
||||||
$admin = new User();
|
$admin = new User();
|
||||||
$admin->setName("admin");
|
$admin->setName("admin");
|
||||||
$admin->setPassword($this->passwordEncoder->encodePassword($admin, "password"));
|
$admin->setPassword($this->passwordEncoder->encodePassword($admin, "password"));
|
||||||
|
|
||||||
$manager->persist($admin);
|
$manager->persist($admin);
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Ramsey\Uuid\Doctrine\UuidGenerator;
|
use Ramsey\Uuid\Doctrine\UuidGenerator;
|
||||||
use Ramsey\Uuid\UuidInterface;
|
use Ramsey\Uuid\UuidInterface;
|
||||||
|
@ -37,6 +39,16 @@ class User implements UserInterface
|
||||||
*/
|
*/
|
||||||
private $password;
|
private $password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity=Video::class, mappedBy="uploader", orphanRemoval=true)
|
||||||
|
*/
|
||||||
|
private $videos;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->videos = new ArrayCollection();
|
||||||
|
}
|
||||||
|
|
||||||
public function getId(): ?UuidInterface
|
public function getId(): ?UuidInterface
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
@ -114,4 +126,34 @@ class User implements UserInterface
|
||||||
// If you store any temporary, sensitive data on the user, clear it here
|
// If you store any temporary, sensitive data on the user, clear it here
|
||||||
// $this->plainPassword = null;
|
// $this->plainPassword = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection|Video[]
|
||||||
|
*/
|
||||||
|
public function getVideos(): Collection
|
||||||
|
{
|
||||||
|
return $this->videos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addVideo(Video $video): self
|
||||||
|
{
|
||||||
|
if (!$this->videos->contains($video)) {
|
||||||
|
$this->videos[] = $video;
|
||||||
|
$video->setUploader($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeVideo(Video $video): self
|
||||||
|
{
|
||||||
|
if ($this->videos->removeElement($video)) {
|
||||||
|
// set the owning side to null (unless already changed)
|
||||||
|
if ($video->getUploader() === $this) {
|
||||||
|
$video->setUploader(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
112
src/Entity/Video.php
Normal file
112
src/Entity/Video.php
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\VideoRepository;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use Ramsey\Uuid\Doctrine\UuidGenerator;
|
||||||
|
use Ramsey\Uuid\UuidInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Entity(repositoryClass=VideoRepository::class)
|
||||||
|
*/
|
||||||
|
class Video
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @ORM\Id
|
||||||
|
* @ORM\Column(type="uuid", unique=true)
|
||||||
|
* @ORM\GeneratedValue(strategy="CUSTOM")
|
||||||
|
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="videos")
|
||||||
|
* @ORM\JoinColumn(nullable=false)
|
||||||
|
*/
|
||||||
|
private $uploader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="datetime_immutable")
|
||||||
|
*/
|
||||||
|
private $uploaded;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=255)
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=1024)
|
||||||
|
*/
|
||||||
|
private $description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="array")
|
||||||
|
*/
|
||||||
|
private $tags = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->uploaded = new DateTimeImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): ?UuidInterface
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUploader(): ?User
|
||||||
|
{
|
||||||
|
return $this->uploader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUploader(?User $uploader): self
|
||||||
|
{
|
||||||
|
$this->uploader = $uploader;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUploaded(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->uploaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): ?string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): self
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription(): ?string
|
||||||
|
{
|
||||||
|
return $this->description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescription(string $description): self
|
||||||
|
{
|
||||||
|
$this->description = $description;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTags(): ?array
|
||||||
|
{
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTags(array $tags): self
|
||||||
|
{
|
||||||
|
$this->tags = $tags;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -54,15 +54,12 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
public function findOneByName($value): ?User
|
||||||
public function findOneBySomeField($value): ?User
|
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('u')
|
return $this->createQueryBuilder('u')
|
||||||
->andWhere('u.exampleField = :val')
|
->andWhere('u.name = :val')
|
||||||
->setParameter('val', $value)
|
->setParameter('val', $value)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getOneOrNullResult()
|
->getOneOrNullResult();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
48
src/Repository/VideoRepository.php
Normal file
48
src/Repository/VideoRepository.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Video;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Video|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
* @method Video|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
|
* @method Video[] findAll()
|
||||||
|
* @method Video[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||||
|
*/
|
||||||
|
class VideoRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, Video::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return Video[] Returns an array of Video objects
|
||||||
|
// */
|
||||||
|
/*
|
||||||
|
public function findByExampleField($value)
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('v')
|
||||||
|
->andWhere('v.exampleField = :val')
|
||||||
|
->setParameter('val', $value)
|
||||||
|
->orderBy('v.id', 'ASC')
|
||||||
|
->setMaxResults(10)
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*public function findByUploader(User $user): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('v')
|
||||||
|
->andWhere('v.uploader_id = :val')
|
||||||
|
->setParameter('val', $user->getId())
|
||||||
|
->getQuery()
|
||||||
|
->getArrayResult()
|
||||||
|
;
|
||||||
|
}*/
|
||||||
|
}
|
Loading…
Reference in a new issue