-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
291 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Gedmo\Mapping\Annotation as Gedmo; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="App\Repository\IdeaStatusRepository") | ||
*/ | ||
class IdeaStatus | ||
{ | ||
/** | ||
* @ORM\Id() | ||
* @ORM\GeneratedValue() | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $title; | ||
|
||
/** | ||
* @Gedmo\Timestampable(on="create") | ||
* @ORM\Column(type="datetime") | ||
*/ | ||
private $creationDatetime; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="App\Entity\Idea", mappedBy="status") | ||
*/ | ||
private $ideas; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255, nullable=true) | ||
*/ | ||
private $slug; | ||
|
||
|
||
public function __construct() | ||
{ | ||
$this->ideas = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getTitle(): ?string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function setTitle(string $title): self | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCreationDatetime(): ?\DateTimeInterface | ||
{ | ||
return $this->creationDatetime; | ||
} | ||
|
||
public function setCreationDatetime(\DateTimeInterface $creationDatetime): self | ||
{ | ||
$this->creationDatetime = $creationDatetime; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection|Idea[] | ||
*/ | ||
public function getIdeas(): Collection | ||
{ | ||
return $this->ideas; | ||
} | ||
|
||
public function addIdea(Idea $idea): self | ||
{ | ||
if (!$this->ideas->contains($idea)) { | ||
$this->ideas[] = $idea; | ||
$idea->setStatus($this); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeIdea(Idea $idea): self | ||
{ | ||
if ($this->ideas->contains($idea)) { | ||
$this->ideas->removeElement($idea); | ||
// set the owning side to null (unless already changed) | ||
if ($idea->getStatus() === $this) { | ||
$idea->setStatus(null); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function getSlug(): ?string | ||
{ | ||
return $this->slug; | ||
} | ||
|
||
public function setSlug(?string $slug): self | ||
{ | ||
$this->slug = $slug; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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 Version20180917061956 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('CREATE TABLE idea_status (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, creation_datetime DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE idea ADD status_id INT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE idea ADD CONSTRAINT FK_A8BCA456BF700BD FOREIGN KEY (status_id) REFERENCES idea_status (id)'); | ||
$this->addSql('CREATE INDEX IDX_A8BCA456BF700BD ON idea (status_id)'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE idea DROP FOREIGN KEY FK_A8BCA456BF700BD'); | ||
$this->addSql('DROP TABLE idea_status'); | ||
$this->addSql('DROP INDEX IDX_A8BCA456BF700BD ON idea'); | ||
$this->addSql('ALTER TABLE idea DROP status_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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 Version20180925063136 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema) : void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE idea_status ADD slug VARCHAR(255) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema) : void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE idea_status DROP slug'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\IdeaStatus; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Symfony\Bridge\Doctrine\RegistryInterface; | ||
|
||
/** | ||
* @method IdeaStatus|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method IdeaStatus|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method IdeaStatus[] findAll() | ||
* @method IdeaStatus[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class IdeaStatusRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(RegistryInterface $registry) | ||
{ | ||
parent::__construct($registry, IdeaStatus::class); | ||
} | ||
|
||
// /** | ||
// * @return IdeaStatus[] Returns an array of IdeaStatus objects | ||
// */ | ||
/* | ||
public function findByExampleField($value) | ||
{ | ||
return $this->createQueryBuilder('i') | ||
->andWhere('i.exampleField = :val') | ||
->setParameter('val', $value) | ||
->orderBy('i.id', 'ASC') | ||
->setMaxResults(10) | ||
->getQuery() | ||
->getResult() | ||
; | ||
} | ||
*/ | ||
|
||
/* | ||
public function findOneBySomeField($value): ?IdeaStatus | ||
{ | ||
return $this->createQueryBuilder('i') | ||
->andWhere('i.exampleField = :val') | ||
->setParameter('val', $value) | ||
->getQuery() | ||
->getOneOrNullResult() | ||
; | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Services; | ||
|
||
use App\Entity\IdeaStatus; | ||
|
||
class IdeaStatusBadgeDefiner | ||
{ | ||
/** | ||
* @param IdeaStatus $ideaStatus | ||
* | ||
* @return string | ||
*/ | ||
public function getBadgeLevel(IdeaStatus $ideaStatus): string | ||
{ | ||
switch ($ideaStatus->getSlug()) { | ||
|
||
case 'implemented' : | ||
return 'success'; | ||
case 'closed': | ||
return 'dark'; | ||
case 'need-example': | ||
case 'need-author': | ||
return 'warning'; | ||
case 'troll': | ||
return 'info'; | ||
default: | ||
return 'primary'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters