. * */ namespace Vvveb\Controller\Content; use function Vvveb\__; use Vvveb\Controller\Base; use function Vvveb\model; class Comment extends Base { protected $type = 'comment'; function save() { $type = $this->type; $comment_id = $this->request->get[$type . '_id'] ?? false; $comment = $this->request->post[$type] ?? false; if ($comment) { $comments = model($type); if ($comment_id) { $result = $comments->edit([$type => $comment, $type . '_id' => $comment_id]); } else { $result = $comments->add([$type => $comment]); } if ($result && isset($result[$type])) { $this->view->success[] = __('Saved!'); } else { $this->view->errors[] = __('Error saving!'); } } return $this->index(); } function index() { $type = $this->type; $comments = model($type); $comment_id = $this->request->get[$type . '_id'] ?? false; $options = [ 'type' => $this->type, $type . '_id' => $comment_id, ] + $this->global; unset($options['user_id']); $this->view->$type = $comments->get($options); } }