From cf24684adbce402f1c0e266672c4a2a5767dc754 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 11 Jan 2016 14:50:17 +0200 Subject: [PATCH] Check user is pro to use custom fonts --- app/Models/Account.php | 29 ++++++++++--------- .../views/accounts/invoice_design.blade.php | 9 ++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index 3cca054f42e1..cee8bc7295ee 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -908,15 +908,8 @@ class Account extends Eloquent } public function getFontsUrl($protocol = ''){ - if ($this->isPro()){ - $bodyFont = $this->body_font_id; - $headerFont = $this->header_font_id; - } - else{ - $bodyFont = DEFAULT_BODY_FONT; - $headerFont = DEFAULT_HEADER_FONT; - } - + $bodyFont = $this->getHeaderFontId(); + $headerFont = $this->getBodyFontId(); $bodyFontSettings = Utils::getFromCache($bodyFont, 'fonts'); $google_fonts = array($bodyFontSettings['google_font']); @@ -929,16 +922,24 @@ class Account extends Eloquent return ($protocol?$protocol.':':'').'//fonts.googleapis.com/css?family='.implode('|',$google_fonts); } + public function getHeaderFontId() { + return $this->isPro() ? $this->header_font_id : DEFAULT_HEADER_FONT; + } + + public function getBodyFontId() { + return $this->isPro() ? $this->body_font_id : DEFAULT_BODY_FONT; + } + public function getHeaderFontName(){ - return Utils::getFromCache($this->header_font_id, 'fonts')['name']; + return Utils::getFromCache($this->getHeaderFontId(), 'fonts')['name']; } public function getBodyFontName(){ - return Utils::getFromCache($this->body_font_id, 'fonts')['name']; + return Utils::getFromCache($this->getBodyFontId(), 'fonts')['name']; } public function getHeaderFontCss($include_weight = true){ - $font_data = Utils::getFromCache($this->header_font_id, 'fonts'); + $font_data = Utils::getFromCache($this->getHeaderFontId(), 'fonts'); $css = 'font-family:'.$font_data['css_stack'].';'; if($include_weight){ @@ -949,7 +950,7 @@ class Account extends Eloquent } public function getBodyFontCss($include_weight = true){ - $font_data = Utils::getFromCache($this->body_font_id, 'fonts'); + $font_data = Utils::getFromCache($this->getBodyFontId(), 'fonts'); $css = 'font-family:'.$font_data['css_stack'].';'; if($include_weight){ @@ -960,7 +961,7 @@ class Account extends Eloquent } public function getFonts(){ - return array_unique(array($this->header_font_id, $this->body_font_id)); + return array_unique(array($this->getHeaderFontId(), $this->getBodyFontId())); } public function getFontsData(){ diff --git a/resources/views/accounts/invoice_design.blade.php b/resources/views/accounts/invoice_design.blade.php index 98dac26a6f5d..99d599d3ab3c 100644 --- a/resources/views/accounts/invoice_design.blade.php +++ b/resources/views/accounts/invoice_design.blade.php @@ -52,9 +52,12 @@ NINJA.primaryColor = $('#primary_color').val(); NINJA.secondaryColor = $('#secondary_color').val(); NINJA.fontSize = parseInt($('#font_size').val()); - NINJA.headerFont = $('#header_font_id option:selected').text(); - NINJA.bodyFont = $('#body_font_id option:selected').text(); - + @if (Auth::user()->isPro()) + NINJA.headerFont = $('#header_font_id option:selected').text(); + NINJA.bodyFont = $('#body_font_id option:selected').text(); + @else + NINJA.headerFont = NINJA.bodyFont = 'Roboto'; + @endif var fields = ['item', 'description', 'unit_cost', 'quantity', 'line_total', 'terms']; invoiceLabels.old = {}; for (var i=0; i