Initial commit
This commit is contained in:
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
|
Reference in New Issue
Block a user