diff --git a/app/Controller/Admin/AdminController.php b/app/Controller/Admin/AdminController.php index b6d43aa..030ad5d 100644 --- a/app/Controller/Admin/AdminController.php +++ b/app/Controller/Admin/AdminController.php @@ -14,7 +14,7 @@ class AdminController extends Controller */ public function index() { - $this->view("admin/master",["template_admin" => $this->templateAdmin]); + $this->view("admin/painel",["template_admin" => $this->templateAdmin]); } diff --git a/app/Controller/Admin/CategoryController.php b/app/Controller/Admin/CategoryController.php new file mode 100644 index 0000000..fa4851d --- /dev/null +++ b/app/Controller/Admin/CategoryController.php @@ -0,0 +1,114 @@ +select()->busca("name")->paginate(3)->get(); + $this->view("admin/categories/index", [ + "template_admin" => $this->templateAdmin, + "categories" => $categories, + "links" => $category->links() + ]); + + } + + /** + * Exibe o formulário de criação + */ + public function create() { + $this->view("admin/categories/create", ["template_admin" => $this->templateAdmin]); + } + + /** + * Processa Formulário de criação + */ + public function store(Request $request, Response $response) { + //$data = filter_input_array(($_SERVER['REQUEST_METHOD'] == "POST") ? INPUT_POST : INPUT_GET, FILTER_SANITIZE_STRING); + $validate = new Validate(); + $data = $validate->validate([ + "name" => "required" + ]); + + if($validate->hasErros()){ + foreach($data as $field => $value){ + flash("post_".$field,$data[$field]); + } + back(); + } + + $category = new Category; + $category->create($data); + if($category->lastCreated > 0){ + flash("name",success("Cadastrado com sucesso")); + Redirect::redirect("/painel/admin/category"); + } + } + + /** + * Exibe dado do Banco de dados + */ + public function show($id) { + echo 'show'; + } + + /** + * Exibe o formulário de edição + */ + public function edit(Request $request, Response $response, $args) { + $category = new Category; + $category = $category->select()->where2(["id","=",$args["id"]])->first(); + return $response->write($this->view("admin/categories/edit", [ + "template_admin" => $this->templateAdmin, + "category" => $category + ])); + + } + + /** + * Processa o formulário de edição + */ + public function update(Request $request, Response $response, $args) { + + $validate = new Validate(); + $data = $validate->validate([ + "name" => "required" + ]); + + + + if($validate->hasErros()){ + foreach($data as $field => $value){ + flash("post_".$field,$data[$field]); + } + back(); + } + + $category = new Category; + $category->update2(["name" => $data["name"]])->where2(["id","=",$args["id"]])->exec(); + return Redirect::redirect("/painel/admin/category"); + } + + /** + * Remove dados do Banco + */ + public function destroy(Request $request, Response $response, $args) { + $category = new Category(); + $category->delete2()->where2(["id","=",$args["id"]])->exec(); + + return Redirect::redirect("/painel/admin/category"); + } + +} \ No newline at end of file diff --git a/app/Controller/Admin/PostController.php b/app/Controller/Admin/PostController.php new file mode 100644 index 0000000..433c217 --- /dev/null +++ b/app/Controller/Admin/PostController.php @@ -0,0 +1,61 @@ +view("admin/post/index", ["template_admin" => $this->templateAdmin]); + + } + + /** + * Exibe o formulário de criação + */ + public function create() { + $this->view("admin/post/create", ["template_admin" => $this->templateAdmin]); + } + + /** + * Processa Formulário de criação + */ + public function store(Request $request, Response $response) { + echo 'store'; + } + + /** + * Exibe dado do Banco de dados + */ + public function show($id) { + echo 'show'; + } + + /** + * Exibe o formulário de edição + */ + public function edit($id) { + echo 'edit'; + } + + /** + * Processa o formulário de edição + */ + public function update(Request $request, Response $response, $args) { + echo 'update'; + } + + /** + * Remove dados do Banco + */ + public function destroy($id) { + echo 'destroy'; + } + +} \ No newline at end of file diff --git a/app/Functions/twig.php b/app/Functions/twig.php index efdecc9..7df93db 100755 --- a/app/Functions/twig.php +++ b/app/Functions/twig.php @@ -3,6 +3,7 @@ use Twig\TwigFunction; use Core\Flash; use Core\Validate; +use Carbon\Carbon; $erros = new TwigFunction("erros",function($index){ @@ -25,4 +26,14 @@ }); -return [$erros,$sent,$message,$admin]; \ No newline at end of file +$timeAgo = new TwigFunction("timeAgo",function($date) { + + Carbon::setLocale("pt-br"); + + $created = Carbon::parse($date); + + return $created->diffForHumans(); + +}); + +return [$erros,$sent,$message,$admin,$timeAgo]; \ No newline at end of file diff --git a/app/Model/Category.php b/app/Model/Category.php new file mode 100644 index 0000000..c03ce66 --- /dev/null +++ b/app/Model/Category.php @@ -0,0 +1,10 @@ +erros[$field][] = flash($field, error("Favor preencha esse campo")); } } diff --git a/app/traits/View.php b/app/traits/View.php index db22325..f3cb3bd 100755 --- a/app/traits/View.php +++ b/app/traits/View.php @@ -2,36 +2,36 @@ namespace App\traits; use Core\Load; -use Twig\Loader\FilesystemLoader; use Twig\Environment; +use Twig\Loader\FilesystemLoader; -trait View{ +trait View { - protected $twig; - protected $templateAdmin = "../assets/templates"; + protected $twig; + protected $templateAdmin = "/assets/templates"; - protected function twig(){ + protected function twig() { - $loader = new FilesystemLoader(__DIR__ . "/../../views"); - $this->twig = new Environment($loader, ['debug' => true]); - $this->twig->addExtension(new \Twig\Extension\DebugExtension()); - } + $loader = new FilesystemLoader(__DIR__ . "/../../views"); + $this->twig = new Environment($loader, ['debug' => true]); + $this->twig->addExtension(new \Twig\Extension\DebugExtension()); + } - protected function functions(){ - $functions = Load::file("/app/Functions/twig.php"); + protected function functions() { + $functions = Load::file("/app/Functions/twig.php"); - foreach ($functions as $function){ - $this->twig->addFunction($function); - } - } + foreach ($functions as $function) { + $this->twig->addFunction($function); + } + } - protected function load(){ - $this->twig(); - $this->functions(); - } + protected function load() { + $this->twig(); + $this->functions(); + } - protected function view(string $view, array $data = []){ - $this->load(); - echo $this->twig->render(str_replace(".","/",$view).".html",$data); - } + protected function view(string $view, array $data = []) { + $this->load(); + echo $this->twig->render(str_replace(".", "/", $view) . ".html", $data); + } } \ No newline at end of file diff --git a/bootstrap.php b/bootstrap.php index cd8acd7..28a25c1 100755 --- a/bootstrap.php +++ b/bootstrap.php @@ -2,11 +2,10 @@ session_start(); require __DIR__ . "/vendor/autoload.php"; -use Slim\App; -use Dotenv\Dotenv; -use Core\Whoops; use Core\Middleware; - +use Core\Whoops; +use Dotenv\Dotenv; +use Slim\App; $dotenv = Dotenv::createImmutable(__DIR__); $dotenv->load(); @@ -14,50 +13,58 @@ $config['displayErrorDetails'] = true; $config['addContentLengthHeader'] = false; $config['db'] = [ - 'driver' => 'mysql', - 'host' => $_ENV["DB_HOST"], - 'database' => $_ENV["DB_DATABASE"], - 'username' => $_ENV["DB_USERNAME"], - 'password' => $_ENV["DB_PASSWORD"], - 'charset' => 'utf8', - 'collation' => 'utf8_unicode_ci', - 'prefix' => '' + 'driver' => 'mysql', + 'host' => $_ENV["DB_HOST"], + 'database' => $_ENV["DB_DATABASE"], + 'username' => $_ENV["DB_USERNAME"], + 'password' => $_ENV["DB_PASSWORD"], + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', ]; $app = new App(['settings' => $config]); $container = $app->getContainer(); - $container['AdminController'] = function ($container) { - $service = new \App\Controller\Admin\AdminController($container); - return $service; + $service = new \App\Controller\Admin\AdminController($container); + return $service; }; $container['ProfessorController'] = function ($container) { - $service = new \App\Controller\Admin\ProfessorController($container); - return $service; + $service = new \App\Controller\Admin\ProfessorController($container); + return $service; }; $container['LoginController'] = function ($container) { - $service = new \App\Controller\Admin\LoginController($container); - return $service; + $service = new \App\Controller\Admin\LoginController($container); + return $service; }; $container['PasswordRecoveryController'] = function ($container) { - $service = new \App\Controller\Admin\PasswordRecoveryController($container); - return $service; + $service = new \App\Controller\Admin\PasswordRecoveryController($container); + return $service; }; -$container['db'] = function ($container) { +$container['PostController'] = function ($container) { + $service = new \App\Controller\Admin\PostController($container); + return $service; +}; - $config = $container->get('settings'); - $capsule = new \Illuminate\Database\Capsule\Manager; - $capsule->addConnection($config["db"]); - $capsule->setAsGlobal(); - $capsule->bootEloquent(); +$container['CategoryController'] = function ($container) { + $service = new \App\Controller\Admin\CategoryController($container); + return $service; +}; + +$container['db'] = function ($container) { + $config = $container->get('settings'); + $capsule = new \Illuminate\Database\Capsule\Manager; + $capsule->addConnection($config["db"]); + $capsule->setAsGlobal(); + $capsule->bootEloquent(); - return $capsule; + return $capsule; }; $whoops = new Whoops(); diff --git a/config.php b/config.php index b0f84e0..e802ed8 100755 --- a/config.php +++ b/config.php @@ -1,22 +1,22 @@ [ - "admin" => [ - "loggedIn" => "admin", - "redirect" => "/painel/admin", - "idLoggedIn" => "id_admin" - ], - "user" => [ - "loggedIn" => "professor", - "redirect" => "/painel/professor", - "idLoggedIn" => "id_professor" - ] - ], + "login" => [ + "admin" => [ + "loggedIn" => "admin", + "redirect" => "/painel/admin", + "idLoggedIn" => "id_admin", + ], + "user" => [ + "loggedIn" => "professor", + "redirect" => "/painel/professor", + "idLoggedIn" => "id_professor", + ], + ], - "permission" => [ - 1 => "/painel/admin", - 2 => "/painel/professor", - 3 => "/painel/cliente" - ] + "permission" => [ + 1 => "/painel/admin", + 2 => "/painel/professor", + 3 => "/painel/cliente", + ], ]; \ No newline at end of file diff --git a/public/assets/templates/docs/_config.yml b/public/assets/templates/docs/_config.yml index e1505c6..106a7a0 100755 --- a/public/assets/templates/docs/_config.yml +++ b/public/assets/templates/docs/_config.yml @@ -67,7 +67,7 @@ navigation: - title: Layout url: javascript/layout.html - title: Push Menu - url: javascript/push-menu.html + url: javascript/push-painel.html - title: Treeview url: javascript/treeview.html - title: Card Widget diff --git a/public/index.php b/public/index.php index 2e1e1a9..f7ae534 100755 --- a/public/index.php +++ b/public/index.php @@ -1,25 +1,30 @@ get("/login","LoginController:index")->add($middleware->checkLoggedIn()); -$app->post("/login","LoginController:store"); -$app->get("/logout","LoginController:destroy"); +$app->get("/login", "LoginController:index")->add($middleware->checkLoggedIn()); +$app->post("/login", "LoginController:store"); +$app->get("/logout", "LoginController:destroy"); -$app->get("/forgot-password","PasswordRecoveryController:index")->add($middleware->checkLoggedIn()); -$app->post("/forgot-password","PasswordRecoveryController:checkMail"); -$app->get("/reset-password/code/{code}","PasswordRecoveryController:checkCode")->add($middleware->checkLoggedIn()); -$app->get("/reset-password-link-send","PasswordRecoveryController:linkConfirm"); -$app->get("/recover-password/user/{code}","PasswordRecoveryController:showFormUpdate")->add($middleware->checkLoggedIn()); -$app->post("/reset-password/user/{code}","PasswordRecoveryController:updatePassword"); +$app->get("/forgot-password", "PasswordRecoveryController:index")->add($middleware->checkLoggedIn()); +$app->post("/forgot-password", "PasswordRecoveryController:checkMail"); +$app->get("/reset-password/code/{code}", "PasswordRecoveryController:checkCode")->add($middleware->checkLoggedIn()); +$app->get("/reset-password-link-send", "PasswordRecoveryController:linkConfirm"); +$app->get("/recover-password/user/{code}", "PasswordRecoveryController:showFormUpdate")->add($middleware->checkLoggedIn()); +$app->post("/reset-password/user/{code}", "PasswordRecoveryController:updatePassword"); -$app->group("/painel/admin",function() use ($app){ - $app->get("[/]","AdminController:index"); +$app->group("/painel/admin", function () use ($app) { + $app->get("[/]", "AdminController:index"); + $app->get("/category[/]", "CategoryController:index"); + $app->get("/category/create", "CategoryController:create"); + $app->get("/category/{id}", "CategoryController:edit"); + $app->post("/category/create", "CategoryController:store"); + $app->post("/category/{id}", "CategoryController:update"); + $app->get("/category/delete/{id}", "CategoryController:destroy"); })->add($middleware->auth(1)); -$app->group("/painel/professor",function() use ($app){ - $app->get("[/]","ProfessorController:index"); +$app->group("/painel/professor", function () use ($app) { + $app->get("[/]", "ProfessorController:index"); })->add($middleware->auth(2)); $app->run(); \ No newline at end of file diff --git a/src/Middleware.php b/src/Middleware.php index 6a7cc02..a54ee75 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -11,7 +11,11 @@ class Middleware { - + /* + * Checa se o usuário tem permissão para acessar a página + * caso não redireciona-o para a página a qual tem permissão. + * @return \Closure + */ public function auth($role){ $config = Load::file("/config.php"); @@ -38,6 +42,11 @@ public function auth($role){ } + /* + * Checa se o usuário está logado, caso sim, redireciona-o para + * a página a qual tem permissão. + * @return \Closure + */ public function checkLoggedIn() { diff --git a/src/db/migrations/20200317003919_create_table_categories.php b/src/db/migrations/20200317003919_create_table_categories.php new file mode 100644 index 0000000..29325aa --- /dev/null +++ b/src/db/migrations/20200317003919_create_table_categories.php @@ -0,0 +1,38 @@ +table("categories"); + $table->addColumn("name", "string", ["limit" => 255]); + $table->addColumn("created_at", 'timestamp', ['default' => 'CURRENT_TIMESTAMP']); + $table->addColumn("updated_at", 'timestamp', ['default' => 'CURRENT_TIMESTAMP']); + $table->create(); + } +} diff --git a/src/db/migrations/20200317003951_create_table_posts.php b/src/db/migrations/20200317003951_create_table_posts.php new file mode 100644 index 0000000..6f5be0e --- /dev/null +++ b/src/db/migrations/20200317003951_create_table_posts.php @@ -0,0 +1,44 @@ +table("posts"); + $table->addColumn("title", "string", ["limit" => 255]); + $table->addColumn("content", "text"); + $table->addColumn('status', 'integer'); + $table->addColumn('category_id', 'integer', ['null' => true]); + $table->addColumn('user_id', 'integer', ['null' => true]); + $table->addForeignKey('user_id', 'users', 'id', ['delete' => 'SET_NULL']); + $table->addForeignKey('category_id', 'categories', 'id', ['delete' => 'SET_NULL']); + $table->addColumn("created_at", 'timestamp', ['default' => 'CURRENT_TIMESTAMP']); + $table->addColumn("updated_at", 'timestamp', ['default' => 'CURRENT_TIMESTAMP']); + $table->create(); + } +} diff --git a/views/admin/categories/create.html b/views/admin/categories/create.html new file mode 100644 index 0000000..6f9885d --- /dev/null +++ b/views/admin/categories/create.html @@ -0,0 +1,18 @@ +{% extends "admin/painel.html" %} +{% block content %} +

Categorias

+
+
+
+
+ + + {{ erros("name") }} + {{ message("name") }} +
+ +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/views/admin/categories/edit.html b/views/admin/categories/edit.html new file mode 100644 index 0000000..7cb7bca --- /dev/null +++ b/views/admin/categories/edit.html @@ -0,0 +1,18 @@ +{% extends "admin/painel.html" %} +{% block content %} +

Categorias

+
+
+
+
+ + + {{ erros("name") }} + {{ message("name") }} +
+ +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/views/admin/categories/index.html b/views/admin/categories/index.html new file mode 100644 index 0000000..0708f5b --- /dev/null +++ b/views/admin/categories/index.html @@ -0,0 +1,55 @@ +{% extends "admin/painel.html" %} +{% block content %} +

Categorias

+
+
+
+ + +
+ + + + + + + + + + + + {% for category in categories %} + + + + + + + + + + {% endfor %} + + + +
IDNOMECRIADO EMATUALIZADO EMOPÇÔES
{{ category.id }}{{ category.name }}{{ timeAgo(category.created_at) }}{{ timeAgo(category.updated_at) }} + + +
+ +
+ +
+ +
+
+ +{% endblock %} \ No newline at end of file diff --git a/views/admin/master.html b/views/admin/master.html index 0de6b1c..1cb5b9c 100755 --- a/views/admin/master.html +++ b/views/admin/master.html @@ -33,7 +33,7 @@
- +
- - - - + {% block menu %}{% endblock %} @@ -268,7 +104,7 @@

{{ page_name ?? "" }}

- {% block master %} + {% block content %} {% endblock %}
diff --git a/views/admin/painel.html b/views/admin/painel.html old mode 100755 new mode 100644 index a570d59..0e6b713 --- a/views/admin/painel.html +++ b/views/admin/painel.html @@ -1,7 +1,62 @@ -{% extends 'master.html' %} - -{% block master %} -

{{ title }}

-

Bem vindo {{ admin().nome }}

-Sair do sistema +{% extends 'admin/master.html' %} +{% block menu %} + {% endblock %} \ No newline at end of file diff --git a/views/admin/post/index.html b/views/admin/post/index.html new file mode 100644 index 0000000..431c5ea --- /dev/null +++ b/views/admin/post/index.html @@ -0,0 +1,74 @@ +{% extends "admin/painel.html" %} +{% block content %} +

Novo Post

+
+
+
+
+ + +
+
+ +
+ + +
+ + + + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDTÍTULOCATEGORIACAPAAUTORCRIADO EMOPÇÔES
1Douglasdcdouglas64@gmail.comdcdouglas64@gmail.comcelularR$ renda + + + +
+ +
+ +
+ +
+
+ +{% endblock %} \ No newline at end of file