Commit b952198f authored by Jack Stupple's avatar Jack Stupple

make localization a little better

parent 12880274
......@@ -5,7 +5,8 @@ namespace App\Http\Controllers\Api;
class LanguageController extends Controller
{
public function index() {
return \App\Language::all();
// raw because <= NOW() is mysql directly into the function and the builder will misunderstand it otherwise
return \App\Language::whereRaw('enabled <= NOW()')->where('enabled', '!=', NULL)->get();
}
public function default() {
......
......@@ -13,6 +13,7 @@ class SeasonRoundupController extends Controller
return \App\SeasonRoundup::with('modifiers')
->where('character_id', $player->character_id)
->where('language_id', $player->language_id)
->orderBy('order')
->get();
}
......@@ -33,6 +34,7 @@ class SeasonRoundupController extends Controller
if (!$has_history) {
$roundups = SeasonRoundup::with(['modifiers', 'modifiers.modifierCategory'])
->where('character_id', $player->character_id)
->where('language_id', $player->language_id)
->whereRaw('`id` NOT IN (select `season_roundup_id` from `player_history` where `player_id` = ' . $player->id . ' and `season_roundup_id` is not null AND `playthrough` = ' . $player->playthrough . ')')
->orderBy('id', 'RAND()')
->limit(round(rand(1,4)))
......
......@@ -143,165 +143,15 @@ class Initial extends Migration
["Startups", "investments"],
["Store credit", "loans"],
["Prepaid Cards", "banking"],
["Packaged Accounts", "banking"]
["Packaged Accounts", "banking"],
["Mortgages", "loans"],
["Retirement", "investments"]
];
static $resources = [
[
'name' => 'Borrowing and credit basics',
'link' => 'https://www.moneyadviceservice.org.uk/en/articles/borrowing-and-credit-basics',
'category' => 'Borrowing money'
],
[
'name' => 'Borrowing money and paying it back',
'link' => 'https://www.youtube.com/watch?time_continue=1&v=IsZu0fjxR2U',
'category' => 'Borrowing money'
],
[
'name' => 'Calculating the cost of borrowing',
'link' => 'https://www.moneyadviceservice.org.uk/en/articles/how-to-work-out-the-true-cost-of-borrowing',
'category' => 'Borrowing money'
],
[
'name' => 'Compare mobile phone deal',
'link' => 'https://mobile-phones.confused.com',
'category' => 'Phone deals'
],
[
'name' => 'Compare the latest Mobile Phone deals',
'link' => 'https://www.moneysupermarket.com/mobile-phones/',
'category' => 'Phone deals'
],
[
'name' => 'Credit options',
'link' => 'http://www.experian.co.uk/downloads/consumer/gettingCredit/gettingCreditDownload.pdf',
'category' => 'Credit options'
],
[
'name' => 'Different type of bank accounts',
'link' => 'http://readanddigest.com/different-types-of-bank-accounts/',
'category' => 'Accounts'
],
[
'name' => 'Do you need to borrow money',
'link' => 'https://www.moneyadviceservice.org.uk/en/articles/do-you-need-to-borrow-money',
'category' => 'Borrowing money'
],
[
'name' => 'How to save for a car',
'link' => 'https://www.nerdwallet.com/blog/finance/how-to-save-for-a-car/',
'category' => 'Saving for a car'
],
[
'name' => 'Just Made Your Last Car Payment?',
'link' => 'https://www.thebalance.com/just-made-your-last-car-payment-start-paying-yourself-453779',
'category' => 'Car repayments'
],
[
'name' => 'Learn about budgeting',
'link' => 'https://www.practicalmoneyskills.com/learn/budgeting',
'category' => 'Budgeting'
],
[
'name' => 'Learn about credit cards',
'link' => 'https://en.wikipedia.org/wiki/Credit_card',
'category' => 'Credit cards'
],
[
'name' => 'Learn about loans',
'link' => 'https://en.wikipedia.org/wiki/Loan',
'category' => 'Loans'
],
[
'name' => 'Learn about payday loans',
'link' => 'https://en.wikipedia.org/wiki/Payday_loan',
'category' => 'Payday loans'
],
[
'name' => 'Learn about payday loans',
'link' => 'https://www.moneyadviceservice.org.uk/en/payday-loans',
'category' => 'Payday loans'
],
[
'name' => 'Learn about phone depreciation',
'link' => 'https://atotaxrates.info/tax-deductions/ato-depreciation/depreciation-mobile-phone/',
'category' => 'Phone Depreciation'
],
[
'name' => 'Learn about saving',
'link' => 'https://en.wikipedia.org/wiki/Saving',
'category' => 'Savings'
],
[
'name' => 'Learn about saving accounts',
'link' => 'https://en.wikipedia.org/wiki/Savings_account',
'category' => 'Savings'
],
[
'name' => 'Learn about saving accounts',
'link' => 'https://www.investopedia.com/terms/s/savingsaccount.asp?ad=dirN&qo=investopediaSiteSearch&qsrc=0&o=40186',
'category' => 'Savings'
],
[
'name' => 'Learning about interest rates',
'link' => 'https://www.investopedia.com/terms/i/interestrate.asp',
'category' => 'Interest rates'
],
[
'name' => 'Payday loans',
'link' => 'https://www.moneyadviceservice.org.uk/en/payday-loans',
'category' => 'Payday loans'
],
[
'name' => 'Personal loans and overdraft',
'link' => 'https://www.moneyadviceservice.org.uk/en/articles/borrowing-and-credit-basics',
'category' => 'Borrowing money'
],
[
'name' => 'See mobile phone deals',
'link' => 'https://www.mobilephonechecker.co.uk',
'category' => 'Phone deals'
],
[
'name' => 'Store credit vs credit cards',
'link' => 'https://www.investopedia.com/articles/pf/10/credit-card-debit-card.asp',
'category' => 'Debit cards'
],
[
'name' => 'The cost of your loan',
'link' => 'https://www.moneyadviceservice.org.uk/en/tools/loan-calculator',
'category' => 'Loans'
],
[
'name' => 'The pros and cons of crowfounding',
'link' => 'https://www.cnbc.com/2017/07/05/can-you-get-rich-by-investing-in-a-startup-how-to-do-it--and-the-pros-and-cons-of-crowdfunding.html',
'category' => 'Startups'
],
[
'name' => 'There are pros and cons in borrowing from friends / family ',
'link' => 'https://www.moneyadviceservice.org.uk/en/articles/should-you-borrow-from-family-or-friends#pros-and-cons-of-borrowing-from-family-and-friends',
'category' => 'Borrowing money'
],
[
'name' => 'What is \'Cash\'?',
'link' => 'https://www.investopedia.com/terms/c/cash.asp?ad=dirN&qo=serpSearchTopBox&qsrc=1&o=40186',
'category' => 'Cash'
],
[
'name' => 'What is a bond?',
'link' => 'https://en.wikipedia.org/wiki/Bond_(finance)',
'category' => 'Bonds'
],
[
'name' => 'Your Phone Loses Value Pretty Fast ',
'link' => 'https://priceonomics.com/phones/',
'category' => 'Phone Depreciation'
],
];
// ^ import this stuff tomorrow, via the db migration
static $resources = '/resources/data/resources.csv';
protected $created_at = null;
protected $language = null;
/**
* Run the migrations.
......@@ -350,6 +200,7 @@ class Initial extends Migration
$blueprint->increments('id');
$blueprint->string('name');
$blueprint->string('slug');
$blueprint->timestamp('enabled')->nullable();
$blueprint->timestamps();
// $blueprint->unique('slug');
......@@ -359,6 +210,21 @@ class Initial extends Migration
DB::table('languages')->insert([
'name' => 'English',
'slug' => 'en',
'enabled' => $this->created_at,
'created_at' => $this->created_at
]);
DB::table('languages')->insert([
'name' => 'Français',
'slug' => 'fr',
'enabled' => getenv('APP_ENV') === 'local' ? $this->created_at : null,
'created_at' => $this->created_at
]);
DB::table('languages')->insert([
'name' => 'Deutch',
'slug' => 'de',
'enabled' => null,
'created_at' => $this->created_at
]);
......@@ -454,7 +320,7 @@ class Initial extends Migration
$modifier_categories = static::$modifier_categories;
foreach ($modifier_categories as &$category) {
if (isset($category['icon'])) {
$category['icon'] = 'data:image/png;base64,' . base64_encode(file_get_contents(dirname(dirname(__DIR__)) . '/resources/assets/icons/modifier-categories/' . $category['icon']));
$category['icon'] = 'data:image/png;base64,' . base64_encode(file_get_contents(APP_ROOT . '/resources/assets/icons/modifier-categories/' . $category['icon']));
}
}
......@@ -522,6 +388,7 @@ class Initial extends Migration
'season_roundups',
function (Blueprint $blueprint) {
$blueprint->increments('id');
$blueprint->integer('language_id');
$blueprint->integer('character_id');
$blueprint->string('roundup_text');
$blueprint->integer('positive_negative'); // 1 is good and -1 is bad
......@@ -540,17 +407,24 @@ class Initial extends Migration
$resource_category->save();
}
foreach (static::$resources as $_resource) {
$category = \App\ResourceCategory::where('name', 'LIKE', $_resource['category'])->first();
$resources_csv_handle = fopen(APP_ROOT . static::$resources, 'r');
$headers = false;
while (($_resource = fgetcsv($resources_csv_handle)) !== false) {
if (empty($headers)) {
$headers = true;
continue;
}
$category = \App\ResourceCategory::where('name', 'LIKE', $_resource[1])->first();
if (!$category) {
exit ('category missing:' . $_resource['category']);
exit ('category missing:' . $_resource[1]);
}
$resource = new \App\Resource;
$resource->language_id = $this->language->id;
$resource->name = $_resource['name'];
$resource->link = $_resource['link'];
$resource->name = $_resource[2];
$resource->link = $_resource[3];
$resource->save();
$resource->categories()->syncWithoutDetaching($category);
......
......@@ -25,7 +25,8 @@ class ImportEmilyQuestions extends CharacterMigration
public function up()
{
$this->created_at = date('Y-m-d H:i:s');
$this->language = \App\Language::where('slug', 'en')->first();
// test importing emily in french
$this->language = \App\Language::where('slug', getenv('APP_ENV') === 'local' ? 'fr' : 'en')->first();
$this->character = new \App\Character();
$this->character->name = 'Emily';
......
......@@ -4,6 +4,13 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
/**
* Class CharacterMigration
* Additional helpers that take a standardised data format and imports it into the required tables, making it easier to
* create character imports.
*
* @note: This class must be manually included at the top of the PHP file as it is not recognized by composer.
*/
class CharacterMigration extends Migration
{
protected function profilePictures($json_location)
......@@ -115,6 +122,7 @@ class CharacterMigration extends Migration
foreach (json_decode(file_get_contents($json_location), 1) as $_roundup) {
$roundup = new \App\SeasonRoundup;
$roundup->language_id = $this->language->id;
$roundup->roundup_text = $_roundup['roundup_text'];
$roundup->positive_negative = $_roundup['positive_negative'];
$roundup->character_id = $this->character->id;
......
RESOURCE GROUPS,CATEGORY,TITLE,UK ASSET,NL ASSET,FR ASSET
banking,Accounts,Types of bank accounts,http://readanddigest.com/different-types-of-bank-accounts/,https://www.wikifin.be/nl/themas/uw-dagelijks-geld/bankrekeningen/bankrekening,
budgeting,Savings,Learn about saving,https://en.wikipedia.org/wiki/Saving,https://no.wikipedia.org/wiki/Sparing,
budgeting,Savings,Learn about saving accounts,https://www.investopedia.com/terms/s/savingsaccount.asp?ad=dirN&qo=investopediaSiteSearch&qsrc=0&o=40186,,
loans,Interest rates,Learning about interest rates,https://www.investopedia.com/terms/i/interestrate.asp,,
banking,Debit cards,Store credit vs credit cards,https://www.investopedia.com/articles/pf/10/credit-card-debit-card.asp,,
loans,Interest,What is interest?,https://www.thebalance.com/what-is-interest-315436,,
budgeting,Phone deals,Comparing phone contracts,https://mobile-phones.confused.com,,
budgeting,Saving for a car,How to save for a car,https://www.nerdwallet.com/blog/finance/how-to-save-for-a-car/,,
budgeting,Saving for a car,Finance advice on buying a car,https://personal.natwest.com/personal/life-moments/buying-a-car.html,,
loans,Car repayments,Car repayment tips,https://www.thebalance.com/just-made-your-last-car-payment-start-paying-yourself-453779,,
budgeting,Budgeting,Learn about budgeting,https://www.practicalmoneyskills.com/learn/budgeting,,
budgeting,Phone deals,View mobile phone deals,https://www.mobilephonechecker.co.uk,https://www.phonearena.com/phones#/phones/sort/popular,
loans,Borrowing money,Borrowing and credit basics,https://www.moneyadviceservice.org.uk/en/articles/borrowing-and-credit-basics,,
loans,Borrowing money,Borrowing money and paying it back,https://www.youtube.com/watch?time_continue=1&v=IsZu0fjxR2U ,,
loans,Borrowing money,Calculating the cost of borrowing,https://www.moneyadviceservice.org.uk/en/articles/how-to-work-out-the-true-cost-of-borrowing,,
investments,Phone Depreciation,Learn about phone depreciation,https://atotaxrates.info/tax-deductions/ato-depreciation/depreciation-mobile-phone/,,
loans,Borrowing money,Personal loans and overdraft,https://www.moneyadviceservice.org.uk/en/articles/borrowing-and-credit-basics,,
loans,Borrowing money,The pros and cons of borrowing from friends / family ,https://www.moneyadviceservice.org.uk/en/articles/should-you-borrow-from-family-or-friends#pros-and-cons-of-borrowing-from-family-and-friends,,
banking,Cash,What is 'Cash'?,https://www.investopedia.com/terms/c/cash.asp?ad=dirN&qo=serpSearchTopBox&qsrc=1&o=40186,https://www.investopedia.com/articles/pf/08/pay-in-cash.asp?ad=dirN&qo=serpSearchTopBox&qsrc=1&o=40186,
investments,Phone Depreciation,Phone depreciation,https://priceonomics.com/phones/,,
investments,Startups,The pros and cons of crowdfunding,https://www.cnbc.com/2017/07/05/can-you-get-rich-by-investing-in-a-startup-how-to-do-it--and-the-pros-and-cons-of-crowdfunding.html,https://www.wikifin.be/nl/themas/sparen-en-beleggen/aandelen/wat-een-aandeel,
investments,Bonds,What is a Bond?,https://en.wikipedia.org/wiki/Bond_(finance),https://www.wikifin.be/nl/themas/sparen-en-beleggen/obligaties/wat-een-obligatie,
loans,Credit options,Credit options ,http://www.experian.co.uk/downloads/consumer/gettingCredit/gettingCreditDownload.pdf,,
loans,Borrowing money,Do you need to borrow money?,https://www.moneyadviceservice.org.uk/en/articles/do-you-need-to-borrow-money,,
loans,Credit cards,Learn about credit cards,https://en.wikipedia.org/wiki/Credit_card,,
loans,Loans,Learn about loans,https://en.wikipedia.org/wiki/Loan,https://www.laanekalkulator.no/,
loans,Payday loans,Learn about payday loans,https://www.moneyadviceservice.org.uk/en/payday-loans,,
banking,Store credit,Store credit vs credit cards,,,https://www.thebalance.com/store-credit-cards-are-different-from-credit-cards-960146
loans,Loans,The cost of your loan,https://www.moneyadviceservice.org.uk/en/tools/loan-calculator,,
loans,Mortgages,Mortgages - beginners guide,https://www.moneyadviceservice.org.uk/en/articles/mortgages-a-beginners-guide,,
investments,Retirement,Retirement advice,https://www.saga.co.uk/magazine/money/retirement,,
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment