Initial commit
This commit is contained in:
101
app/plugins/dnd/controllers/admin/monsters.php
Normal file
101
app/plugins/dnd/controllers/admin/monsters.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/controllers/admin/monsters.php
|
||||
*
|
||||
* This is the monsters 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\Monsters as MonstersModel;
|
||||
use TheTempusProject\Houdini\Classes\Forms as HoudiniForms;
|
||||
|
||||
class Monsters extends AdminController {
|
||||
protected static $monsters;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$title = 'Admin - D&D Monsters';
|
||||
self::$monsters = new MonstersModel;
|
||||
}
|
||||
|
||||
public function index( $data = null ) {
|
||||
Views::view( 'dnd.admin.monsters.list', self::$monsters->list() );
|
||||
}
|
||||
|
||||
public function view( $id = null ) {
|
||||
$data = self::$monsters->findById( $id );
|
||||
if ( $data == false ) {
|
||||
Issues::add( 'error', 'Monster not found.' );
|
||||
return $this->index();
|
||||
}
|
||||
Views::view( 'dnd.admin.monsters.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.monsters.create' );
|
||||
}
|
||||
if ( !Forms::check( 'createMonster' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.admin.monsters.create' );
|
||||
}
|
||||
if ( self::$monsters->create( Input::post( 'name' )) ) {
|
||||
Issues::add( 'success', 'Monster created' );
|
||||
return $this->index();
|
||||
} else {
|
||||
Issues::add( 'error', 'There was an error creating your monster.' );
|
||||
return Views::view( 'dnd.admin.monsters.create' );
|
||||
}
|
||||
}
|
||||
|
||||
public function edit( $id = null ) {
|
||||
$data = self::$monsters->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.monsters.edit', $data );
|
||||
}
|
||||
if ( !Forms::check( 'editMonster' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your request.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.admin.monsters.edit', $data );
|
||||
}
|
||||
if ( self::$monsters->update( $id, Input::post( 'title' ), Input::post( 'suggestion' ), Input::post( 'approved' ) ) ) {
|
||||
Issues::add( 'success', 'Monster updated' );
|
||||
} else {
|
||||
return Views::view( 'dnd.admin.monsters.edit', $data );
|
||||
}
|
||||
}
|
||||
|
||||
public function delete( $data = null ) {
|
||||
if ( Input::exists( 'submit' ) ) {
|
||||
$data = Input::post( 'MO_' );
|
||||
}
|
||||
if ( !self::$monsters->delete( $data ) ) {
|
||||
Issues::add( 'error', 'There was an error with your request.' );
|
||||
} else {
|
||||
Issues::add( 'success', 'Monster has been deleted' );
|
||||
}
|
||||
$this->index();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user