Modify database structure - refs #7768

1.10.x
Angel Fernando Quiroz Campos 9 years ago
parent 9a30669c93
commit affd4988c6
  1. 1
      plugin/buycourses/config.php
  2. 779
      plugin/buycourses/database.php
  3. 9
      plugin/buycourses/src/BuyCoursesUtils.php
  4. 3
      plugin/buycourses/src/buy_course_plugin.class.php

@ -13,4 +13,3 @@ define('TABLE_BUY_COURSE_TEMPORAL', 'plugin_buy_course_temporal');
define('TABLE_BUY_COURSE_SALE', 'plugin_buy_course_sale');
require_once __DIR__ . '/../../main/inc/global.inc.php';
require_once api_get_path(PLUGIN_PATH) . 'buycourses/src/buy_course_plugin.class.php';

@ -11,398 +11,411 @@
if (!function_exists('api_get_path')) {
die('This script must be loaded through the Chamilo plugin installer sequence');
}
/**
* Create the script context, then execute database queries to enable
*/
$table = Database::get_main_table(TABLE_BUY_SESSION);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
session_id INT unsigned NOT NULL DEFAULT '0',
name VARCHAR(250),
date_start VARCHAR(40),
date_end VARCHAR(40),
visible int,
price FLOAT(11,2) NOT NULL DEFAULT '0',
sync int)";
Database::query($sql);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "SELECT id, name, access_start_date, access_end_date FROM $tableSession";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$presql = "INSERT INTO $table (id, name, date_start, date_end, visible)
VALUES ('" . $row['id'] . "','" . $row['name'] . "','" . $row['access_start_date'] . "','" . $row['access_end_date'] . "','NO')";
Database::query($presql);
}
$entityManager = Database::getManager();
$pluginSchema = new \Doctrine\DBAL\Schema\Schema();
$connection = $entityManager->getConnection();
$platform = $connection->getDatabasePlatform();
$table = Database::get_main_table(TABLE_BUY_COURSE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
session_id INT unsigned NOT NULL DEFAULT 0,
course_id INT unsigned NOT NULL DEFAULT '0',
code VARCHAR(40),
title VARCHAR(250),
visible int,
price FLOAT(11,2) NOT NULL DEFAULT '0',
sync int)";
Database::query($sql);
//Create tables
$paypalTable = $pluginSchema->createTable(BuyCoursesUtils::TABLE_PAYPAL);
$paypalTable->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$paypalTable->addColumn('username', \Doctrine\DBAL\Types\Type::STRING);
$paypalTable->addColumn('password', \Doctrine\DBAL\Types\Type::STRING);
$paypalTable->addColumn('signature', \Doctrine\DBAL\Types\Type::STRING);
$paypalTable->addColumn('sandbox', \Doctrine\DBAL\Types\Type::BOOLEAN);
$paypalTable->setPrimaryKey(['id']);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$sql = "SELECT id, code, title FROM $tableCourse";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$presql = "INSERT INTO $table (course_id, code, title, visible) VALUES ('" . $row['id'] . "','" . $row['code'] . "','" . $row['title'] . "','NO')";
Database::query($presql);
}
$transferTable = $pluginSchema->createTable(BuyCoursesUtils::TABLE_TRANSFER);
$transferTable->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$transferTable->addColumn('name', \Doctrine\DBAL\Types\Type::STRING);
$transferTable->addColumn('account', \Doctrine\DBAL\Types\Type::STRING);
$transferTable->addColumn('swift', \Doctrine\DBAL\Types\Type::STRING);
$table = Database::get_main_table(TABLE_BUY_SESSION_COURSE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
session_id SMALLINT(5) unsigned DEFAULT '0',
course_code VARCHAR(40),
nbr_users SMALLINT(5) unsigned DEFAULT '0',
sync int)";
Database::query($sql);
$currencyTable = $pluginSchema->createTable(BuyCoursesUtils::TABLE_CURRENCY);
$currencyTable->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$currencyTable->addColumn(
'country_code',
\Doctrine\DBAL\Types\Type::STRING,
['length' => 2]
);
$currencyTable->addColumn(
'country_name',
\Doctrine\DBAL\Types\Type::STRING,
['length' => 255]
);
$currencyTable->addColumn(
'iso_code',
\Doctrine\DBAL\Types\Type::STRING,
['length' => 3]
);
$currencyTable->addColumn('status', \Doctrine\DBAL\Types\Type::BOOLEAN);
$currencyTable->addUniqueIndex(['country_code']);
$currencyTable->addIndex(['iso_code']);
$currencyTable->setPrimaryKey(['id']);
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$sql = "SELECT * FROM $table";
$res = Database::query($sql);
while ($row = Database::fetch_assoc($res)) {
$presql = "INSERT INTO $table (session_id, c_id, nbr_users)
VALUES ('" . $row['session_id'] . "','" . $row['c_id'] . "','" . $row['nbr_users'] . "')";
Database::query($presql);
}
$itemTable = $pluginSchema->createTable(BuyCoursesUtils::TABLE_ITEM);
$itemTable->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$itemTable->addColumn('product_type', \Doctrine\DBAL\Types\Type::INTEGER);
$itemTable->addColumn(
'product_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$itemTable->addColumn(
'price',
\Doctrine\DBAL\Types\Type::DECIMAL,
['scale' => 2]
);
$itemTable->addColumn(
'currency_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$itemTable->setPrimaryKey(['id']);
$itemTable->addForeignKeyConstraint(
$currencyTable,
['currency_id'],
['id'],
['onDelete' => 'CASCADE']
);
$table = Database::get_main_table(TABLE_BUY_COURSE_COUNTRY);
$sql = "CREATE TABLE IF NOT EXISTS $table (
country_id int NOT NULL AUTO_INCREMENT,
country_code char(2) NOT NULL DEFAULT '',
country_name varchar(45) NOT NULL DEFAULT '',
currency_code char(3) DEFAULT NULL,
iso_alpha3 char(3) DEFAULT NULL,
status int DEFAULT '0',
PRIMARY KEY (country_id)
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;";
Database::query($sql);
$saleTable = $pluginSchema->createTable(BuyCoursesUtils::TABLE_SALE);
$saleTable->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$saleTable->addColumn('date', \Doctrine\DBAL\Types\Type::DATE);
$saleTable->addColumn(
'user_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$saleTable->addColumn('product_type', \Doctrine\DBAL\Types\Type::INTEGER);
$saleTable->addColumn('product_name', \Doctrine\DBAL\Types\Type::STRING);
$saleTable->addColumn(
'product_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$saleTable->addColumn(
'price',
\Doctrine\DBAL\Types\Type::DECIMAL,
['scale' => 2]
);
$saleTable->addColumn(
'currency_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$saleTable->addColumn('status', \Doctrine\DBAL\Types\Type::INTEGER);
$saleTable->addColumn('payment_type', \Doctrine\DBAL\Types\Type::INTEGER);
$saleTable->setPrimaryKey(['id']);
$saleTable->addForeignKeyConstraint(
$currencyTable,
['currency_id'],
['id'],
['onDelete' => 'CASCADE']
);
$sql = "CREATE UNIQUE INDEX index_country ON $table (country_code)";
Database::query($sql);
$queries = $pluginSchema->toSql($platform);
$sql = "INSERT INTO $table (country_code, country_name, currency_code, iso_alpha3) VALUES
('AD', 'Andorra', 'EUR', 'AND'),
('AE', 'United Arab Emirates', 'AED', 'ARE'),
('AF', 'Afghanistan', 'AFN', 'AFG'),
('AG', 'Antigua and Barbuda', 'XCD', 'ATG'),
('AI', 'Anguilla', 'XCD', 'AIA'),
('AL', 'Albania', 'ALL', 'ALB'),
('AM', 'Armenia', 'AMD', 'ARM'),
('AO', 'Angola', 'AOA', 'AGO'),
('AR', 'Argentina', 'ARS', 'ARG'),
('AS', 'American Samoa', 'USD', 'ASM'),
('AT', 'Austria', 'EUR', 'AUT'),
('AU', 'Australia', 'AUD', 'AUS'),
('AW', 'Aruba', 'AWG', 'ABW'),
('AX', 'Åland', 'EUR', 'ALA'),
('AZ', 'Azerbaijan', 'AZN', 'AZE'),
('BA', 'Bosnia and Herzegovina', 'BAM', 'BIH'),
('BB', 'Barbados', 'BBD', 'BRB'),
('BD', 'Bangladesh', 'BDT', 'BGD'),
('BE', 'Belgium', 'EUR', 'BEL'),
('BF', 'Burkina Faso', 'XOF', 'BFA'),
('BG', 'Bulgaria', 'BGN', 'BGR'),
('BH', 'Bahrain', 'BHD', 'BHR'),
('BI', 'Burundi', 'BIF', 'BDI'),
('BJ', 'Benin', 'XOF', 'BEN'),
('BL', 'Saint Barthélemy', 'EUR', 'BLM'),
('BM', 'Bermuda', 'BMD', 'BMU'),
('BN', 'Brunei', 'BND', 'BRN'),
('BO', 'Bolivia', 'BOB', 'BOL'),
('BQ', 'Bonaire', 'USD', 'BES'),
('BR', 'Brazil', 'BRL', 'BRA'),
('BS', 'Bahamas', 'BSD', 'BHS'),
('BT', 'Bhutan', 'BTN', 'BTN'),
('BV', 'Bouvet Island', 'NOK', 'BVT'),
('BW', 'Botswana', 'BWP', 'BWA'),
('BY', 'Belarus', 'BYR', 'BLR'),
('BZ', 'Belize', 'BZD', 'BLZ'),
('CA', 'Canada', 'CAD', 'CAN'),
('CC', 'Cocos [Keeling] Islands', 'AUD', 'CCK'),
('CD', 'Congo', 'CDF', 'COD'),
('CF', 'Central African Republic', 'XAF', 'CAF'),
('CG', 'Republic of the Congo', 'XAF', 'COG'),
('CH', 'Switzerland', 'CHF', 'CHE'),
('CI', 'Ivory Coast', 'XOF', 'CIV'),
('CK', 'Cook Islands', 'NZD', 'COK'),
('CL', 'Chile', 'CLP', 'CHL'),
('CM', 'Cameroon', 'XAF', 'CMR'),
('CN', 'China', 'CNY', 'CHN'),
('CO', 'Colombia', 'COP', 'COL'),
('CR', 'Costa Rica', 'CRC', 'CRI'),
('CU', 'Cuba', 'CUP', 'CUB'),
('CV', 'Cape Verde', 'CVE', 'CPV'),
('CW', 'Curacao', 'ANG', 'CUW'),
('CX', 'Christmas Island', 'AUD', 'CXR'),
('CY', 'Cyprus', 'EUR', 'CYP'),
('CZ', 'Czechia', 'CZK', 'CZE'),
('DE', 'Germany', 'EUR', 'DEU'),
('DJ', 'Djibouti', 'DJF', 'DJI'),
('DK', 'Denmark', 'DKK', 'DNK'),
('DM', 'Dominica', 'XCD', 'DMA'),
('DO', 'Dominican Republic', 'DOP', 'DOM'),
('DZ', 'Algeria', 'DZD', 'DZA'),
('EC', 'Ecuador', 'USD', 'ECU'),
('EE', 'Estonia', 'EUR', 'EST'),
('EG', 'Egypt', 'EGP', 'EGY'),
('EH', 'Western Sahara', 'MAD', 'ESH'),
('ER', 'Eritrea', 'ERN', 'ERI'),
('ES', 'Spain', 'EUR', 'ESP'),
('ET', 'Ethiopia', 'ETB', 'ETH'),
('FI', 'Finland', 'EUR', 'FIN'),
('FJ', 'Fiji', 'FJD', 'FJI'),
('FK', 'Falkland Islands', 'FKP', 'FLK'),
('FM', 'Micronesia', 'USD', 'FSM'),
('FO', 'Faroe Islands', 'DKK', 'FRO'),
('FR', 'France', 'EUR', 'FRA'),
('GA', 'Gabon', 'XAF', 'GAB'),
('GB', 'United Kingdom', 'GBP', 'GBR'),
('GD', 'Grenada', 'XCD', 'GRD'),
('GE', 'Georgia', 'GEL', 'GEO'),
('GF', 'French Guiana', 'EUR', 'GUF'),
('GG', 'Guernsey', 'GBP', 'GGY'),
('GH', 'Ghana', 'GHS', 'GHA'),
('GI', 'Gibraltar', 'GIP', 'GIB'),
('GL', 'Greenland', 'DKK', 'GRL'),
('GM', 'Gambia', 'GMD', 'GMB'),
('GN', 'Guinea', 'GNF', 'GIN'),
('GP', 'Guadeloupe', 'EUR', 'GLP'),
('GQ', 'Equatorial Guinea', 'XAF', 'GNQ'),
('GR', 'Greece', 'EUR', 'GRC'),
('GS', 'South Georgia and the South Sandwich Islands', 'GBP', 'SGS'),
('GT', 'Guatemala', 'GTQ', 'GTM'),
('GU', 'Guam', 'USD', 'GUM'),
('GW', 'Guinea-Bissau', 'XOF', 'GNB'),
('GY', 'Guyana', 'GYD', 'GUY'),
('HK', 'Hong Kong', 'HKD', 'HKG'),
('HM', 'Heard Island and McDonald Islands', 'AUD', 'HMD'),
('HN', 'Honduras', 'HNL', 'HND'),
('HR', 'Croatia', 'HRK', 'HRV'),
('HT', 'Haiti', 'HTG', 'HTI'),
('HU', 'Hungary', 'HUF', 'HUN'),
('ID', 'Indonesia', 'IDR', 'IDN'),
('IE', 'Ireland', 'EUR', 'IRL'),
('IL', 'Israel', 'ILS', 'ISR'),
('IM', 'Isle of Man', 'GBP', 'IMN'),
('IN', 'India', 'INR', 'IND'),
('IO', 'British Indian Ocean Territory', 'USD', 'IOT'),
('IQ', 'Iraq', 'IQD', 'IRQ'),
('IR', 'Iran', 'IRR', 'IRN'),
('IS', 'Iceland', 'ISK', 'ISL'),
('IT', 'Italy', 'EUR', 'ITA'),
('JE', 'Jersey', 'GBP', 'JEY'),
('JM', 'Jamaica', 'JMD', 'JAM'),
('JO', 'Jordan', 'JOD', 'JOR'),
('JP', 'Japan', 'JPY', 'JPN'),
('KE', 'Kenya', 'KES', 'KEN'),
('KG', 'Kyrgyzstan', 'KGS', 'KGZ'),
('KH', 'Cambodia', 'KHR', 'KHM'),
('KI', 'Kiribati', 'AUD', 'KIR'),
('KM', 'Comoros', 'KMF', 'COM'),
('KN', 'Saint Kitts and Nevis', 'XCD', 'KNA'),
('KP', 'North Korea', 'KPW', 'PRK'),
('KR', 'South Korea', 'KRW', 'KOR'),
('KW', 'Kuwait', 'KWD', 'KWT'),
('KY', 'Cayman Islands', 'KYD', 'CYM'),
('KZ', 'Kazakhstan', 'KZT', 'KAZ'),
('LA', 'Laos', 'LAK', 'LAO'),
('LB', 'Lebanon', 'LBP', 'LBN'),
('LC', 'Saint Lucia', 'XCD', 'LCA'),
('LI', 'Liechtenstein', 'CHF', 'LIE'),
('LK', 'Sri Lanka', 'LKR', 'LKA'),
('LR', 'Liberia', 'LRD', 'LBR'),
('LS', 'Lesotho', 'LSL', 'LSO'),
('LT', 'Lithuania', 'LTL', 'LTU'),
('LU', 'Luxembourg', 'EUR', 'LUX'),
('LV', 'Latvia', 'LVL', 'LVA'),
('LY', 'Libya', 'LYD', 'LBY'),
('MA', 'Morocco', 'MAD', 'MAR'),
('MC', 'Monaco', 'EUR', 'MCO'),
('MD', 'Moldova', 'MDL', 'MDA'),
('ME', 'Montenegro', 'EUR', 'MNE'),
('MF', 'Saint Martin', 'EUR', 'MAF'),
('MG', 'Madagascar', 'MGA', 'MDG'),
('MH', 'Marshall Islands', 'USD', 'MHL'),
('MK', 'Macedonia', 'MKD', 'MKD'),
('ML', 'Mali', 'XOF', 'MLI'),
('MM', 'Myanmar [Burma]', 'MMK', 'MMR'),
('MN', 'Mongolia', 'MNT', 'MNG'),
('MO', 'Macao', 'MOP', 'MAC'),
('MP', 'Northern Mariana Islands', 'USD', 'MNP'),
('MQ', 'Martinique', 'EUR', 'MTQ'),
('MR', 'Mauritania', 'MRO', 'MRT'),
('MS', 'Montserrat', 'XCD', 'MSR'),
('MT', 'Malta', 'EUR', 'MLT'),
('MU', 'Mauritius', 'MUR', 'MUS'),
('MV', 'Maldives', 'MVR', 'MDV'),
('MW', 'Malawi', 'MWK', 'MWI'),
('MX', 'Mexico', 'MXN', 'MEX'),
('MY', 'Malaysia', 'MYR', 'MYS'),
('MZ', 'Mozambique', 'MZN', 'MOZ'),
('NA', 'Namibia', 'NAD', 'NAM'),
('NC', 'New Caledonia', 'XPF', 'NCL'),
('NE', 'Niger', 'XOF', 'NER'),
('NF', 'Norfolk Island', 'AUD', 'NFK'),
('NG', 'Nigeria', 'NGN', 'NGA'),
('NI', 'Nicaragua', 'NIO', 'NIC'),
('NL', 'Netherlands', 'EUR', 'NLD'),
('NO', 'Norway', 'NOK', 'NOR'),
('NP', 'Nepal', 'NPR', 'NPL'),
('NR', 'Nauru', 'AUD', 'NRU'),
('NU', 'Niue', 'NZD', 'NIU'),
('NZ', 'New Zealand', 'NZD', 'NZL'),
('OM', 'Oman', 'OMR', 'OMN'),
('PA', 'Panama', 'PAB', 'PAN'),
('PE', 'Peru', 'PEN', 'PER'),
('PF', 'French Polynesia', 'XPF', 'PYF'),
('PG', 'Papua New Guinea', 'PGK', 'PNG'),
('PH', 'Philippines', 'PHP', 'PHL'),
('PK', 'Pakistan', 'PKR', 'PAK'),
('PL', 'Poland', 'PLN', 'POL'),
('PM', 'Saint Pierre and Miquelon', 'EUR', 'SPM'),
('PN', 'Pitcairn Islands', 'NZD', 'PCN'),
('PR', 'Puerto Rico', 'USD', 'PRI'),
('PS', 'Palestine', 'ILS', 'PSE'),
('PT', 'Portugal', 'EUR', 'PRT'),
('PW', 'Palau', 'USD', 'PLW'),
('PY', 'Paraguay', 'PYG', 'PRY'),
('QA', 'Qatar', 'QAR', 'QAT'),
('RE', 'Réunion', 'EUR', 'REU'),
('RO', 'Romania', 'RON', 'ROU'),
('RS', 'Serbia', 'RSD', 'SRB'),
('RU', 'Russia', 'RUB', 'RUS'),
('RW', 'Rwanda', 'RWF', 'RWA'),
('SA', 'Saudi Arabia', 'SAR', 'SAU'),
('SB', 'Solomon Islands', 'SBD', 'SLB'),
('SC', 'Seychelles', 'SCR', 'SYC'),
('SD', 'Sudan', 'SDG', 'SDN'),
('SE', 'Sweden', 'SEK', 'SWE'),
('SG', 'Singapore', 'SGD', 'SGP'),
('SH', 'Saint Helena', 'SHP', 'SHN'),
('SI', 'Slovenia', 'EUR', 'SVN'),
('SJ', 'Svalbard and Jan Mayen', 'NOK', 'SJM'),
('SK', 'Slovakia', 'EUR', 'SVK'),
('SL', 'Sierra Leone', 'SLL', 'SLE'),
('SM', 'San Marino', 'EUR', 'SMR'),
('SN', 'Senegal', 'XOF', 'SEN'),
('SO', 'Somalia', 'SOS', 'SOM'),
('SR', 'Suriname', 'SRD', 'SUR'),
('SS', 'South Sudan', 'SSP', 'SSD'),
('ST', 'São Tomé and Príncipe', 'STD', 'STP'),
('SV', 'El Salvador', 'USD', 'SLV'),
('SX', 'Sint Maarten', 'ANG', 'SXM'),
('SY', 'Syria', 'SYP', 'SYR'),
('SZ', 'Swaziland', 'SZL', 'SWZ'),
('TC', 'Turks and Caicos Islands', 'USD', 'TCA'),
('TD', 'Chad', 'XAF', 'TCD'),
('TF', 'French Southern Territories', 'EUR', 'ATF'),
('TG', 'Togo', 'XOF', 'TGO'),
('TH', 'Thailand', 'THB', 'THA'),
('TJ', 'Tajikistan', 'TJS', 'TJK'),
('TK', 'Tokelau', 'NZD', 'TKL'),
('TL', 'East Timor', 'USD', 'TLS'),
('TM', 'Turkmenistan', 'TMT', 'TKM'),
('TN', 'Tunisia', 'TND', 'TUN'),
('TO', 'Tonga', 'TOP', 'TON'),
('TR', 'Turkey', 'TRY', 'TUR'),
('TT', 'Trinidad and Tobago', 'TTD', 'TTO'),
('TV', 'Tuvalu', 'AUD', 'TUV'),
('TW', 'Taiwan', 'TWD', 'TWN'),
('TZ', 'Tanzania', 'TZS', 'TZA'),
('UA', 'Ukraine', 'UAH', 'UKR'),
('UG', 'Uganda', 'UGX', 'UGA'),
('UM', 'U.S. Minor Outlying Islands', 'USD', 'UMI'),
('US', 'United States', 'USD', 'USA'),
('UY', 'Uruguay', 'UYU', 'URY'),
('UZ', 'Uzbekistan', 'UZS', 'UZB'),
('VA', 'Vatican City', 'EUR', 'VAT'),
('VC', 'Saint Vincent and the Grenadines', 'XCD', 'VCT'),
('VE', 'Venezuela', 'VEF', 'VEN'),
('VG', 'British Virgin Islands', 'USD', 'VGB'),
('VI', 'U.S. Virgin Islands', 'USD', 'VIR'),
('VN', 'Vietnam', 'VND', 'VNM'),
('VU', 'Vanuatu', 'VUV', 'VUT'),
('WF', 'Wallis and Futuna', 'XPF', 'WLF'),
('WS', 'Samoa', 'WST', 'WSM'),
('XK', 'Kosovo', 'EUR', 'XKX'),
('YE', 'Yemen', 'YER', 'YEM'),
('YT', 'Mayotte', 'EUR', 'MYT'),
('ZA', 'South Africa', 'ZAR', 'ZAF'),
('ZM', 'Zambia', 'ZMK', 'ZMB'),
('ZW', 'Zimbabwe', 'ZWL', 'ZWE')";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_PAYPAL);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
sandbox VARCHAR(5) NOT NULL DEFAULT 'YES',
username VARCHAR(100) NOT NULL DEFAULT '',
password VARCHAR(100) NOT NULL DEFAULT '',
signature VARCHAR(100) NOT NULL DEFAULT '')";
Database::query($sql);
$sql = "INSERT INTO $table (id,username,password,signature) VALUES ('1', 'API_UserName', 'API_Password', 'API_Signature')";
Database::query($sql);
$table = Database::get_main_table(TABLE_BUY_COURSE_TRANSFER);
$sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY,
name VARCHAR(100) NOT NULL DEFAULT '',
account VARCHAR(100) NOT NULL DEFAULT '',
swift VARCHAR(100) NOT NULL DEFAULT '')";
Database::query($sql);
foreach ($queries as $query) {
Database::query($query);
}
$table = Database::get_main_table(TABLE_BUY_SESSION_TEMPORARY);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
user_id INT unsigned NOT NULL,
name VARCHAR(255) NOT NULL DEFAULT '',
session_id INT unsigned NOT NULL DEFAULT '0',
title VARCHAR(200) NOT NULL DEFAULT '',
reference VARCHAR(20) NOT NULL DEFAULT '',
price FLOAT(11,2) NOT NULL DEFAULT '0',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
//Insert data
$paypalTable = Database::get_main_table(BuyCoursesUtils::TABLE_PAYPAL);
$currencyTable = Database::get_main_table(BuyCoursesUtils::TABLE_CURRENCY);
$itemTable = Database::get_main_table(BuyCoursesUtils::TABLE_ITEM);
$saleTable = Database::get_main_table(BuyCoursesUtils::TABLE_SALE);
$table = Database::get_main_table(TABLE_BUY_COURSE_TEMPORAL);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
user_id INT unsigned NOT NULL,
name VARCHAR(255) NOT NULL DEFAULT '',
course_code VARCHAR(200) NOT NULL DEFAULT '',
title VARCHAR(200) NOT NULL DEFAULT '',
reference VARCHAR(20) NOT NULL DEFAULT '',
price FLOAT(11,2) NOT NULL DEFAULT '0',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
Database::insert(
$paypalTable,
[
'username' => 'API_UserName',
'password' => 'API_Password',
'signature' => 'API_Signature',
'sandbox' => true
]
);
$table = Database::get_main_table(TABLE_BUY_SESSION_SALE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
user_id INT unsigned NOT NULL,
session_id INT unsigned NOT NULL DEFAULT '0',
price FLOAT(11,2) NOT NULL DEFAULT '0',
payment_type VARCHAR(100) NOT NULL DEFAULT '',
status VARCHAR(20) NOT NULL DEFAULT '',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
$currencies = [
['AD', 'Andorra', 'EUR', 'AND'],
['AE', 'United Arab Emirates', 'AED', 'ARE'],
['AF', 'Afghanistan', 'AFN', 'AFG'],
['AG', 'Antigua and Barbuda', 'XCD', 'ATG'],
['AI', 'Anguilla', 'XCD', 'AIA'],
['AL', 'Albania', 'ALL', 'ALB'],
['AM', 'Armenia', 'AMD', 'ARM'],
['AO', 'Angola', 'AOA', 'AGO'],
['AR', 'Argentina', 'ARS', 'ARG'],
['AS', 'American Samoa', 'USD', 'ASM'],
['AT', 'Austria', 'EUR', 'AUT'],
['AU', 'Australia', 'AUD', 'AUS'],
['AW', 'Aruba', 'AWG', 'ABW'],
['AX', 'Åland', 'EUR', 'ALA'],
['AZ', 'Azerbaijan', 'AZN', 'AZE'],
['BA', 'Bosnia and Herzegovina', 'BAM', 'BIH'],
['BB', 'Barbados', 'BBD', 'BRB'],
['BD', 'Bangladesh', 'BDT', 'BGD'],
['BE', 'Belgium', 'EUR', 'BEL'],
['BF', 'Burkina Faso', 'XOF', 'BFA'],
['BG', 'Bulgaria', 'BGN', 'BGR'],
['BH', 'Bahrain', 'BHD', 'BHR'],
['BI', 'Burundi', 'BIF', 'BDI'],
['BJ', 'Benin', 'XOF', 'BEN'],
['BL', 'Saint Barthélemy', 'EUR', 'BLM'],
['BM', 'Bermuda', 'BMD', 'BMU'],
['BN', 'Brunei', 'BND', 'BRN'],
['BO', 'Bolivia', 'BOB', 'BOL'],
['BQ', 'Bonaire', 'USD', 'BES'],
['BR', 'Brazil', 'BRL', 'BRA'],
['BS', 'Bahamas', 'BSD', 'BHS'],
['BT', 'Bhutan', 'BTN', 'BTN'],
['BV', 'Bouvet Island', 'NOK', 'BVT'],
['BW', 'Botswana', 'BWP', 'BWA'],
['BY', 'Belarus', 'BYR', 'BLR'],
['BZ', 'Belize', 'BZD', 'BLZ'],
['CA', 'Canada', 'CAD', 'CAN'],
['CC', 'Cocos [Keeling] Islands', 'AUD', 'CCK'],
['CD', 'Congo', 'CDF', 'COD'],
['CF', 'Central African Republic', 'XAF', 'CAF'],
['CG', 'Republic of the Congo', 'XAF', 'COG'],
['CH', 'Switzerland', 'CHF', 'CHE'],
['CI', 'Ivory Coast', 'XOF', 'CIV'],
['CK', 'Cook Islands', 'NZD', 'COK'],
['CL', 'Chile', 'CLP', 'CHL'],
['CM', 'Cameroon', 'XAF', 'CMR'],
['CN', 'China', 'CNY', 'CHN'],
['CO', 'Colombia', 'COP', 'COL'],
['CR', 'Costa Rica', 'CRC', 'CRI'],
['CU', 'Cuba', 'CUP', 'CUB'],
['CV', 'Cape Verde', 'CVE', 'CPV'],
['CW', 'Curacao', 'ANG', 'CUW'],
['CX', 'Christmas Island', 'AUD', 'CXR'],
['CY', 'Cyprus', 'EUR', 'CYP'],
['CZ', 'Czechia', 'CZK', 'CZE'],
['DE', 'Germany', 'EUR', 'DEU'],
['DJ', 'Djibouti', 'DJF', 'DJI'],
['DK', 'Denmark', 'DKK', 'DNK'],
['DM', 'Dominica', 'XCD', 'DMA'],
['DO', 'Dominican Republic', 'DOP', 'DOM'],
['DZ', 'Algeria', 'DZD', 'DZA'],
['EC', 'Ecuador', 'USD', 'ECU'],
['EE', 'Estonia', 'EUR', 'EST'],
['EG', 'Egypt', 'EGP', 'EGY'],
['EH', 'Western Sahara', 'MAD', 'ESH'],
['ER', 'Eritrea', 'ERN', 'ERI'],
['ES', 'Spain', 'EUR', 'ESP'],
['ET', 'Ethiopia', 'ETB', 'ETH'],
['FI', 'Finland', 'EUR', 'FIN'],
['FJ', 'Fiji', 'FJD', 'FJI'],
['FK', 'Falkland Islands', 'FKP', 'FLK'],
['FM', 'Micronesia', 'USD', 'FSM'],
['FO', 'Faroe Islands', 'DKK', 'FRO'],
['FR', 'France', 'EUR', 'FRA'],
['GA', 'Gabon', 'XAF', 'GAB'],
['GB', 'United Kingdom', 'GBP', 'GBR'],
['GD', 'Grenada', 'XCD', 'GRD'],
['GE', 'Georgia', 'GEL', 'GEO'],
['GF', 'French Guiana', 'EUR', 'GUF'],
['GG', 'Guernsey', 'GBP', 'GGY'],
['GH', 'Ghana', 'GHS', 'GHA'],
['GI', 'Gibraltar', 'GIP', 'GIB'],
['GL', 'Greenland', 'DKK', 'GRL'],
['GM', 'Gambia', 'GMD', 'GMB'],
['GN', 'Guinea', 'GNF', 'GIN'],
['GP', 'Guadeloupe', 'EUR', 'GLP'],
['GQ', 'Equatorial Guinea', 'XAF', 'GNQ'],
['GR', 'Greece', 'EUR', 'GRC'],
['GS', 'South Georgia and the South Sandwich Islands', 'GBP', 'SGS'],
['GT', 'Guatemala', 'GTQ', 'GTM'],
['GU', 'Guam', 'USD', 'GUM'],
['GW', 'Guinea-Bissau', 'XOF', 'GNB'],
['GY', 'Guyana', 'GYD', 'GUY'],
['HK', 'Hong Kong', 'HKD', 'HKG'],
['HM', 'Heard Island and McDonald Islands', 'AUD', 'HMD'],
['HN', 'Honduras', 'HNL', 'HND'],
['HR', 'Croatia', 'HRK', 'HRV'],
['HT', 'Haiti', 'HTG', 'HTI'],
['HU', 'Hungary', 'HUF', 'HUN'],
['ID', 'Indonesia', 'IDR', 'IDN'],
['IE', 'Ireland', 'EUR', 'IRL'],
['IL', 'Israel', 'ILS', 'ISR'],
['IM', 'Isle of Man', 'GBP', 'IMN'],
['IN', 'India', 'INR', 'IND'],
['IO', 'British Indian Ocean Territory', 'USD', 'IOT'],
['IQ', 'Iraq', 'IQD', 'IRQ'],
['IR', 'Iran', 'IRR', 'IRN'],
['IS', 'Iceland', 'ISK', 'ISL'],
['IT', 'Italy', 'EUR', 'ITA'],
['JE', 'Jersey', 'GBP', 'JEY'],
['JM', 'Jamaica', 'JMD', 'JAM'],
['JO', 'Jordan', 'JOD', 'JOR'],
['JP', 'Japan', 'JPY', 'JPN'],
['KE', 'Kenya', 'KES', 'KEN'],
['KG', 'Kyrgyzstan', 'KGS', 'KGZ'],
['KH', 'Cambodia', 'KHR', 'KHM'],
['KI', 'Kiribati', 'AUD', 'KIR'],
['KM', 'Comoros', 'KMF', 'COM'],
['KN', 'Saint Kitts and Nevis', 'XCD', 'KNA'],
['KP', 'North Korea', 'KPW', 'PRK'],
['KR', 'South Korea', 'KRW', 'KOR'],
['KW', 'Kuwait', 'KWD', 'KWT'],
['KY', 'Cayman Islands', 'KYD', 'CYM'],
['KZ', 'Kazakhstan', 'KZT', 'KAZ'],
['LA', 'Laos', 'LAK', 'LAO'],
['LB', 'Lebanon', 'LBP', 'LBN'],
['LC', 'Saint Lucia', 'XCD', 'LCA'],
['LI', 'Liechtenstein', 'CHF', 'LIE'],
['LK', 'Sri Lanka', 'LKR', 'LKA'],
['LR', 'Liberia', 'LRD', 'LBR'],
['LS', 'Lesotho', 'LSL', 'LSO'],
['LT', 'Lithuania', 'LTL', 'LTU'],
['LU', 'Luxembourg', 'EUR', 'LUX'],
['LV', 'Latvia', 'LVL', 'LVA'],
['LY', 'Libya', 'LYD', 'LBY'],
['MA', 'Morocco', 'MAD', 'MAR'],
['MC', 'Monaco', 'EUR', 'MCO'],
['MD', 'Moldova', 'MDL', 'MDA'],
['ME', 'Montenegro', 'EUR', 'MNE'],
['MF', 'Saint Martin', 'EUR', 'MAF'],
['MG', 'Madagascar', 'MGA', 'MDG'],
['MH', 'Marshall Islands', 'USD', 'MHL'],
['MK', 'Macedonia', 'MKD', 'MKD'],
['ML', 'Mali', 'XOF', 'MLI'],
['MM', 'Myanmar [Burma]', 'MMK', 'MMR'],
['MN', 'Mongolia', 'MNT', 'MNG'],
['MO', 'Macao', 'MOP', 'MAC'],
['MP', 'Northern Mariana Islands', 'USD', 'MNP'],
['MQ', 'Martinique', 'EUR', 'MTQ'],
['MR', 'Mauritania', 'MRO', 'MRT'],
['MS', 'Montserrat', 'XCD', 'MSR'],
['MT', 'Malta', 'EUR', 'MLT'],
['MU', 'Mauritius', 'MUR', 'MUS'],
['MV', 'Maldives', 'MVR', 'MDV'],
['MW', 'Malawi', 'MWK', 'MWI'],
['MX', 'Mexico', 'MXN', 'MEX'],
['MY', 'Malaysia', 'MYR', 'MYS'],
['MZ', 'Mozambique', 'MZN', 'MOZ'],
['NA', 'Namibia', 'NAD', 'NAM'],
['NC', 'New Caledonia', 'XPF', 'NCL'],
['NE', 'Niger', 'XOF', 'NER'],
['NF', 'Norfolk Island', 'AUD', 'NFK'],
['NG', 'Nigeria', 'NGN', 'NGA'],
['NI', 'Nicaragua', 'NIO', 'NIC'],
['NL', 'Netherlands', 'EUR', 'NLD'],
['NO', 'Norway', 'NOK', 'NOR'],
['NP', 'Nepal', 'NPR', 'NPL'],
['NR', 'Nauru', 'AUD', 'NRU'],
['NU', 'Niue', 'NZD', 'NIU'],
['NZ', 'New Zealand', 'NZD', 'NZL'],
['OM', 'Oman', 'OMR', 'OMN'],
['PA', 'Panama', 'PAB', 'PAN'],
['PE', 'Peru', 'PEN', 'PER'],
['PF', 'French Polynesia', 'XPF', 'PYF'],
['PG', 'Papua New Guinea', 'PGK', 'PNG'],
['PH', 'Philippines', 'PHP', 'PHL'],
['PK', 'Pakistan', 'PKR', 'PAK'],
['PL', 'Poland', 'PLN', 'POL'],
['PM', 'Saint Pierre and Miquelon', 'EUR', 'SPM'],
['PN', 'Pitcairn Islands', 'NZD', 'PCN'],
['PR', 'Puerto Rico', 'USD', 'PRI'],
['PS', 'Palestine', 'ILS', 'PSE'],
['PT', 'Portugal', 'EUR', 'PRT'],
['PW', 'Palau', 'USD', 'PLW'],
['PY', 'Paraguay', 'PYG', 'PRY'],
['QA', 'Qatar', 'QAR', 'QAT'],
['RE', 'Réunion', 'EUR', 'REU'],
['RO', 'Romania', 'RON', 'ROU'],
['RS', 'Serbia', 'RSD', 'SRB'],
['RU', 'Russia', 'RUB', 'RUS'],
['RW', 'Rwanda', 'RWF', 'RWA'],
['SA', 'Saudi Arabia', 'SAR', 'SAU'],
['SB', 'Solomon Islands', 'SBD', 'SLB'],
['SC', 'Seychelles', 'SCR', 'SYC'],
['SD', 'Sudan', 'SDG', 'SDN'],
['SE', 'Sweden', 'SEK', 'SWE'],
['SG', 'Singapore', 'SGD', 'SGP'],
['SH', 'Saint Helena', 'SHP', 'SHN'],
['SI', 'Slovenia', 'EUR', 'SVN'],
['SJ', 'Svalbard and Jan Mayen', 'NOK', 'SJM'],
['SK', 'Slovakia', 'EUR', 'SVK'],
['SL', 'Sierra Leone', 'SLL', 'SLE'],
['SM', 'San Marino', 'EUR', 'SMR'],
['SN', 'Senegal', 'XOF', 'SEN'],
['SO', 'Somalia', 'SOS', 'SOM'],
['SR', 'Suriname', 'SRD', 'SUR'],
['SS', 'South Sudan', 'SSP', 'SSD'],
['ST', 'São Tomé and Príncipe', 'STD', 'STP'],
['SV', 'El Salvador', 'USD', 'SLV'],
['SX', 'Sint Maarten', 'ANG', 'SXM'],
['SY', 'Syria', 'SYP', 'SYR'],
['SZ', 'Swaziland', 'SZL', 'SWZ'],
['TC', 'Turks and Caicos Islands', 'USD', 'TCA'],
['TD', 'Chad', 'XAF', 'TCD'],
['TF', 'French Southern Territories', 'EUR', 'ATF'],
['TG', 'Togo', 'XOF', 'TGO'],
['TH', 'Thailand', 'THB', 'THA'],
['TJ', 'Tajikistan', 'TJS', 'TJK'],
['TK', 'Tokelau', 'NZD', 'TKL'],
['TL', 'East Timor', 'USD', 'TLS'],
['TM', 'Turkmenistan', 'TMT', 'TKM'],
['TN', 'Tunisia', 'TND', 'TUN'],
['TO', 'Tonga', 'TOP', 'TON'],
['TR', 'Turkey', 'TRY', 'TUR'],
['TT', 'Trinidad and Tobago', 'TTD', 'TTO'],
['TV', 'Tuvalu', 'AUD', 'TUV'],
['TW', 'Taiwan', 'TWD', 'TWN'],
['TZ', 'Tanzania', 'TZS', 'TZA'],
['UA', 'Ukraine', 'UAH', 'UKR'],
['UG', 'Uganda', 'UGX', 'UGA'],
['UM', 'U.S. Minor Outlying Islands', 'USD', 'UMI'],
['US', 'United States', 'USD', 'USA'],
['UY', 'Uruguay', 'UYU', 'URY'],
['UZ', 'Uzbekistan', 'UZS', 'UZB'],
['VA', 'Vatican City', 'EUR', 'VAT'],
['VC', 'Saint Vincent and the Grenadines', 'XCD', 'VCT'],
['VE', 'Venezuela', 'VEF', 'VEN'],
['VG', 'British Virgin Islands', 'USD', 'VGB'],
['VI', 'U.S. Virgin Islands', 'USD', 'VIR'],
['VN', 'Vietnam', 'VND', 'VNM'],
['VU', 'Vanuatu', 'VUV', 'VUT'],
['WF', 'Wallis and Futuna', 'XPF', 'WLF'],
['WS', 'Samoa', 'WST', 'WSM'],
['XK', 'Kosovo', 'EUR', 'XKX'],
['YE', 'Yemen', 'YER', 'YEM'],
['YT', 'Mayotte', 'EUR', 'MYT'],
['ZA', 'South Africa', 'ZAR', 'ZAF'],
['ZM', 'Zambia', 'ZMK', 'ZMB'],
['ZW', 'Zimbabwe', 'ZWL', 'ZWE']
];
$table = Database::get_main_table(TABLE_BUY_COURSE_SALE);
$sql = "CREATE TABLE IF NOT EXISTS $table (
cod INT unsigned NOT NULL auto_increment PRIMARY KEY,
user_id INT unsigned NOT NULL,
course_code VARCHAR(200) NOT NULL DEFAULT '',
price FLOAT(11,2) NOT NULL DEFAULT '0',
payment_type VARCHAR(100) NOT NULL DEFAULT '',
status VARCHAR(20) NOT NULL DEFAULT '',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
foreach ($currencies as $currency) {
Database::insert(
$currencyTable,
[
'country_code' => $currency[0],
'country_name' => $currency[1],
'iso_code' => $currency[2]
]
);
}

@ -9,16 +9,19 @@ use \Doctrine\DBAL\Types\Type;
class BuyCoursesUtils
{
const TABLE_PAYPAL = 'plugin_buycourses_paypal_account';
const TABLE_CURRENCY = 'plugin_buycourses_currency';
const TABLE_ITEM = 'plugin_buycourses_item';
const TABLE_SALE = 'plugin_buycourses_sale';
const TABLE_TRANSFER = 'plugin_buycourses_transfer';
const TABLE_SESSION = 'plugin_buy_session';
const TABLE_SESSION_COURSE = 'plugin_buy_session_course';
const TABLE_SESSION_TEMPORARY = 'plugin_buy_session_temporary';
const TABLE_SESSION_SALE = 'plugin_buy_session_sale';
const TABLE_COURSE = 'plugin_buy_course';
const TABLE_COUNTRY = 'plugin_buy_course_country';
const TABLE_PAYPAL = 'plugin_buy_course_paypal';
const TABLE_TRANSFER = 'plugin_buy_course_transfer';
const TABLE_TEMPORAL = 'plugin_buy_course_temporal';
const TABLE_SALE = 'plugin_buy_course_sale';
private static $plugin;

@ -12,6 +12,9 @@
*/
class BuyCoursesPlugin extends Plugin
{
const PRODUCT_TYPE_COURSE = 1;
const PRODUCT_TYPE_SESSION = 2;
/**
*
* @return StaticPlugin

Loading…
Cancel
Save