-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(BodyData): Added default body data (#118) * Update dependencies * Add default value to body data * feat(Migrations): Implemented db migrations (#119) * Install doctrine migrations package * Add migrations configuration * Add migrations folder * Update usefull commands * Generates initial migration * Load all migrations * Update readme * Update pr template * Add foreign keys * Rename workflow * Move cache up * Move checkout * Release/v0.1.1 (#120) (#121) * fix(BodyData): Added default body data (#118) * Update dependencies * Add default value to body data * feat(Migrations): Implemented db migrations (#119) * Install doctrine migrations package * Add migrations configuration * Add migrations folder * Update usefull commands * Generates initial migration * Load all migrations * Update readme * Update pr template * Add foreign keys * Rename workflow * Move cache up * Move checkout * Bump version * Remove empty line * feat(Created): Added created column (#122) * Add created column * Generate migration * Add created column * Generate migration * Update dependencies * Sort by created date * Fix/rename users table (#123) * Add migrations generate command * Rename table * Generate migration * Fix migration * Fix migration * Fix ascii convertion (#125) * feat(Menu): Implemented menu (#126) * Update dependencies * Add menu entity * Add menu item entity * Fix anotations * Fix anotation * Add DateTime type * Generate migration * Add menu controller * Update return structure * Bump version
- Loading branch information
Showing
9 changed files
with
580 additions
and
127 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller; | ||
|
||
use App\Controller\Base; | ||
use App\Lib\Middleware\RouteFactory; | ||
use Exception; | ||
|
||
final class Menu extends Base | ||
{ | ||
/** | ||
* Register routes to router | ||
* | ||
* @param \App\Lib\Middleware\Router $router | ||
* @return void | ||
*/ | ||
public function registerRoutes(\App\Lib\Middleware\Router $router): void | ||
{ | ||
$router->register(RouteFactory::fromConstants(1, "GET", "@^(?<version>[0-9]+)/menu/(?<id>[0-9]+)$@", "getOneById", array("id"))); | ||
} | ||
|
||
/** | ||
* Gets one menu by ID | ||
* | ||
* @param int $id | ||
* @return \App\Model\Entity\Menu | ||
*/ | ||
public function getOneById(int $id): \App\Model\Entity\Menu | ||
{ | ||
$menu = $this->entityManager->getRepository('App\Model\Entity\Menu')->findOneBy(array('id' => $id)); | ||
|
||
if ($menu instanceof \App\Model\Entity\Menu) { | ||
$items = []; | ||
foreach ($menu->getItems() as $item) { | ||
array_push($items, array('title' => $item->getTitle(), 'target' => $item->getTarget(), "updated" => $menu->getUpdated(), 'created' => $menu->getCreated(), "state" => $menu->getState())); | ||
} | ||
|
||
$this->view->render(["title" => $menu->getTitle(), "items" => $items, "updated" => $menu->getUpdated(), 'created' => $menu->getCreated(), "state" => $menu->getState()]); | ||
|
||
return $menu; | ||
} else { | ||
throw new Exception("Menu with ID:" . $id . " can not be founded!", 404); | ||
} | ||
} | ||
} |
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,173 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Model\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\ORM\PersistentCollection; | ||
use DateTime; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="menu") | ||
*/ | ||
class Menu | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* @var int | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=512) | ||
* @var string | ||
*/ | ||
protected $title; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="MenuItem", mappedBy="menu") | ||
* @var PersistentCollection<MenuItem> | ||
*/ | ||
protected $items; | ||
|
||
/** | ||
* @ORM\Column(type="datetime", nullable=false) | ||
* @ORM\Version | ||
* @var DateTime | ||
*/ | ||
protected $updated; | ||
|
||
/** | ||
* @ORM\Column(type="datetime", nullable=false) | ||
* @var DateTime | ||
*/ | ||
protected $created; | ||
|
||
/** | ||
* @ORM\Column(type="boolean") | ||
* @var boolean | ||
*/ | ||
protected $state; | ||
|
||
/** | ||
* @param string $title | ||
* @param bool $state | ||
*/ | ||
public function __construct(string $title = "", bool $state = true) | ||
{ | ||
$this->setTitle($title); | ||
$this->setCreated(new DateTime("now")); | ||
$this->setState($state); | ||
} | ||
|
||
/** | ||
* Sets title | ||
* | ||
* @param string $title | ||
* @return self | ||
*/ | ||
public function setTitle(string $title): self | ||
{ | ||
$this->title = $title; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets updated date | ||
* | ||
* @return self | ||
*/ | ||
public function setUpdated(): self | ||
{ | ||
$this->updated = new DateTime("now"); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets created date | ||
* | ||
* @param DateTime $created | ||
* @return self | ||
*/ | ||
public function setCreated(DateTime $created): self | ||
{ | ||
$this->created = $created; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Sets state | ||
* | ||
* @param boolean $state | ||
* @return self | ||
*/ | ||
public function setState(bool $state): self | ||
{ | ||
$this->state = $state; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Return ID | ||
* | ||
* @return integer | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Returns title | ||
* | ||
* @return string | ||
*/ | ||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* Returns menu items associated to menu entity | ||
* | ||
* @return PersistentCollection<MenuItem> | ||
*/ | ||
public function getItems(): PersistentCollection | ||
{ | ||
return $this->items; | ||
} | ||
|
||
/** | ||
* Returns updated date | ||
* | ||
* @return DateTime | ||
*/ | ||
public function getUpdated(): DateTime | ||
{ | ||
return $this->updated; | ||
} | ||
|
||
/** | ||
* Returns created date | ||
* | ||
* @return DateTime | ||
*/ | ||
public function getCreated(): DateTime | ||
{ | ||
return $this->created; | ||
} | ||
|
||
/** | ||
* Returns state | ||
* | ||
* @return boolean | ||
*/ | ||
public function getState(): bool | ||
{ | ||
return $this->state; | ||
} | ||
} |
Oops, something went wrong.