class XordSportsbook_Install
{
private static $_instance;
protected $_db;
public static final function getInstance()
{
if (!self::$_instance)
{
self::$_instance = new self;
}
return self::$_instance;
}
protected function _getDb()
{
if ($this->_db === null)
{
$this->_db = XenForo_Application::get('db');
}
return $this->_db;
}
public static function build($existingAddOn, $addOnData)
{
$startVersion = 1;
$endVersion = $addOnData['version_id'];
if ($existingAddOn)
{
$startVersion = $existingAddOn['version_id'] + 1;
}
$install = self::getInstance();
for ($i = $startVersion; $i <= $endVersion; $i++)
{
$method = '_installVersion' . $i;
if (method_exists($install, $method) === false)
{
continue;
}
$install->$method();
}
}
protected function _installVersion1()
{
$db = $this->_getDb();
$db->query("
ALTER TABLE xf_user
ADD sportsbook_cash BIGINT(20) UNSIGNED NOT NULL DEFAULT '500'
");
}
protected function _installVersion2()
{
$db->query("
CREATE TABLE IF NOT EXISTS xordsportsbook_category (
category_id int(10) unsigned NOT NULL AUTO_INCREMENT,
category_name varchar(255) NOT NULL,
category_abbr varchar(25) NOT NULL,
PRIMARY KEY (category_id)
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
");
}
protected function _installVersion3()
{
$db = $this->_getDb();
$db->query("
INSERT INTO xf_content_type
(content_type, addon_id, fields)
VALUES
('sportsbook_event', 'XordSportsbook', ''),
('sportsbook_comment', 'XordSportsbook', ''),
('sportsbook_wager', 'XordSportsbook', '')
");
}
}