In view to internationalize Projeqtor (my company has planned to have several branch in others countries – especially out of Europa, and we have already clients and resources in 50 countries !), I have added a values table for countries (in a first time, only french and english) as following :
CREATE TABLE IF NOT EXISTS `country` (
`id` int(12) unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(4) DEFAULT NULL,
`lang` varchar(2) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`idle` int(1) unsigned DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `countryCodeLang` (`code`,`lang`),
KEY `countryCode` (`code`),
KEY `countryLang` (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
INSERT INTO `country` VALUES(1, 'af', 'en', 'Afghanistan', 0);
INSERT INTO `country` VALUES(2, 'af', 'fr', 'Afghanistan', 0);
INSERT INTO `country` VALUES(3, 'al', 'en', 'Albania', 0);
INSERT INTO `country` VALUES(4, 'al', 'fr', 'Albanie', 0);
INSERT INTO `country` VALUES(5, 'dz', 'en', 'Algeria', 0);
INSERT INTO `country` VALUES(6, 'dz', 'fr', 'Algérie', 0);
INSERT INTO `country` VALUES(7, 'ad', 'en', 'Andorra', 0);
INSERT INTO `country` VALUES(8, 'ad', 'fr', 'Andorre', 0);
(…)
(As I understand, the ‘idle’ column is requested for use of the table in a combo box, is this true?)
I have added a new entry in ‘menu’ table :
INSERT INTO `menu` VALUES(135, 'menuCountry', 36, 'object', 710, NULL, 0);
… so it should comes in menu under ‘parameters / Values lists‘ before ‘roles’
I have created model/Country.php:
<?php
/* ============================================================================
* Country defines list of countries.
*/
require_once('_securityCheck.php');
class Country extends SqlElement {
// extends SqlElement, so has $id
public $_col_1_2_Description;
public $id; // redefine $id to specify its visible place
public $code;
public $lang;
public $name;
// Define the layout that will be used for lists
private static $_layout='
<th field="id" formatter="numericFormatter" width="10%"># ${id}</th>
<th field="code" width="10%">${code}</th>
<th field="lang" width="10%">${lang}</th>
<th field="name" width="70%">${name}</th>
';
private static $_fieldsAttributes=array("code"=>"required",
"lang"=>"required",
"name"=>"required"
);
/** ==========================================================================
* Constructor
* @param $id the id of the object in the database (null if not stored yet)
* @return void
*/
function __construct($id = NULL) {
parent::__construct($id);
}
/** ==========================================================================
* Destructor
* @return void
*/
function __destruct() {
parent::__destruct();
}
// ============================================================================**********
// GET STATIC DATA FUNCTIONS
// ============================================================================**********
/** ==========================================================================
* Return the specific layout
* @return the layout
*/
protected function getStaticLayout() {
return self::$_layout;
}
/** ==========================================================================
* Return the specific fieldsAttributes
* @return the fieldsAttributes
*/
protected function getStaticFieldsAttributes() {
return self::$_fieldsAttributes;
}
}
?>
Of course, I also added translations in adequate ‘lang‘ files:
colCountryCode: "country code",
colCountryName: "country name",
colLang: "language",
menuCountry: "Countries",
and
colCountryCode: "code pays",
colCountryName: "libellé pays",
colLang: "language",
menuCountry: "Pays",
… but I have two problems:
1. This new table does not appears in main menu! What have I missed?
2. How redefines ‘country‘ field in model/Client.php to have a combo box:
a. filtered on ‘lang’ column with user language (as stored in ‘parameter‘ table)
b. showing ‘country’ field and storing ‘councode’ in client.country ?
c. correctly labelled.
… don’t build the link with the new table.