amdp3-metaforums/Application/Controllers/IndexController.php

51 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2019-11-18 13:33:45 +00:00
<?php
namespace Application\Controllers;
use Application\HTTP\Request;
use Application\HTTP\Response;
use Application\Services\ServiceContainer;
2019-11-19 03:36:39 +00:00
use Application\Models\Category;
use Application\Models\Group;
use Application\Models\Thread;
2019-11-18 13:33:45 +00:00
class IndexController {
public function __construct() {
2019-11-20 05:19:02 +00:00
}
public function moderation(Request $request, Response $response) {
if(!ServiceContainer::Authentication()->isLoggedIn() || !ServiceContainer::Authentication()->user()->is_moderator) {
return $response->redirect("/");
}
$groups = Group::all();
$group = null;
$category = null;
if(isset($request->group)) {
$group = Group::find($request->group);
}
if(isset($request->category)) {
$category = Category::find($request->category);
$group = Group::find($category->group_id);
}
return $response->view('moderation', ['groups' => $groups, 'group' => $group, 'category' => $category ] );
2019-11-18 13:33:45 +00:00
}
public function index(Request $request, Response $response) {
2019-11-19 03:36:39 +00:00
$groups = Group::all();
$group = null;
$category = null;
$thread = null;
if(isset($request->group)) {
$group = Group::find($request->group);
}
if(isset($request->category)) {
$category = Category::find($request->category);
2019-11-20 05:19:02 +00:00
$group = Group::find($category->group_id);
2019-11-19 03:36:39 +00:00
}
if(isset($request->thread)) {
$thread = Thread::find($request->thread);
2019-11-20 05:19:02 +00:00
$category = Category::find($thread->category_id);
$group = Group::find($category->group_id);
2019-11-19 03:36:39 +00:00
}
return $response->view('index', ['groups' => $groups, 'group' => $group, 'category' => $category, 'thread' => $thread ] );
2019-11-18 13:33:45 +00:00
}
}