Initial commit
This commit is contained in:
297
app/plugins/dnd/models/characters.php
Normal file
297
app/plugins/dnd/models/characters.php
Normal file
@ -0,0 +1,297 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/characters.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_characters database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Bedrock\Functions\Date;
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Houdini\Classes\Filters;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
|
||||
class Characters extends DatabaseModel {
|
||||
public $tableName = 'dnd_characters';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'prefix', 'varchar', '128' ],
|
||||
[ 'first_name', 'varchar', '128' ],
|
||||
[ 'middle_name', 'varchar', '128' ],
|
||||
[ 'last_name', 'varchar', '128' ],
|
||||
[ 'suffix', 'varchar', '128' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'notes', 'text', '' ], // campaign notes
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'image', 'text', '' ],
|
||||
[ 'avatar', 'text', '' ],
|
||||
|
||||
// allignment
|
||||
[ 'morality', 'varchar', '16' ], // good, neutral, evil
|
||||
[ 'order', 'varchar', '16' ], // lawful, neutral, chaotic
|
||||
|
||||
// Appearance
|
||||
[ 'age', 'int', '4' ],
|
||||
[ 'height', 'varchar', '32' ],
|
||||
[ 'weight', 'varchar', '32' ],
|
||||
[ 'eyes', 'varchar', '32' ],
|
||||
[ 'skin', 'varchar', '32' ],
|
||||
[ 'hair', 'varchar', '32' ],
|
||||
[ 'gender', 'varchar', '32' ],
|
||||
|
||||
// Core
|
||||
[ 'raceID', 'int', '11' ],
|
||||
[ 'classID', 'int', '11' ],
|
||||
[ 'hitpoints', 'int', '5' ],
|
||||
[ 'current_hitpoints', 'int', '5' ],
|
||||
[ 'level', 'int', '4' ],
|
||||
[ 'experience', 'int', '12' ],
|
||||
|
||||
// Skills
|
||||
[ 'strength', 'int', '4' ],
|
||||
[ 'dexterity', 'int', '4' ],
|
||||
[ 'constitution', 'int', '4' ],
|
||||
[ 'charisma', 'int', '4' ],
|
||||
[ 'intelligence', 'int', '4' ],
|
||||
[ 'wisdom', 'int', '4' ],
|
||||
|
||||
// Expository
|
||||
[ 'story', 'text', '' ], // backstory
|
||||
[ 'appearance', 'text', '' ],
|
||||
[ 'allies', 'text', '' ],
|
||||
[ 'enemies', 'text', '' ],
|
||||
[ 'organizations', 'text', '' ],
|
||||
[ 'flaws', 'text', '' ],
|
||||
[ 'bonds', 'text', '' ],
|
||||
[ 'oaths', 'text', '' ],
|
||||
[ 'ideals', 'text', '' ],
|
||||
[ 'creed', 'text', '' ],
|
||||
[ 'motto', 'text', '' ],
|
||||
[ 'traits', 'text', '' ], // personality traits
|
||||
|
||||
// Currency
|
||||
[ 'copper', 'int', '12' ],
|
||||
[ 'silver', 'int', '12' ],
|
||||
[ 'gold', 'int', '12' ],
|
||||
[ 'platinum', 'int', '12' ],
|
||||
[ 'electrum', 'int', '12' ],
|
||||
|
||||
// [ 'armorclass', 'int', '4' ],
|
||||
// [ 'initiative', 'int', '4' ],
|
||||
// [ 'speed', 'int', '4' ],
|
||||
// [ 'proficiency', 'int', '4' ],
|
||||
// [ 'inspiration', 'int', '4' ],
|
||||
// [ 'alignment', 'varchar', '16' ],
|
||||
// [ 'background', 'varchar', '128' ],
|
||||
// [ 'languages', 'text', '' ],
|
||||
// [ 'equipment', 'text', '' ],
|
||||
// [ 'features', 'text', '' ],
|
||||
// [ 'spells', 'text', '' ],
|
||||
// [ 'skills', 'text', '' ],
|
||||
// [ 'saves', 'text', '' ],
|
||||
// [ 'bonuses', 'text', '' ],
|
||||
// [ 'inventory', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function createFromScreenOne( $first_name, $last_name, $privacy, $version, $prefix = '', $middle_name = '', $suffix = '', $avatar = '' ) {
|
||||
$fields = [
|
||||
// required
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
// optional
|
||||
'prefix' => $prefix,
|
||||
'middle_name' => $middle_name,
|
||||
'suffix' => $suffix,
|
||||
'avatar' => $avatar,
|
||||
];
|
||||
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'characterCreate' );
|
||||
Debug::error( "Character: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function updateFromScreenTwo( $id, $raceID ) {
|
||||
$fields = [
|
||||
'raceID' => $raceID,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateFromScreenThree( $id, $classID ) {
|
||||
$fields = [
|
||||
'classID' => $classID,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// public function updateFromScreenFour( $id, $name ) {
|
||||
// $fields = [
|
||||
// 'name' => $name,
|
||||
// ];
|
||||
// if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
// new CustomException( 'characterUpdate' );
|
||||
// Debug::error( "Character: $id not updated: $fields" );
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public function updateFromScreenFive( $id, $strength, $dexterity, $constitution, $charisma, $intelligence, $wisdom ) {
|
||||
$fields = [
|
||||
'strength' => $strength,
|
||||
'dexterity' => $dexterity,
|
||||
'constitution' => $constitution,
|
||||
'charisma' => $charisma,
|
||||
'intelligence' => $intelligence,
|
||||
'wisdom' => $wisdom,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateFromScreenSix( $id, $order, $morality, $story = '', $allies = '', $enemies = '', $organizations = '', $flaws = '', $bonds = '', $ideals = '', $traits = '', $oaths = '', $motto = '', $creed = '' ) {
|
||||
$fields = [
|
||||
'order' => $order,
|
||||
'morality' => $morality,
|
||||
'story' => $story,
|
||||
'allies' => $allies,
|
||||
'enemies' => $enemies,
|
||||
'organizations' => $organizations,
|
||||
'flaws' => $flaws,
|
||||
'bonds' => $bonds,
|
||||
'ideals' => $ideals,
|
||||
'traits' => $traits,
|
||||
'oaths' => $oaths,
|
||||
'motto' => $motto,
|
||||
'creed' => $creed,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateFromScreenSeven( $id, $age = '', $height = '', $weight = '', $eyes = '', $skin = '', $hair = '', $gender = '', $appearance = '' ) {
|
||||
$fields = [
|
||||
'age' => $age,
|
||||
'height' => $height,
|
||||
'weight' => $weight,
|
||||
'eyes' => $eyes,
|
||||
'skin' => $skin,
|
||||
'hair' => $hair,
|
||||
'gender' => $gender,
|
||||
'appearance' => $appearance,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateFromScreenEight( $id, $name ) {
|
||||
$fields = [
|
||||
'copper' => $copper,
|
||||
'silver' => $silver,
|
||||
'gold' => $gold,
|
||||
'platinum' => $platinum,
|
||||
'electrum' => $electrum,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create( $name ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'characterCreate' );
|
||||
Debug::error( "Character: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'characterUpdate' );
|
||||
Debug::error( "Character: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Characters found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
// inventory() - items
|
||||
// spells() - spells
|
||||
// skills() - skills
|
||||
// saves() - calculate all the various saving throws
|
||||
// bonuses() - calculate the various bonuses such as to initiative and AC etc
|
||||
}
|
121
app/plugins/dnd/models/classes.php
Normal file
121
app/plugins/dnd/models/classes.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/classes.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_classes database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Classes extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_classes';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
[ 'avatar', 'text', '' ],
|
||||
|
||||
[ 'classID', 'int', '11' ],
|
||||
// spells()
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Class: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Class: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Classes found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
117
app/plugins/dnd/models/feats.php
Normal file
117
app/plugins/dnd/models/feats.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/feats.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_feats database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Feats extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_feats';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Feat: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Feat: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Feats found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
100
app/plugins/dnd/models/gods.php
Normal file
100
app/plugins/dnd/models/gods.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/gods.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_gods database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Gods extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_gods';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
[ 'pantheon', 'varchar', '32' ],
|
||||
[ 'domains', 'varchar', '32' ],
|
||||
[ 'symbol', 'varchar', '32' ],
|
||||
[ 'morality', 'varchar', '16' ], // good, neutral, evil
|
||||
[ 'order', 'varchar', '16' ], // lawful, neutral, chaotic
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "God: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "God: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Gods found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
}
|
131
app/plugins/dnd/models/items.php
Normal file
131
app/plugins/dnd/models/items.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/items.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_items database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Items extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_items';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// type
|
||||
// Weight
|
||||
// class ( mundane / magical )
|
||||
|
||||
[ 'cost_copper', 'int', '12' ],
|
||||
[ 'cost_silver', 'int', '12' ],
|
||||
[ 'cost_gold', 'int', '12' ],
|
||||
[ 'cost_platinum', 'int', '12' ],
|
||||
[ 'cost_electrum', 'int', '12' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Item: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Item: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Items found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
154
app/plugins/dnd/models/languages.php
Normal file
154
app/plugins/dnd/models/languages.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/languages.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_languages database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Languages extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_languages';
|
||||
public $databaseMatrix = [
|
||||
// Core
|
||||
[ 'name', 'varchar', '32' ],
|
||||
[ 'type', 'varchar', '32' ], // exotic / standard / other
|
||||
[ 'typical_speakers', 'varchar', '32' ],
|
||||
[ 'script', 'varchar', '32' ],
|
||||
[ 'sound', 'text', '' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID = '', $type = '', $typical_speakers = '', $script = '', $sound = '', $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'typical_speakers' => $typical_speakers,
|
||||
'script' => $script,
|
||||
'sound' => $sound,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'shortDescription' => $shortDescription,
|
||||
'description' => $description,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Language: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID = '', $type = '', $typical_speakers = '', $script = '', $sound = '', $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'type' => $type,
|
||||
'typical_speakers' => $typical_speakers,
|
||||
'script' => $script,
|
||||
'sound' => $sound,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'shortDescription' => $shortDescription,
|
||||
'description' => $description,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Language: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Languages found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function paginatedList() {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
$objects = self::$db->getPaginated( $this->tableName, $whereClause );
|
||||
if ( ! $objects->count() ) {
|
||||
Debug::info( 'No Language found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function simpleList() {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
if ( ! $objects->count() ) {
|
||||
Debug::warn( 'No Languages found.' );
|
||||
return false;
|
||||
}
|
||||
|
||||
$objects = $objects->results();
|
||||
$out = [];
|
||||
foreach ( $objects as &$object ) {
|
||||
$out[ $object->name ] = $object->ID;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
153
app/plugins/dnd/models/monsters.php
Normal file
153
app/plugins/dnd/models/monsters.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/monsters.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_monsters database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Monsters extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_monsters';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
[ 'avatar', 'text', '' ],
|
||||
|
||||
// Core
|
||||
[ 'experience', 'int', '12' ],
|
||||
[ 'perception', 'varchar', '4' ],
|
||||
[ 'armor_class', 'varchar', '4' ],
|
||||
[ 'armor_type', 'varchar', '16' ],
|
||||
[ 'alignment', 'varchar', '16' ],
|
||||
[ 'hit_die', 'varchar', '4' ],
|
||||
[ 'hit_die_count', 'int', '4' ],
|
||||
[ 'hit_die_modifier', 'varchar', '4' ],
|
||||
[ 'race', 'varchar', '32' ],
|
||||
[ 'size', 'varchar', '32' ],
|
||||
[ 'type', 'varchar', '32' ],
|
||||
[ 'sub_type', 'varchar', '32' ],
|
||||
[ 'challenge_rating', 'varchar', '32' ],
|
||||
[ 'average_hp', 'int', '5' ],
|
||||
|
||||
// Skills
|
||||
[ 'strength', 'int', '4' ],
|
||||
[ 'dexterity', 'int', '4' ],
|
||||
[ 'constitution', 'int', '4' ],
|
||||
[ 'charisma', 'int', '4' ],
|
||||
[ 'intelligence', 'int', '4' ],
|
||||
[ 'wisdom', 'int', '4' ],
|
||||
|
||||
// Expository
|
||||
[ 'characteristics', 'text', '' ],
|
||||
[ 'special_traits', 'text', '' ],
|
||||
[ 'actions', 'text', '' ],
|
||||
[ 'reactions', 'text', '' ],
|
||||
[ 'bonus_actions', 'text', '' ],
|
||||
[ 'mythic_actions', 'text', '' ],
|
||||
[ 'legendary_actions', 'text', '' ],
|
||||
[ 'lair_actions', 'text', '' ],
|
||||
[ 'languages', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Monster: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Monster: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Monsters found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
213
app/plugins/dnd/models/races.php
Normal file
213
app/plugins/dnd/models/races.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/races.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_races database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Races extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_races';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
[ 'languages', 'varchar', '32' ],
|
||||
[ 'racial_traits', 'varchar', '32' ],
|
||||
[ 'size', 'varchar', '16' ],
|
||||
[ 'age', 'text', '' ],
|
||||
[ 'raceID', 'int', '11' ],
|
||||
[ 'suggested_classes', 'text', '' ],
|
||||
[ 'abilityScores', 'text', '' ], // json
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
[ 'avatar', 'text', '' ],
|
||||
|
||||
// Speeds
|
||||
[ 'walking_speed', 'int', '4' ],
|
||||
[ 'climbing_speed', 'int', '4' ],
|
||||
[ 'swimming_speed', 'int', '4' ],
|
||||
[ 'burrowing_speed', 'int', '4' ],
|
||||
[ 'flying_speed', 'int', '4' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Race: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Race: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Races found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Master list with origins 2:
|
||||
// Aarakocra - Elemental Evil Player's Companion, Monsters of the Multiverse
|
||||
// Aasimar - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Autognome - Spelljammer: Adventures in Space
|
||||
// Bugbear - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
|
||||
// Centaur - Guildmaster’s Guide to Ravnica, Mythic Odysseys of Theros, Monsters of the Multiverse
|
||||
// Cervan - Humblewood Campaign Setting
|
||||
// Changeling - Eberron: Rising from the Last War, Monsters of the Multiverse
|
||||
// Corvum - Humblewood Campaign Setting
|
||||
// Dhampir - Van Richten's Guide to Ravenloft
|
||||
// The Disembodied - Grim Hollow: Player Pack
|
||||
|
||||
|
||||
|
||||
// Fairy - The Wild Beyond the Witchlight, Monsters of the Multiverse
|
||||
// Firbolg - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Gallus - Humblewood Campaign Setting
|
||||
// Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
|
||||
// Giff - Spelljammer: Adventures in Space
|
||||
// Gith - Mordenkainen’s Tome of Foes, Monsters of the Multiverse (Githyanki, Githzerai)
|
||||
|
||||
// Goblin - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
|
||||
// Goliath - Elemental Evil Player's Companion, Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Grung - One Grung Above
|
||||
// Hadozee - Spelljammer: Adventures in Space
|
||||
|
||||
|
||||
|
||||
// Harengon - The Wild Beyond the Witchlight, Monsters of the Multiverse
|
||||
// Hedge - Humblewood Campaign Setting
|
||||
// Hexblood - Van Richten's Guide to Ravenloft
|
||||
// Hobgoblin - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
|
||||
|
||||
// Jerbeen - Humblewood Campaign Setting
|
||||
// Kalashtar - Eberron: Rising from the Last War
|
||||
// Kender - Dragonlance: Shadow of the Dragon Queen
|
||||
// Kenku - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Kobold - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Leonin - Mythic Odysseys of Theros
|
||||
// Lizardfolk - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Locathah - Locathah Rising
|
||||
// Loxodon - Guildmaster’s Guide to Ravnica
|
||||
// Luma - Humblewood Campaign Setting
|
||||
// Mapach - Humblewood Campaign Setting
|
||||
// Minotaur - Guildmaster’s Guide to Ravnica, Mythic Odysseys of Theros, Monsters of the Multiverse
|
||||
// Orc - Volo's Guide to Monsters, Eberron: Rising from the Last War, Monsters of the Multiverse
|
||||
// Owlin - Strixhaven: Curriculum of Chaos
|
||||
// Plasmoid - Spelljammer: Adventures in Space
|
||||
// Raptor - Humblewood Campaign Setting
|
||||
// Reborn - Van Richten's Guide to Ravenloft
|
||||
// Satyr - Mythic Odysseys of Theros, Monsters of the Multiverse
|
||||
// Shadar-kai - Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
||||
// Shifter - Eberron: Rising from the Last War, Monsters of the Multiverse
|
||||
// Simic Hybrid - Guildmaster’s Guide to Ravnica
|
||||
// Strig - Humblewood Campaign Setting
|
||||
// Tabaxi - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Thri-kreen - Spelljammer: Adventures in Space, Monsters of the Multiverse
|
||||
|
||||
// Tortle - The Tortle Package, Monsters of the Multiverse
|
||||
// Triton - Mythic Odysseys of Theros, Monsters of the Multiverse
|
||||
// Vedalken - Guildmaster’s Guide to Ravnica
|
||||
// Verdan - Acquisitions Incorporated
|
||||
// Vulpin - Humblewood Campaign Setting
|
||||
// Warforged - Eberron: Rising from the Last War
|
||||
// Wechselkind - Grim Hollow: Player Pack
|
||||
// Yuan-ti Pureblood - Volo's Guide to Monsters, Monsters of the Multiverse
|
||||
// Custom Lineage - Tasha's Cauldron of Everything
|
||||
// Deep Gnome - Elemental Evil Player's Companion, Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
||||
// Duergar - Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
||||
// Eladrin - Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
||||
// Air Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
|
||||
// Earth Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
|
||||
// Fire Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
|
||||
// Water Genasi - Elemental Evil Player's Companion, Monsters of the Multiverse
|
||||
// Astral Elf - Spelljammer: Adventures in Space
|
||||
// Sea Elf - Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
||||
// Githyanki - Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
||||
// Githzerai - Mordenkainen’s Tome of Foes, Monsters of the Multiverse
|
117
app/plugins/dnd/models/skills.php
Normal file
117
app/plugins/dnd/models/skills.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/skills.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_skills database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Skills extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_skills';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Skill: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Skill: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Skills found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
154
app/plugins/dnd/models/sourcebooks.php
Normal file
154
app/plugins/dnd/models/sourcebooks.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/sourcebooks.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_sourcebooks database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
|
||||
class Sourcebooks extends DatabaseModel {
|
||||
public $tableName = 'dnd_sourcebooks';
|
||||
public $databaseMatrix = [
|
||||
// Name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
|
||||
// Core
|
||||
[ 'type', 'varchar', '5' ],
|
||||
[ 'publish_year', 'int', '4' ],
|
||||
[ 'amazon_url', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $type = '', $publishYear = '', $amazonUrl = '', $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'type' => $type,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'publish_year' => $publishYear,
|
||||
'amazon_url' => $amazonUrl,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "SourceBook: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $type = '', $publishYear = '', $amazonUrl = '', $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'type' => $type,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'publish_year' => $publishYear,
|
||||
'amazon_url' => $amazonUrl,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "SourceBook: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function paginatedList() {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
$objects = self::$db->getPaginated( $this->tableName, $whereClause );
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No SourceBooks found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No SourceBooks found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function simpleList() {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
if ( ! $objects->count() ) {
|
||||
Debug::warn( 'No Languages found.' );
|
||||
return false;
|
||||
}
|
||||
|
||||
$objects = $objects->results();
|
||||
$out = [];
|
||||
foreach ( $objects as &$object ) {
|
||||
$out[ $object->name ] = $object->ID;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// origins
|
||||
// Player's Handbook / Basic Rules
|
||||
// The main Rulebook for D&D.
|
||||
// Elemental Evil Player's Companion
|
||||
// Volo's Guide to Monsters
|
||||
// Mordenkainen Presents: Monsters of the Multiverse
|
||||
// Eberron: Rising from the Last War
|
||||
// Fizban’s Treasury of Dragons
|
||||
// Guildmaster’s Guide to Ravnica
|
||||
// Locathah Rising
|
||||
// Mordenkainen’s Tome of Foes
|
||||
// Mythic Odysseys of Theros
|
||||
// One Grung Above
|
||||
// The Tortle Package
|
||||
// The Wild Beyond the Witchlight
|
||||
// Dragonlance: Shadow of the Dragon Queen
|
||||
// Spelljammer: Adventures in Space
|
||||
// Strixhaven: Curriculum of Chaos
|
||||
// Van Richten's Guide to Ravenloft
|
||||
// Tasha's Cauldron of Everything
|
||||
// Grim Hollow: Player Pack
|
||||
// Humblewood Campaign Setting
|
||||
// Acquisitions Incorporated
|
||||
// Sword Coast Adventurer's Guide
|
140
app/plugins/dnd/models/spells.php
Normal file
140
app/plugins/dnd/models/spells.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/spells.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_spells database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Spells extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_spells';
|
||||
public $databaseMatrix = [
|
||||
// level
|
||||
// Name // spell-name
|
||||
[ 'name', 'varchar', '32' ],
|
||||
// casting time
|
||||
// duration
|
||||
// school / magic school
|
||||
[ 'school', 'varchar', '16' ],
|
||||
// comps / components
|
||||
// range
|
||||
// area
|
||||
// attack
|
||||
// save
|
||||
// conc / concentration
|
||||
// source
|
||||
// damage effect
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'image', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Spell: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Spell: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Spells found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
131
app/plugins/dnd/models/traits.php
Normal file
131
app/plugins/dnd/models/traits.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/dnd/models/traits.php
|
||||
*
|
||||
* This class is used for the manipulation of the dnd_racial_traits database table.
|
||||
*
|
||||
* @package TTE Dungeons & Dragons
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@tabletopelite.com>
|
||||
* @link https://TableTopElite.com
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\TheTempusProject as App;
|
||||
use TheTempusProject\Bedrock\Classes\CustomException;
|
||||
use TheTempusProject\Models\Sourcebooks as SourcebooksModel;
|
||||
|
||||
class Traits extends DatabaseModel {
|
||||
protected static $sourcebooks;
|
||||
public $tableName = 'dnd_racial_traits';
|
||||
public $databaseMatrix = [
|
||||
// Core
|
||||
[ 'name', 'varchar', '64' ],
|
||||
[ 'description', 'text', '' ],
|
||||
[ 'shortDescription', 'text', '' ],
|
||||
|
||||
// General
|
||||
[ 'createdBy', 'int', '11' ],
|
||||
[ 'createdAt', 'int', '11' ],
|
||||
[ 'privacy', 'varchar', '16' ],
|
||||
[ 'version', 'varchar', '5' ],
|
||||
[ 'sourcebookID', 'int', '11' ],
|
||||
[ 'image', 'text', '' ],
|
||||
];
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
self::$sourcebooks = new SourcebooksModel;
|
||||
}
|
||||
|
||||
public function create( $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
'createdBy' => App::$activeUser->ID,
|
||||
'createdAt' => time(),
|
||||
];
|
||||
if ( ! self::$db->insert( $this->tableName, $fields ) ) {
|
||||
new CustomException( 'Create' );
|
||||
Debug::error( "Traits: not created " . var_export($fields,true) );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function update( $id, $name, $privacy, $version, $sourcebookID, $description = '', $shortDescription = '' ) {
|
||||
$fields = [
|
||||
'name' => $name,
|
||||
'privacy' => $privacy,
|
||||
'version' => $version,
|
||||
'sourcebookID' => $sourcebookID,
|
||||
'description' => $description,
|
||||
'shortDescription' => $shortDescription,
|
||||
];
|
||||
if ( !self::$db->update( $this->tableName, $id, $fields ) ) {
|
||||
new CustomException( 'Update' );
|
||||
Debug::error( "Traits: $id not updated: $fields" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function byUser( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', App::$activeUser->ID];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Traits found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function bySystem( $limit = null ) {
|
||||
$whereClause = ['createdBy', '=', '0'];
|
||||
if ( empty( $limit ) ) {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause );
|
||||
} else {
|
||||
$objects = self::$db->get( $this->tableName, $whereClause, 'ID', 'DESC', [0, $limit] );
|
||||
}
|
||||
if ( !$objects->count() ) {
|
||||
Debug::info( 'No Traits found.' );
|
||||
return false;
|
||||
}
|
||||
return $this->filter( $objects->results() );
|
||||
}
|
||||
|
||||
public function filter( $data, $params = [] ) {
|
||||
$out = [];
|
||||
foreach ( $data as $instance ) {
|
||||
if ( !is_object( $instance ) ) {
|
||||
$instance = $data;
|
||||
$end = true;
|
||||
}
|
||||
$sourcebook = self::$sourcebooks->findById( $instance->sourcebookID );
|
||||
if ( !empty( $sourcebook ) ) {
|
||||
$instance->sourcebookName = $sourcebook->name;
|
||||
} else {
|
||||
$instance->sourcebookName = 'Unknown';
|
||||
}
|
||||
$out[] = $instance;
|
||||
if ( !empty( $end ) ) {
|
||||
$out = $out[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user