58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Projects;
|
|
|
|
use App\Controllers\BaseController;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
|
|
class CommentsController extends BaseController
|
|
{
|
|
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
|
|
if (!defined('AUTHENTICATED') || AUTHENTICATED === false) {
|
|
die('NO ACCESS');
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
// Default action
|
|
}
|
|
|
|
public function getComments(int $foreignID, string $tablename): ResponseInterface
|
|
{
|
|
$comments = \Comment::getComments($foreignID, $tablename);
|
|
|
|
return $this->json($comments);
|
|
}
|
|
|
|
public function getComment(int $commentID): ResponseInterface
|
|
{
|
|
$comment = \Comment::find($commentID);
|
|
|
|
$comment->comment = base64_decode($comment->comment);
|
|
|
|
return $this->json($comment);
|
|
}
|
|
|
|
public function addComment(int $foreignID, string $tablename): ResponseInterface
|
|
{
|
|
$commentID = \Comment::addComment($foreignID, $tablename);
|
|
|
|
return $this->json($commentID);
|
|
}
|
|
|
|
public function saveComment(int $commentID): ResponseInterface
|
|
{
|
|
$comment = $this->request->getPost('comment');
|
|
|
|
$comment = base64_encode($comment);
|
|
|
|
\Comment::whereId($commentID)->update(['comment' => $comment]);
|
|
|
|
return $this->json(['success' => true]);
|
|
}
|
|
}
|