From 7b0e87d28ccd155304c45b79b5aac137e4c230e1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 30 Jul 2012 15:10:58 +1000 Subject: [PATCH] Language ID rework --- application/classes/config.php | 2 +- .../lnapp/controller/templatedefault.php | 2 +- application/classes/model/account.php | 6 +----- application/classes/model/language.php | 16 ++++++++++++++++ application/classes/model/setup.php | 1 + application/classes/ormosb.php | 19 +++++++++++++++++++ application/views/account/user/edit.php | 2 +- modules/email/classes/email/template.php | 3 ++- .../classes/model/product/category.php | 7 ++++++- .../product/views/product/admin/update.php | 2 +- .../product/views/product/category/view.php | 2 +- modules/product/views/product/view.php | 2 +- 12 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 application/classes/model/language.php diff --git a/application/classes/config.php b/application/classes/config.php index 0ed1fe2e..a306333b 100644 --- a/application/classes/config.php +++ b/application/classes/config.php @@ -13,7 +13,7 @@ class Config extends lnApp_Config { // Our setup object public $so; - public static $no_site_id_tables = array('setup','country','currency','tax'); + public static $no_site_id_tables = array('setup','country','currency','language','tax'); /** * Load our site configuration from the DB diff --git a/application/classes/lnapp/controller/templatedefault.php b/application/classes/lnapp/controller/templatedefault.php index 1c6f419d..c4a9afa8 100644 --- a/application/classes/lnapp/controller/templatedefault.php +++ b/application/classes/lnapp/controller/templatedefault.php @@ -162,7 +162,7 @@ abstract class lnApp_Controller_TemplateDefault extends Controller_Template { $this->template->title = ''; // Language - $this->meta->language = Config::instance()->so->language_id; + $this->meta->language = Config::instance()->so->language->iso; // Description $this->meta->description = sprintf('%s::%s',$this->request->controller(),$this->request->action()); diff --git a/application/classes/model/account.php b/application/classes/model/account.php index be59abe0..3ebea21b 100644 --- a/application/classes/model/account.php +++ b/application/classes/model/account.php @@ -20,6 +20,7 @@ class Model_Account extends Model_Auth_UserDefault { ); protected $_has_one = array( 'affiliate' => array('far_key'=>'id'), + 'language'=>array('foreign_key'=>'id','far_key'=>'language_id'), ); protected $_display_filters = array( @@ -60,11 +61,6 @@ class Model_Account extends Model_Auth_UserDefault { return StaticList_Module::form($name,'country',$this->country_id,'id','name',array('active'=>'=:1'),FALSE,array('class'=>'form_button')); } - public function language($name) { - // @todo To setup - return 'en'; - } - /** * Get the groups that an account belongs to */ diff --git a/application/classes/model/language.php b/application/classes/model/language.php new file mode 100644 index 00000000..ae88714f --- /dev/null +++ b/application/classes/model/language.php @@ -0,0 +1,16 @@ +'id','value'=>'name'); +} +?> diff --git a/application/classes/model/setup.php b/application/classes/model/setup.php index 9f4830dd..a20cc812 100644 --- a/application/classes/model/setup.php +++ b/application/classes/model/setup.php @@ -19,6 +19,7 @@ class Model_Setup extends ORMOSB { protected $_has_one = array( 'country'=>array('foreign_key'=>'id','far_key'=>'country_id'), + 'language'=>array('foreign_key'=>'id','far_key'=>'language_id'), ); public function rules() { diff --git a/application/classes/ormosb.php b/application/classes/ormosb.php index 223ba7eb..d9adf721 100644 --- a/application/classes/ormosb.php +++ b/application/classes/ormosb.php @@ -22,6 +22,9 @@ abstract class ORMOSB extends ORM { // Our attribute values that need to be stored as serialized protected $_serialize_column = array(); + // Our attributes used in forms. + protected $_form = array(); + public function rules() { return array( 'id'=>array( @@ -60,6 +63,10 @@ abstract class ORMOSB extends ORM { } } + final public static function form($table,$blank=FALSE) { + return ORM::factory($table)->formselect($blank); + } + /** * Get Next record id * @@ -146,6 +153,18 @@ abstract class ORMOSB extends ORM { return parent::__get($column); } + public function formselect($blank) { + $result = array(); + + if ($blank) + $result[] = ''; + + foreach ($this->find_all() as $o) + $result[$o->{$this->_form['id']}] = $o->{$this->_form['value']}; + + return $result; + } + public function keyget($column,$key=NULL) { if (is_null($key) OR ! is_array($this->$column)) return $this->$column; diff --git a/application/views/account/user/edit.php b/application/views/account/user/edit.php index 16a09632..e24c6f9b 100644 --- a/application/views/account/user/edit.php +++ b/application/views/account/user/edit.php @@ -65,7 +65,7 @@ Language - language('language_id'); ?> + language->display('name'); ?> Currency diff --git a/modules/email/classes/email/template.php b/modules/email/classes/email/template.php index 42c293d2..760c76a6 100644 --- a/modules/email/classes/email/template.php +++ b/modules/email/classes/email/template.php @@ -15,7 +15,8 @@ class Email_Template { private $template; private $etto; private $email_data = array(); - private $default_lang = 'en'; + // @todo Default lang should be the site setup + private $default_lang = 1; private $components = array('subject','message_text','message_html'); public function __construct($template,$language_id=NULL) { diff --git a/modules/product/classes/model/product/category.php b/modules/product/classes/model/product/category.php index 02d35fdf..27ba2f5c 100644 --- a/modules/product/classes/model/product/category.php +++ b/modules/product/classes/model/product/category.php @@ -22,7 +22,12 @@ class Model_Product_Category extends ORMOSB { ); public function description() { - return ($a=$this->product_category_translate->where('language_id','=','en')->find()->description) ? $a : 'No Description'; + // If the user is not logged in, show the site default language + // @todo This needs to change to the session language. + if (! $ao=Auth::instance()->get_user()) + $ao=Config::instance()->so; + + return ($a=$this->product_category_translate->where('language_id','=',$ao->language_id)->find()->description) ? $a : _('No Description'); } public function list_active() { diff --git a/modules/product/views/product/admin/update.php b/modules/product/views/product/admin/update.php index 09a0a5c4..02dcae60 100644 --- a/modules/product/views/product/admin/update.php +++ b/modules/product/views/product/admin/update.php @@ -48,7 +48,7 @@ Product Descriptions - 'EN')); ?> +   diff --git a/modules/product/views/product/category/view.php b/modules/product/views/product/category/view.php index e5fa767e..46c5d9ef 100644 --- a/modules/product/views/product/category/view.php +++ b/modules/product/views/product/category/view.php @@ -11,7 +11,7 @@ // If there isnt a translated page, show the default language // @todo - default language should come from configuration if (! $translate->loaded()) - $translate = $record->product_translate->where('product_id','=',$record->id)->and_where('language_id','=','en')->find(); + $translate = $record->product_translate->where('product_id','=',$record->id)->and_where('language_id','=',1)->find(); ?> diff --git a/modules/product/views/product/view.php b/modules/product/views/product/view.php index 4b72f560..d5dafb31 100644 --- a/modules/product/views/product/view.php +++ b/modules/product/views/product/view.php @@ -10,7 +10,7 @@ $translate = $record->product_translate->where('product_id','=',$record->id)->an // If there isnt a translated page, show the default language // @todo - default language should come from configuration if (! $translate->loaded()) - $translate = $record->product_translate->where('product_id','=',$record->id)->and_where('language_id','=','en')->find(); + $translate = $record->product_translate->where('product_id','=',$record->id)->and_where('language_id','=',1)->find(); // @todo Need to add in product attributes // @todo Need to add in product plugins