102 lines
3.9 KiB
PHP
102 lines
3.9 KiB
PHP
<?php
|
|
/**
|
|
* app/plugins/dnd/controllers/admin/gods.php
|
|
*
|
|
* This is the gods admin controller.
|
|
*
|
|
* @package TTE Dungeons & Dragons
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@tabletopelite.com>
|
|
* @link https://TableTopElite.com
|
|
*/
|
|
namespace TheTempusProject\Controllers\Admin;
|
|
|
|
use TheTempusProject\Houdini\Classes\Issues;
|
|
use TheTempusProject\Houdini\Classes\Views;
|
|
use TheTempusProject\Houdini\Classes\Components;
|
|
use TheTempusProject\Bedrock\Functions\Input;
|
|
use TheTempusProject\Bedrock\Functions\Check;
|
|
use TheTempusProject\Classes\Forms;
|
|
use TheTempusProject\Classes\AdminController;
|
|
use TheTempusProject\Models\Gods as GodsModel;
|
|
use TheTempusProject\Houdini\Classes\Forms as HoudiniForms;
|
|
|
|
class Gods extends AdminController {
|
|
protected static $gods;
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
self::$title = 'Admin - D&D Gods';
|
|
self::$gods = new GodsModel;
|
|
}
|
|
|
|
public function index( $data = null ) {
|
|
Views::view( 'dnd.admin.gods.list', self::$gods->list() );
|
|
}
|
|
|
|
public function view( $id = null ) {
|
|
$data = self::$gods->findById( $id );
|
|
if ( $data == false ) {
|
|
Issues::add( 'error', 'God not found.' );
|
|
return $this->index();
|
|
}
|
|
Views::view( 'dnd.admin.gods.view', $data );
|
|
}
|
|
|
|
public function create( $data = null ) {
|
|
Components::set( 'privacyDropdown', Views::simpleView('dnd.forms.privacyDropdown') );
|
|
Components::set( 'versionDropdown', Views::simpleView('dnd.forms.versionDropdown') );
|
|
$sourcebookSelect = HoudiniForms::getFormFieldHtml( 'sourcebookID', 'SourceBook', 'select', 'none', self::$sourcebooks->simpleList() );
|
|
Components::set( 'sourcebookSelect', $sourcebookSelect );
|
|
if ( !Input::exists( 'submit' ) ) {
|
|
Views::view( 'dnd.admin.gods.create' );
|
|
}
|
|
if ( !Forms::check( 'createGod' ) ) {
|
|
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
|
return Views::view( 'dnd.admin.gods.create' );
|
|
}
|
|
if ( self::$gods->create( Input::post( 'name' )) ) {
|
|
Issues::add( 'success', 'God created' );
|
|
return $this->index();
|
|
} else {
|
|
Issues::add( 'error', 'There was an error creating your god.' );
|
|
return Views::view( 'dnd.admin.gods.create' );
|
|
}
|
|
}
|
|
|
|
public function edit( $id = null ) {
|
|
$data = self::$gods->findById( $id );
|
|
if ( false == $data ) {
|
|
return $this->index();
|
|
}
|
|
Components::set( 'privacyDropdown', Views::simpleView('dnd.forms.privacyDropdown', $data) );
|
|
Components::set( 'versionDropdown', Views::simpleView('dnd.forms.versionDropdown', $data) );
|
|
$sourcebookSelect = HoudiniForms::getFormFieldHtml( 'sourcebookID', 'SourceBook', 'select', $data->sourcebookID, self::$sourcebooks->simpleList() );
|
|
Components::set( 'sourcebookSelect', $sourcebookSelect );
|
|
if ( !Input::exists( 'submit' ) ) {
|
|
return Views::view( 'dnd.admin.gods.edit', $data );
|
|
}
|
|
if ( !Forms::check( 'editGod' ) ) {
|
|
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
|
return Views::view( 'dnd.admin.gods.edit', $data );
|
|
}
|
|
if ( self::$gods->update( $id, Input::post( 'title' ), Input::post( 'suggestion' ), Input::post( 'approved' ) ) ) {
|
|
Issues::add( 'success', 'God updated' );
|
|
} else {
|
|
return Views::view( 'dnd.admin.gods.edit', $data );
|
|
}
|
|
}
|
|
|
|
public function delete( $data = null ) {
|
|
if ( Input::exists( 'submit' ) ) {
|
|
$data = Input::post( 'GD_' );
|
|
}
|
|
if ( !self::$gods->delete( $data ) ) {
|
|
Issues::add( 'error', 'There was an error with your request.' );
|
|
} else {
|
|
Issues::add( 'success', 'God has been deleted' );
|
|
}
|
|
$this->index();
|
|
}
|
|
}
|