示例#1
0
文件: add.php 项目: sedvis/mysql-nd
<?php

require_once '../entity/CommentRep.php';
require_once '../entity/ThemeRep.php';
if (isset($_GET['theme_id']) && is_numeric($_GET['theme_id'])) {
    $comment = new Comment();
    $comment->setDate((new DateTime('now'))->format('Y-m-d H:i:s'));
    $comment->setAuthor(isset($_GET['author']) ? $_GET['author'] : 'bet koks autorius');
    $comment->setComment(isset($_GET['comment']) ? $_GET['comment'] : 'bet koks komentaras');
    $comment->setThemeId($_GET['theme_id']);
    $themeRep = new ThemeRep();
    $theme = $themeRep->findById($_GET['theme_id']);
    if (empty($theme)) {
        echo 'Tema su id ' . $_GET['theme_id'] . ' neegzistuoja';
        return;
    }
    $themeRep->increaseCommentCount($theme);
    $commentRep = new CommentRep();
    $commentRep->save($comment);
    echo 'Komentaras pridetas.';
} else {
    echo 'Reikalingas temos id.';
}
示例#2
0
文件: list.php 项目: sedvis/mysql-nd
<?php

require_once '../entity/ThemeRep.php';
$themeRep = new ThemeRep();
$themes = $themeRep->getAll();
foreach ($themes as $theme) {
    echo '<strong>Temos pavadinimas: </strong>' . $theme->getTitle() . ' <strong>Data: </strong> ' . $theme->getDate() . ' <strong>Komentaru skaicius: </strong> ' . $theme->getCommentsCount() . '<br>';
}