From 15b17dfeedfdab3707908a4a2f76e3ff7af0c15a Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 6 Nov 2015 12:59:53 +0200 Subject: [PATCH] Added view presenters --- app/Models/Account.php | 4 + app/Ninja/Mailers/ContactMailer.php | 6 +- app/Ninja/Presenters/AccountPresenter.php | 12 +++ app/Ninja/Transformers/AccountTransformer.php | 2 +- .../Transformers/UserAccountTransformer.php | 2 +- composer.json | 3 +- composer.lock | 83 +++++++++++++++---- database/seeds/UserTableSeeder.php | 2 +- resources/lang/en/texts.php | 1 + resources/views/emails/view_action.blade.php | 6 +- 10 files changed, 94 insertions(+), 27 deletions(-) create mode 100644 app/Ninja/Presenters/AccountPresenter.php diff --git a/app/Models/Account.php b/app/Models/Account.php index 2784e40ff1..506f00a6e2 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -8,10 +8,14 @@ use Event; use App; use App\Events\UserSettingsChanged; use Illuminate\Database\Eloquent\SoftDeletes; +use Laracasts\Presenter\PresentableTrait; class Account extends Eloquent { + use PresentableTrait; use SoftDeletes; + + protected $presenter = 'App\Ninja\Presenters\AccountPresenter'; protected $dates = ['deleted_at']; protected $hidden = ['ip']; diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index cce2b5fc16..9858ee66cc 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -91,6 +91,7 @@ class ContactMailer extends Mailer 'entityType' => $invoice->getEntityType(), 'invoiceId' => $invoice->id, 'invitation' => $invitation, + 'account' => $account, ]; if ($account->attatchPDF()) { @@ -137,11 +138,12 @@ class ContactMailer extends Mailer 'account' => $account, 'client' => $client, 'invitation' => $invitation, - 'amount' => $payment->amount + 'amount' => $payment->amount, ]; $data = [ - 'body' => $this->processVariables($emailTemplate, $variables) + 'body' => $this->processVariables($emailTemplate, $variables), + 'account' => $account, ]; if ($account->attatchPDF()) { diff --git a/app/Ninja/Presenters/AccountPresenter.php b/app/Ninja/Presenters/AccountPresenter.php new file mode 100644 index 0000000000..a53f9f20c1 --- /dev/null +++ b/app/Ninja/Presenters/AccountPresenter.php @@ -0,0 +1,12 @@ +entity->name ?: trans('texts.untitled_account'); + } + +} \ No newline at end of file diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index b81e8847bd..e10938ebe2 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -26,7 +26,7 @@ class AccountTransformer extends TransformerAbstract { return [ 'account_key' => $account->account_key, - 'name' => $account->name, + 'name' => $account->present()->name, ]; } } \ No newline at end of file diff --git a/app/Ninja/Transformers/UserAccountTransformer.php b/app/Ninja/Transformers/UserAccountTransformer.php index fee2c14816..2b3724a2f6 100644 --- a/app/Ninja/Transformers/UserAccountTransformer.php +++ b/app/Ninja/Transformers/UserAccountTransformer.php @@ -27,7 +27,7 @@ class UserAccountTransformer extends TransformerAbstract { return [ 'account_key' => $user->account->account_key, - 'name' => $user->account->name, + 'name' => $user->account->present()->name, 'token' => $user->account->getToken($this->tokenName), ]; } diff --git a/composer.json b/composer.json index 7ce195f974..20c80fd000 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ "meebio/omnipay-secure-trading": "dev-master", "justinbusschau/omnipay-secpay": "~2.0", "labs7in0/omnipay-wechat": "dev-master", - "collizo4sky/omnipay-wepay": "~1.0" + "collizo4sky/omnipay-wepay": "~1.0", + "laracasts/presenter": "dev-master" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/composer.lock b/composer.lock index 2ec1b88aa5..dc3c86d86f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "9b0cd6db7a2a2e16ffb1711043005f2b", + "hash": "4c2d5d48a648e380f3acf2943b91e6bc", "packages": [ { "name": "agmscode/omnipay-agms", @@ -176,12 +176,12 @@ "source": { "type": "git", "url": "https://github.com/formers/former.git", - "reference": "9e75217536bf6c377318e5a6f68d4c1f96a8ae3b" + "reference": "795f7b9b200a4ff4a33b37a96eaaab0229e36325" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/formers/former/zipball/9e75217536bf6c377318e5a6f68d4c1f96a8ae3b", - "reference": "9e75217536bf6c377318e5a6f68d4c1f96a8ae3b", + "url": "https://api.github.com/repos/formers/former/zipball/795f7b9b200a4ff4a33b37a96eaaab0229e36325", + "reference": "795f7b9b200a4ff4a33b37a96eaaab0229e36325", "shasum": "" }, "require": { @@ -227,7 +227,7 @@ "foundation", "laravel" ], - "time": "2015-09-24 15:56:30" + "time": "2015-11-05 15:53:52" }, { "name": "anahkiasen/html-object", @@ -2221,12 +2221,12 @@ "source": { "type": "git", "url": "https://github.com/Intervention/image.git", - "reference": "33f848674c96b82b050fde2806ba4e55ee88078f" + "reference": "2d8de6577b86c8b3bf49b6578d659ba9ee21fcc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Intervention/image/zipball/33f848674c96b82b050fde2806ba4e55ee88078f", - "reference": "33f848674c96b82b050fde2806ba4e55ee88078f", + "url": "https://api.github.com/repos/Intervention/image/zipball/2d8de6577b86c8b3bf49b6578d659ba9ee21fcc1", + "reference": "2d8de6577b86c8b3bf49b6578d659ba9ee21fcc1", "shasum": "" }, "require": { @@ -2275,7 +2275,7 @@ "thumbnail", "watermark" ], - "time": "2015-11-04 14:06:13" + "time": "2015-11-05 18:30:26" }, { "name": "ircmaxell/password-compat", @@ -2608,6 +2608,52 @@ ], "time": "2015-10-27 05:12:08" }, + { + "name": "laracasts/presenter", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/laracasts/Presenter.git", + "reference": "b284f3137f990efd6e95df49d254f1ccc4541e92" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laracasts/Presenter/zipball/b284f3137f990efd6e95df49d254f1ccc4541e92", + "reference": "b284f3137f990efd6e95df49d254f1ccc4541e92", + "shasum": "" + }, + "require": { + "illuminate/support": "~5.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpspec/phpspec": "~2.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Laracasts\\Presenter": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeffrey Way", + "email": "jeffrey@laracasts.com" + } + ], + "description": "Simple view presenters", + "keywords": [ + "laravel", + "presenter", + "view" + ], + "time": "2014-09-13 13:18:07" + }, { "name": "laravel/framework", "version": "v5.0.33", @@ -3501,16 +3547,16 @@ }, { "name": "nesbot/carbon", - "version": "1.20.0", + "version": "1.21.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "bfd3eaba109c9a2405c92174c8e17f20c2b9caf3" + "reference": "7b08ec6f75791e130012f206e3f7b0e76e18e3d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bfd3eaba109c9a2405c92174c8e17f20c2b9caf3", - "reference": "bfd3eaba109c9a2405c92174c8e17f20c2b9caf3", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7b08ec6f75791e130012f206e3f7b0e76e18e3d7", + "reference": "7b08ec6f75791e130012f206e3f7b0e76e18e3d7", "shasum": "" }, "require": { @@ -3518,12 +3564,12 @@ "symfony/translation": "~2.6|~3.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.0|~5.0" }, "type": "library", "autoload": { - "psr-0": { - "Carbon": "src" + "psr-4": { + "Carbon\\": "src/Carbon/" } }, "notification-url": "https://packagist.org/downloads/", @@ -3544,7 +3590,7 @@ "datetime", "time" ], - "time": "2015-06-25 04:19:39" + "time": "2015-11-04 20:07:17" }, { "name": "nikic/php-parser", @@ -8330,7 +8376,8 @@ "descubraomundo/omnipay-pagarme": 20, "dercoder/omnipay-paysafecard": 20, "meebio/omnipay-secure-trading": 20, - "labs7in0/omnipay-wechat": 20 + "labs7in0/omnipay-wechat": 20, + "laracasts/presenter": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/database/seeds/UserTableSeeder.php b/database/seeds/UserTableSeeder.php index 2d6c32796d..2f27b94793 100644 --- a/database/seeds/UserTableSeeder.php +++ b/database/seeds/UserTableSeeder.php @@ -14,7 +14,7 @@ class UserTableSeeder extends Seeder Eloquent::unguard(); $account = Account::create([ - 'name' => 'Test Account', + //'name' => 'Test Account', 'account_key' => str_random(RANDOM_KEY_LENGTH), 'timezone_id' => 1, ]); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 154b23025b..2a0ffc3986 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -907,5 +907,6 @@ return array( 'restore_recurring_invoice' => 'Restore Recurring Invoice', 'restored_recurring_invoice' => 'Successfully restored recurring invoice', 'archived' => 'Archived', + 'untitled_account' => 'Untitled Company', ); diff --git a/resources/views/emails/view_action.blade.php b/resources/views/emails/view_action.blade.php index 718af5a596..987aa527a0 100644 --- a/resources/views/emails/view_action.blade.php +++ b/resources/views/emails/view_action.blade.php @@ -5,13 +5,13 @@ "description":"View your {{ $entityType }}", "action": { "@type": "ViewAction", - "url": "{{{ $link }}}", + "url": "{!! $link !!}", "name": "View {{ $entityType }}" - }, + }, "publisher": { "@type": "Organization", "name": "Invoice Ninja", - "url": "{{{ NINJA_WEB_URL }}}" + "url": "{!! NINJA_WEB_URL !!}" } } \ No newline at end of file