]> git.leonardobizzoni.com Git - highschool-graduation-project/commitdiff
Setup pagina vtuber
authorLeonardoBizzoni <leo2002714@gmail.com>
Mon, 18 Apr 2022 13:53:59 +0000 (15:53 +0200)
committerLeonardoBizzoni <leo2002714@gmail.com>
Mon, 18 Apr 2022 13:53:59 +0000 (15:53 +0200)
www/Migrations/m_1650287984_vtuberTable.php [new file with mode: 0644]
www/controllers/SiteController.php
www/core/BaseModel.php
www/models/Vtubers.php [new file with mode: 0644]
www/pub/index.php
www/views/layouts/main.php
www/views/live.php [new file with mode: 0644]

diff --git a/www/Migrations/m_1650287984_vtuberTable.php b/www/Migrations/m_1650287984_vtuberTable.php
new file mode 100644 (file)
index 0000000..899bca9
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+use app\core\Application;
+
+class m_1650287984_vtuberTable
+{
+    public function up()
+    {
+        $db = Application::$app->db;
+        $sql = "CREATE TABLE vtubers (
+                id INT AUTO_INCREMENT PRIMARY KEY,
+                username VARCHAR(255) NOT NULL,
+                link VARCHAR(512) NOT NULL
+              ) ENGINE=INNODB;";
+        $db->pdo->exec($sql);
+    }
+
+    public function down()
+    {
+        $db = Application::$app->db;
+        $sql = "DROP TABLE vtuber";
+        $db->pdo->exec($sql);
+    }
+}
+?>
index 913bf56e740e3a025d2e01241791e1b281a46c00..432a4f083c77cc2fc2c2cb499083af3bfa2c2494 100644 (file)
@@ -3,6 +3,7 @@ namespace app\controllers;
 
 use app\core\BaseController;
 use app\core\Request;
+use app\models\Vtubers;
 
 class SiteController extends BaseController {
     public function home() {
@@ -13,16 +14,18 @@ class SiteController extends BaseController {
         return $this->render("home", $params);
     }
 
-    public function contact() {
-        return $this->render("contact");
-    }
-
-    public function handleContact(Request $req) {
-        $body = $req->getBody();
+    public function live(Request $req) {
+        $errors = [];
+        $vtuberModel = new Vtubers;
 
-        # $body validation
+        if ($req->getMethod() == "post") {
+            $vtuberModel->loadData($req->getBody());
+            $vtuberModel->getVtuberName();
 
-        return "Handling submitted data";
+            if ($vtuberModel->validate() && $vtuberModel->register()) {
+                return "Success";
+            }
+        }
+        return $this->render("live", [ "model" => $vtuberModel ]);
     }
 }
-?>
index 9960ffee9a0c372341057d96f36f56215108e0eb..0a6e6d8cc0c631c82e41fe052ddeddad82f248f0 100644 (file)
@@ -63,6 +63,7 @@ abstract class BaseModel {
             }
         }
 
+        echo " <script>alert('validate fatto!')</script>";
         return empty($this->errors);
     }
 
diff --git a/www/models/Vtubers.php b/www/models/Vtubers.php
new file mode 100644 (file)
index 0000000..894f66d
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace app\models;
+
+use app\core\DbModel;
+
+class Vtubers extends DbModel
+{
+    public string $username = "";
+    public string $link = "";
+
+    public function tableName(): string
+    {
+        return "vtubers";
+    }
+
+    public function attributes(): array {
+        return [ "username", "link" ];
+    }
+
+    public function register()
+    {
+        return $this->save();
+    }
+
+    public function rules(): array
+    {
+        return [
+            "username" => [self::RULE_REQUIRED],
+            "link" => [self::RULE_REQUIRED, [self::RULE_UNIQUE, "class" => self::class ]],
+        ];
+    }
+
+    public function getVtuberName() {
+        $this->username = "i got you bro";
+    }
+}
index 57aa14d0687bdd64306313c2c9eb83777dbcc5d3..a877dcefdb018677bbc6b00c14a1b695b33f97f2 100644 (file)
@@ -19,8 +19,8 @@ $app = new Application(dirname(__DIR__), $config);
 
 $app->router->get("/", [SiteController::class, "home"]);
 
-$app->router->get("/contact", [SiteController::class, "contact"]);
-$app->router->post("/contact", [SiteController::class, "handleContact"]);
+$app->router->get("/live", [SiteController::class, "live"]);
+$app->router->post("/live", [SiteController::class, "live"]);
 
 # User authentication
 $app->router->get("/login", [AuthController::class, "login"]);
index 52b316eaf69516a7090c9bd868836d2b3a6b4e8a..1f13f44169e410dffaad4f27155373fb83e64475 100644 (file)
@@ -18,7 +18,7 @@
             <div class="collapse navbar-collapse" id="navbarNav" style="display: flex;">
                 <ul class="navbar-nav">
                     <li class="nav-item">
-                        <a class="nav-link" href="/contact">Contact</a>
+                        <a class="nav-link" href="/live">Live</a>
                     </li>
                 </ul>
 
diff --git a/www/views/live.php b/www/views/live.php
new file mode 100644 (file)
index 0000000..c918670
--- /dev/null
@@ -0,0 +1,8 @@
+<h1>Live page</h1>
+
+<div class="container">
+    <?php $form = app\core\forms\Form::begin("", "post"); ?>
+    <?php echo $form->field($model, "Link"); ?>
+    <button type="submit" class="btn btn-primary">Submit</button>
+    <?php app\core\forms\Form::end(); ?>
+</div>