99 lines
4.2 KiB
PHP
99 lines
4.2 KiB
PHP
<?php
|
|
/**
|
|
* app/plugins/tablefinder/controllers/tablefinder.php
|
|
*
|
|
* This is the table finder controller.
|
|
*
|
|
* @package TP TableFinder
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
namespace TheTempusProject\Controllers;
|
|
|
|
use TheTempusProject\Bedrock\Functions\Check;
|
|
use TheTempusProject\Bedrock\Functions\Input;
|
|
use TheTempusProject\Hermes\Functions\Redirect;
|
|
use TheTempusProject\Bedrock\Functions\Session;
|
|
use TheTempusProject\Houdini\Classes\Issues;
|
|
use TheTempusProject\Houdini\Classes\Views;
|
|
use TheTempusProject\Classes\Controller;
|
|
use TheTempusProject\Classes\Forms;
|
|
use TheTempusProject\Models\Tables;
|
|
use TheTempusProject\TheTempusProject as App;
|
|
use TheTempusProject\Models\Comments as CommentsModel;
|
|
use TheTempusProject\Plugins\Comments;
|
|
use TheTempusProject\Houdini\Classes\Components;
|
|
|
|
class TableFinder extends Controller {
|
|
protected static $suggestions;
|
|
protected static $comments;
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
if ( !App::$isLoggedIn ) {
|
|
Session::flash( 'notice', 'You must be logged in to use this feature.' );
|
|
return Redirect::home();
|
|
}
|
|
self::$suggestions = new Tables;
|
|
self::$title = 'Table Finder - {SITENAME}';
|
|
self::$pageDescription = 'On this page you can find or create a new table. Tables are essentially just a group of players who meet online or in-person to play tabletop games..';
|
|
}
|
|
|
|
public function index() {
|
|
Views::view( 'suggestions.list', self::$suggestions->recent() );
|
|
}
|
|
|
|
public function view( $id = null ) {
|
|
$data = self::$suggestions->findById( $id );
|
|
if ( $data == false ) {
|
|
Issues::add( 'error', 'Suggestion not found.' );
|
|
return $this->index();
|
|
}
|
|
if ( empty( self::$comments ) ) {
|
|
self::$comments = new CommentsModel;
|
|
}
|
|
if ( Input::exists( 'contentId' ) ) {
|
|
$this->comments( 'post', Input::post( 'contentId' ) );
|
|
}
|
|
Components::set( 'CONTENT_ID', $id );
|
|
Components::set( 'COMMENT_TYPE', 'suggestions' );
|
|
Components::set( 'NEWCOMMENT', Views::simpleView( 'comments.create' ) );
|
|
Components::set( 'count', self::$comments->count( 'suggestion', $id ) );
|
|
Components::set( 'COMMENTS', Views::simpleView( 'comments.list', self::$comments->display( 10, self::$suggestions->tableName, $id ) ) );
|
|
Views::view( 'suggestions.view', $data );
|
|
}
|
|
|
|
public function create() {
|
|
if ( !Input::exists() ) {
|
|
return Views::view( 'suggestions.create' );
|
|
}
|
|
if ( !Forms::check( 'newSuggestion' ) ) {
|
|
Issues::add( 'error', [ 'There was an error with your suggestion.' => Check::userErrors() ] );
|
|
return Views::view( 'suggestions.create' );
|
|
}
|
|
if ( !self::$suggestions->create( Input::post( 'title' ), Input::post( 'suggestion' ) ) ) {
|
|
Issues::add( 'error', [ 'There was an error with your suggestion.' => Check::userErrors() ] );
|
|
return Views::view( 'suggestions.create' );
|
|
}
|
|
Session::flash( 'success', 'Your Suggestion has been received. We must verify all suggestions before they are published, but as long as it doesn\'t violate our code of conduct, it should be available to view and comment on publicly within 24 hours.' );
|
|
Redirect::to( 'suggestions/index' );
|
|
}
|
|
|
|
public function edit( $data = null ) {
|
|
if ( !Input::exists( 'submit' ) ) {
|
|
return Views::view( 'suggestions.edit', self::$suggestions->findById( $data ) );
|
|
}
|
|
if ( !Forms::check( 'editSuggestion' ) ) {
|
|
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
|
return Views::view( 'suggestions.edit', self::$suggestions->findById( $data ) );
|
|
}
|
|
if ( self::$suggestions->update( $data, Input::post( 'title' ), Input::post( 'suggestion' ) ) ) {
|
|
Issues::add( 'success', 'Suggestion updated' );
|
|
} else {
|
|
return Views::view( 'suggestions.edit', self::$suggestions->findById( $data ) );
|
|
}
|
|
$this->index();
|
|
}
|
|
} |