<?php
namespace App\Controller;
use App\Entity\ForumTopics;
use App\Entity\KnowledgeBase;
use App\Entity\KnowledgeBaseCategories;
use App\Entity\User;
use App\Service\GlobalFunctions;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class KbController extends AbstractController
{
/**
* @Route("/kb", name="kb")
*/
public function index()
{
$GetCategory = $this->getDoctrine()->getRepository(KnowledgeBaseCategories::class)->findBy(['Public' => 1]);
$GetAdminCategory = $this->getDoctrine()->getRepository(KnowledgeBaseCategories::class)->findBy(['Public' => 0]);
$GetTopics = $this->getDoctrine()->getRepository(ForumTopics::class)->findAll();
return $this->render('kb/index.html.twig', [
'categories' => $GetCategory,
'admincategories' => $GetAdminCategory,
'forum_topics' => $GetTopics,
]);
}
public function article($article_slug)
{
$GetArticle = $this->getDoctrine()->getRepository(KnowledgeBase::class)->findOneBy(['KBSlug' => $article_slug]);
$GetCategory = $GetArticle->getCategory();
$GetCategoryArticles = $GetCategory->getArticles();
$GetAuthor = $this->getDoctrine()->getRepository(User::class)->find($GetArticle->getAuthorId());
if (false !== strpos($GetArticle->getOptions(), '[is_query_article]')) {
@$EntityId = $_GET['id'];
if (!isset($EntityId)) {
$EntityId = 'select';
}
$template = 'kb/query.html.twig';
/*$GlobalFn = new GlobalFunctions();
$ShowHeaders = explode(",",$GlobalFn->parse_filter_options($GetArticle->getOptions(), "entity_output_cols"));
$Entity = $GlobalFn->parse_filter_options($GetArticle->getOptions(), "entity_name");
$EntitySearch = $this->getDoctrine()->getRepository($Entity::class)->findBy(['Slug'=>$category_slug]);*/
} else {
$template = 'kb/article.html.twig';
$entity_id = 0;
$ShowHeaders = [];
}
return $this->render($template, [
'controller_name' => 'KbController',
'article_info' => $GetArticle,
'category_info' => $GetCategory,
'author_info' => $GetAuthor,
'other_articles' => $GetCategoryArticles,
]);
}
public function category($category_slug)
{
$GetCategory = $this->getDoctrine()->getRepository(KnowledgeBaseCategories::class)->findOneBy(['Slug' => $category_slug]);
$GetCategoryArticles = $GetCategory->getArticles();
return $this->render('kb/category.html.twig', [
'category_info' => $GetCategory,
'category_articles' => $GetCategoryArticles,
]);
}
public function categoryBlank()
{
return $this->redirectToRoute('kb');
}
public function search()
{
if (isset($_GET['search_term'])) {
$search_term = $_GET['search_term'];
}
$conn = $this->getDoctrine()->getManager()->getConnection();
$sql = "
SELECT * FROM knowledge_base INNER JOIN knowledge_base_categories ON knowledge_base.category_id=knowledge_base_categories.id WHERE (article_title LIKE '%$search_term%' OR article LIKE '%$search_term%') AND publish_date<now() AND knowledge_base_categories.public='1'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$GetSearch = $stmt->fetchAll();
return $this->render('kb/search.html.twig', [
'results' => $GetSearch,
'search_term' => $search_term,
]);
}
}