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