diff --git a/composer.json b/composer.json index 34c4ae3..787d1f9 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "mcnd/picea": "dev-master", "mcnd/picea-ui": "dev-master", "mcnd/cronard": "dev-master", - "mcnd/storage": "dev-master", "mcnd/tell": "dev-master", "mcnd/dump": "dev-master", "mcnd/notes": "dev-master", diff --git a/meta/i18n/en/lean.software.json b/meta/i18n/en/lean.software.json new file mode 100644 index 0000000..9edde48 --- /dev/null +++ b/meta/i18n/en/lean.software.json @@ -0,0 +1,4 @@ +{ + "copyright" : "All rights reserved © {$organisation} {$year}", + "dashboard": "Dashboard" +} diff --git a/meta/i18n/fr/lean.software.json b/meta/i18n/fr/lean.software.json new file mode 100644 index 0000000..1051187 --- /dev/null +++ b/meta/i18n/fr/lean.software.json @@ -0,0 +1,4 @@ +{ + "copyright" : "Tout droits réservés © {$organisation} {$year}", + "dashboard": "Tableau de bord" +} diff --git a/src/ControllerTrait.php b/src/ControllerTrait.php index 39d1498..b3914fd 100644 --- a/src/ControllerTrait.php +++ b/src/ControllerTrait.php @@ -2,8 +2,10 @@ namespace Lean; -use Picea; +use Picea, + Picea\Ui\Method\FormContext; +use Psr\Http\Message\ServerRequestInterface; use Storage\Session; use Laminas\Diactoros\Response\{ HtmlResponse, TextResponse, RedirectResponse, JsonResponse }; @@ -12,7 +14,7 @@ use Ulmus\EntityCollection; use Psr\Http\Message\ResponseInterface; -# use TheBugs\Email\MailerInterface; +use TheBugs\Email\MailerInterface; use Notes\Route\Annotation\Object\Route as RouteParam, Notes\Route\Annotation\Method\Route, @@ -31,12 +33,23 @@ trait ControllerTrait { public ? Picea\Picea $picea; - public MailerInterface $mailer; - - public function __construct(? Picea\Picea $picea, Session $session/*, MailerInterface $mailer*/) { + public ? MailerInterface $mailer; + + public array $contextList = []; + + public function __construct(? Picea\Picea $picea, Session $session, ? MailerInterface $mailer = null) { $this->picea = $picea; $this->session = $session; - // $this->mailer = $mailer; + $this->mailer = $mailer; + } + + public function exportJson(ServerRequestInterface $request, string $entityClass, bool $includeRelations = true, ? callable $callback = null) : ResponseInterface + { + foreach($entityClass::repository()->filterServerRequest( $entityClass::searchRequest()->fromRequest($request->withQueryParams($request->getQueryParams() + ['limit' => PHP_INT_MAX,])) )->loadAll() as $entity) { + $data[] = $callback ? call_user_func($callback, $entity->toArray($includeRelations)) : $entity->toArray($includeRelations); + } + + return $this->renderJson( array_filter($data ?? [], function($row) { return $row !== null; })); } public function renderView(string $view, ?array $variables = null) : ResponseInterface @@ -54,7 +67,7 @@ trait ControllerTrait { protected function redirect(string $url, int $code = 302, array $headers = []) { return new RedirectResponse($url, $code, $headers); } - + public static function renderText(string $html, int $code = 200, array $headers = []) : ResponseInterface { return new TextResponse($html, $code, $headers); @@ -69,4 +82,16 @@ trait ControllerTrait { { return new JsonResponse($data, $code, $headers); } + + public function pushContext(FormContext $context) : FormContext + { + $this->contextList[$context->formName ?? uniqid("context_")] = $context; + + return $context; + } + + public function context(string $name) : FormContext + { + return $this->contextList[$name]; + } } diff --git a/view/lean/widget/breadcrumb.phtml b/view/lean/widget/breadcrumb.phtml new file mode 100644 index 0000000..ec135d7 --- /dev/null +++ b/view/lean/widget/breadcrumb.phtml @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/view/lean/widget/message.phtml b/view/lean/widget/message.phtml new file mode 100644 index 0000000..de7412b --- /dev/null +++ b/view/lean/widget/message.phtml @@ -0,0 +1,7 @@ +
+ {% foreach array_filter(array_merge($this->contextList, [ $context ?? null ])) as $name => $context %} + {% foreach $context->messages ?? [] as $message %} + {{= $message->render() }} + {% endforeach %} + {% endforeach %} +
\ No newline at end of file