Initial commit
This commit is contained in:
137
app/plugins/tablefinder/models/players.php
Normal file
137
app/plugins/tablefinder/models/players.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/tablefinder/models/players.php
|
||||
*
|
||||
* This class is used for the manipulation of the feedback database table.
|
||||
*
|
||||
* @package TP TableFinder
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\Plugins\Tablefinder as Plugin;
|
||||
|
||||
class Players extends DatabaseModel {
|
||||
public $tableName = 'players';
|
||||
public $databaseMatrix = [
|
||||
[ 'userID', 'int', '10' ],
|
||||
[ 'tableID', 'int', '10' ],
|
||||
[ 'characterID', 'int', '10' ],
|
||||
[ 'applicationDate', 'int', '10' ],
|
||||
[ 'rejectionDate', 'int', '10' ],
|
||||
[ 'joinDate', 'int', '10' ],
|
||||
[ 'leaveDate', 'int', '10' ],
|
||||
];
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->plugin = new Plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the db.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function create( $userID, $tableID, $type = 'apply', $characterID = 0 ) {
|
||||
if ( !$this->plugin->checkEnabled() ) {
|
||||
Debug::info( 'TableFinder is disabled in the config.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'userID' => $userID,
|
||||
'tableID' => $tableID,
|
||||
];
|
||||
|
||||
if ( ! empty( $characterID ) ) {
|
||||
$fields['characterID'] = $characterID;
|
||||
}
|
||||
if ( 'apply' == $type ) {
|
||||
$fields['applicationDate'] = time();
|
||||
} else {
|
||||
$fields['joinDate'] = time();
|
||||
}
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
Debug::info( 'TableFinder::create - failed to insert to db' );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
|
||||
public function listPlayersByUser( $userID, $type = 'applied' ) {
|
||||
if ( !$this->plugin->checkEnabled() ) {
|
||||
Debug::info( 'TableFinder is disabled in the config.' );
|
||||
return false;
|
||||
}
|
||||
switch ($type) {
|
||||
case 'applied':
|
||||
$type = 'applicationDate';
|
||||
break;
|
||||
case 'denied':
|
||||
$type = 'rejectionDate';
|
||||
break;
|
||||
case 'joined':
|
||||
$type = 'joinDate';
|
||||
break;
|
||||
case 'left':
|
||||
$type = 'leaveDate';
|
||||
break;
|
||||
default:
|
||||
// simple way to not limit the results
|
||||
$type = 'id';
|
||||
break;
|
||||
}
|
||||
$terms = [ 'userID', '=', $userID, 'AND', $type, '>', 0 ];
|
||||
|
||||
$results = self::$db->get( $this->tableName, $terms );
|
||||
if ( $results->count() == 0 ) {
|
||||
Debug::info( 'Failed to mark message as read.' );
|
||||
return false;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function listPlayersByTable( $tableID, $type = 'applied' ) {
|
||||
if ( !$this->plugin->checkEnabled() ) {
|
||||
Debug::info( 'TableFinder is disabled in the config.' );
|
||||
return false;
|
||||
}
|
||||
switch ($type) {
|
||||
case 'applied':
|
||||
$type = 'applicationDate';
|
||||
break;
|
||||
case 'denied':
|
||||
$type = 'rejectionDate';
|
||||
break;
|
||||
case 'joined':
|
||||
$type = 'joinDate';
|
||||
break;
|
||||
case 'left':
|
||||
$type = 'leaveDate';
|
||||
break;
|
||||
default:
|
||||
// simple way to not limit the results
|
||||
$type = 'id';
|
||||
break;
|
||||
}
|
||||
$terms = [ 'tableID', '=', $tableID, 'AND', $type, '>', 0 ];
|
||||
|
||||
$results = self::$db->get( $this->tableName, $terms );
|
||||
if ( $results->count() == 0 ) {
|
||||
Debug::info( 'Failed to mark message as read.' );
|
||||
return false;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
93
app/plugins/tablefinder/models/tables.php
Normal file
93
app/plugins/tablefinder/models/tables.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* app/plugins/tablefinder/models/players.php
|
||||
*
|
||||
* This class is used for the manipulation of the feedback database table.
|
||||
*
|
||||
* @package TP TableFinder
|
||||
* @version 3.0
|
||||
* @author Joey Kimsey <Joey@thetempusproject.com>
|
||||
* @link https://TheTempusProject.com
|
||||
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
||||
*/
|
||||
namespace TheTempusProject\Models;
|
||||
|
||||
use TheTempusProject\Bedrock\Classes\Config;
|
||||
use TheTempusProject\Bedrock\Functions\Check;
|
||||
use TheTempusProject\Canary\Canary as Debug;
|
||||
use TheTempusProject\Classes\DatabaseModel;
|
||||
use TheTempusProject\Plugins\Tablefinder as Plugin;
|
||||
|
||||
class Players extends DatabaseModel {
|
||||
public $tableName = 'players';
|
||||
public $databaseMatrix = [
|
||||
[ 'name', 'int', '10' ],
|
||||
[ 'description', 'int', '10' ],
|
||||
[ 'rules', 'int', '10' ],
|
||||
[ 'gmID', 'int', '10' ],
|
||||
[ 'createdAt', 'int', '10' ],
|
||||
[ 'createdBy', 'int', '10' ],
|
||||
[ 'calendarID', 'int', '10' ],
|
||||
[ 'preferredSessionFrequency', 'int', '10' ],
|
||||
// weekly
|
||||
// bi-weekly
|
||||
// monthly
|
||||
// undefined
|
||||
[ 'preferredSessionLength', 'int', '10' ],
|
||||
[ 'minimumSessionLength', 'int', '10' ],
|
||||
[ 'maximumSessionLength', 'int', '10' ],
|
||||
[ 'gamePlatform', 'int', '10' ],
|
||||
[ 'gameVersion', 'int', '10' ],
|
||||
[ 'playType', 'int', '10' ],
|
||||
// in-person
|
||||
// online
|
||||
[ 'location', 'int', '10' ],
|
||||
];
|
||||
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* The model constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->plugin = new Plugin;
|
||||
}
|
||||
|
||||
public function create(
|
||||
$name,
|
||||
$description = '',
|
||||
$rules = '',
|
||||
$frequency = 'Weekly',
|
||||
$lengthPref = '4h',
|
||||
$lengthMin = '30m',
|
||||
$lengthMax = '12h',
|
||||
$platform = 'Dungeons & Dragons',
|
||||
$version = '5e',
|
||||
$playType = 'Online',
|
||||
$location = 'TBD'
|
||||
) {
|
||||
if ( !$this->plugin->checkEnabled() ) {
|
||||
Debug::info( 'TableFinder is disabled in the config.' );
|
||||
return false;
|
||||
}
|
||||
$fields = [
|
||||
'userID' => $userID,
|
||||
'tableID' => $tableID,
|
||||
];
|
||||
|
||||
if ( ! empty( $characterID ) ) {
|
||||
$fields['characterID'] = $characterID;
|
||||
}
|
||||
if ( 'apply' == $type ) {
|
||||
$fields['applicationDate'] = time();
|
||||
} else {
|
||||
$fields['joinDate'] = time();
|
||||
}
|
||||
if ( !self::$db->insert( $this->tableName, $fields ) ) {
|
||||
Debug::info( 'TableFinder::create - failed to insert to db' );
|
||||
return false;
|
||||
}
|
||||
return self::$db->lastId();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user