Initial commit
This commit is contained in:
280
app/plugins/dnd/controllers/characters.php
Normal file
280
app/plugins/dnd/controllers/characters.php
Normal file
@ -0,0 +1,280 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/controllers/creator.php
|
||||
*
|
||||
* This is the Character Creation controller.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @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\Houdini\Classes\Views;
|
||||
use TheTempusProject\Classes\Controller;
|
||||
use TheTempusProject\Models\Characters as CharacterModel;
|
||||
use TheTempusProject\Models\Classes;
|
||||
use TheTempusProject\Models\Races;
|
||||
use TheTempusProject\Houdini\Classes\Components;
|
||||
|
||||
class Characters extends Controller {
|
||||
protected static $characters;
|
||||
protected static $classes;
|
||||
protected static $races;
|
||||
|
||||
public function index() {
|
||||
self::$title = 'Character Creator - {SITENAME}';
|
||||
self::$pageDescription = 'This is for creating and managing various TT characters.';
|
||||
self::$characters = new CharacterModel;
|
||||
self::$classes = new Classes;
|
||||
self::$races = new Races;
|
||||
Views::view( 'dnd.index' );
|
||||
|
||||
$characterListView = Views::simpleView('dnd.characters.list', self::$characters->byUser() );
|
||||
Components::set( 'characterList', $characterListView );
|
||||
}
|
||||
|
||||
public function characters( $id = 0 ) {}
|
||||
public function editCharacter() {}
|
||||
public function deleteCharacter() {}
|
||||
|
||||
public function createCharacter() {
|
||||
if ( ! Input::exists() ) {
|
||||
return $this->createCharacterScreenOne();
|
||||
}
|
||||
return $this->saveAndLoad();
|
||||
}
|
||||
|
||||
private function saveAndLoad() {
|
||||
if ( empty( Input::post( 'characterID' ) ) ) {
|
||||
if ( ! Forms::check( 'createCharacterScreenOne' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return $this->createCharacterScreenOne();
|
||||
}
|
||||
$avatar = ''; // @TODO: come back and actually add the avatar upload functionality
|
||||
$id = self::$characters->createFromScreenOne(
|
||||
Input::post('first_name'),
|
||||
Input::post('last_name'),
|
||||
Input::post('privacy'),
|
||||
Input::post('version'),
|
||||
Input::post('prefix'),
|
||||
Input::post('middle_name'),
|
||||
Input::post('suffix'),
|
||||
$avatar
|
||||
);
|
||||
if ( ! $id ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return $this->createCharacterScreenOne();
|
||||
}
|
||||
} else {
|
||||
$id = Input::post( 'characterID' );
|
||||
}
|
||||
$character = $this->findCharacterOrFail( $id );
|
||||
Components::set( 'characterID', $character->ID );
|
||||
if ( empty( $character->raceID ) ) {
|
||||
return $this->createCharacterScreenTwo( $character->ID );
|
||||
}
|
||||
if ( empty( $character->classID ) ) {
|
||||
return $this->createCharacterScreenThree( $character->ID );
|
||||
}
|
||||
if ( empty( $character->level ) ) {
|
||||
return $this->createCharacterScreenFour( $character->ID );
|
||||
}
|
||||
if ( empty( $character->strength ) ) {
|
||||
return $this->createCharacterScreenFive( $character->ID );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if ( empty( $character->strength ) ) {
|
||||
return $this->createCharacterScreenFive( $character->ID );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Name, Version, Privacy
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenOne() {
|
||||
Components::set( 'privacyDropdown', Views::simpleView('dnd.forms.privacyDropdown') );
|
||||
Components::set( 'versionDropdown', Views::simpleView('dnd.forms.versionDropdown') );
|
||||
Components::set( 'hitpointRollDropdown', Views::simpleView('dnd.forms.hitpointRollDropdown') );
|
||||
return Views::view( 'dnd.creator.screen1' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Race
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenTwo( $id ) {
|
||||
Components::set( 'raceSelect', self::$races->getAll() );
|
||||
if ( ! Forms::check( 'createCharacterScreenTwo' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen2' );
|
||||
}
|
||||
$result = self::$characters->updateFromScreenTwo(
|
||||
Input::post('race')
|
||||
);
|
||||
if ( ! $result ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen2' );
|
||||
}
|
||||
return $this->createCharacterScreenThree( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenThree( $id ) {
|
||||
Components::set( 'classSelect', self::$classes->getAll() );
|
||||
if ( ! Forms::check( 'createCharacterScreenThree' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen3' );
|
||||
}
|
||||
$result = self::$characters->updateFromScreenThree(
|
||||
Input::post('class')
|
||||
);
|
||||
if ( ! $result ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen3' );
|
||||
}
|
||||
return $this->createCharacterScreenFour( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Level / Race & class selections
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenFour( $id ) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ability Scores - Str, Dex, Int, Wis, Char, Con
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenFive( $id ) {
|
||||
if ( ! Forms::check( 'createCharacterScreenFive' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen5' );
|
||||
}
|
||||
$result = self::$characters->updateFromScreenFive(
|
||||
Input::post('strength'),
|
||||
Input::post('dexterity'),
|
||||
Input::post('constitution'),
|
||||
Input::post('charisma'),
|
||||
Input::post('intelligence'),
|
||||
Input::post('wisdom')
|
||||
);
|
||||
if ( ! $result ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen5' );
|
||||
}
|
||||
return $this->createCharacterScreenSix( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Character Info - Religion, family, associations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenSix( $id ) {
|
||||
Components::set( 'orderDropdown', Views::simpleView('dnd.forms.orderDropdown') );
|
||||
Components::set( 'moralityDropdown', Views::simpleView('dnd.forms.moralityDropdown') );
|
||||
if ( ! Forms::check( 'createCharacterScreenSix' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen6' );
|
||||
}
|
||||
$result = self::$characters->updateFromScreenSix(
|
||||
Input::post('order'),
|
||||
Input::post('morality'),
|
||||
Input::post('story'),
|
||||
Input::post('allies'),
|
||||
Input::post('enemies'),
|
||||
Input::post('organizations'),
|
||||
Input::post('flaws'),
|
||||
Input::post('bonds'),
|
||||
Input::post('ideals'),
|
||||
Input::post('traits'),
|
||||
Input::post('oaths'),
|
||||
Input::post('motto'),
|
||||
Input::post('creed')
|
||||
);
|
||||
if ( ! $result ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen6' );
|
||||
}
|
||||
return $this->createCharacterScreenSeven( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Character Info - Appearance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenSeven( $id ) {
|
||||
if ( ! Forms::check( 'createCharacterScreenSeven' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen7' );
|
||||
}
|
||||
$result = self::$characters->updateFromScreenSeven(
|
||||
Input::post('age'),
|
||||
Input::post('height'),
|
||||
Input::post('weight'),
|
||||
Input::post('eyes'),
|
||||
Input::post('skin'),
|
||||
Input::post('hair'),
|
||||
Input::post('gender'),
|
||||
Input::post('appearance')
|
||||
);
|
||||
if ( ! $result ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen7' );
|
||||
}
|
||||
return $this->createCharacterScreenEight( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Equipment and Inventory
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function createCharacterScreenEight( $id ) {
|
||||
if ( ! Forms::check( 'createCharacterScreenEight' ) ) {
|
||||
Issues::add( 'error', [ 'There was an error with your form.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen8' );
|
||||
}
|
||||
$result = self::$characters->updateFromScreenEight(
|
||||
);
|
||||
if ( ! $result ) {
|
||||
Issues::add( 'error', [ 'There was an error saving your character.' => Check::userErrors() ] );
|
||||
return Views::view( 'dnd.creator.screen8' );
|
||||
}
|
||||
Session::flash( 'success', 'Character Created' );
|
||||
Redirect::to( 'dnd/index' );
|
||||
}
|
||||
|
||||
private function findCharacterOrFail( $id = null ) {
|
||||
$character = self::$characters->findById( $id );
|
||||
if ( $character == false ) {
|
||||
Session::flash( 'error', 'Character not found.' );
|
||||
Redirect::to( 'dnd/index/' );
|
||||
}
|
||||
if ( $character->createdBy != App::$activeUser->ID ) {
|
||||
Session::flash( 'error', 'Permissions Error.' );
|
||||
Redirect::to( 'dnd/index/' );
|
||||
}
|
||||
return $character;
|
||||
}
|
||||
}
|
||||
|
||||
// Associations
|
||||
// ( family and friends )
|
Reference in New Issue
Block a user