/** * Special function for locale stored attributes under serialization. * @param string $attribute * @return array|null|string */ public function getLocaled($attribute) { // if always decoded if (Obj::isArray($this->{$attribute})) { return $this->{$attribute}[App::$Request->getLanguage()]; } if (!Obj::isString($attribute) || Str::likeEmpty($this->{$attribute})) { return null; } return Serialize::getDecodeLocale($this->{$attribute}); }
/** * Get locale data from input array or serialized string * @param array|string $input * @param string|null $lang * @param string|null $default * @return string|null */ public function getLocaleText($input, $lang = null, $default = null) { // define language if empty if ($lang === null) { $lang = App::$Request->getLanguage(); } // unserialize from string to array if (Obj::isString($input)) { $input = Serialize::decode($input); } if (Obj::isArray($input) && array_key_exists($lang, $input)) { return $input[$lang]; } return $default; }
/** * Install function callback */ public static function install() { // prepare application information to extend inserted before row to table apps $appData = new \stdClass(); $appData->configs = ['textCfg' => 'Some value', 'intCfg' => 10, 'boolCfg' => true]; $appData->name = ['ru' => 'Демо приложение', 'en' => 'Demo app']; // get current app row from db (like SELECT ... WHERE type='app' and sys_name='Demoapp') $query = AppRecord::where('type', '=', 'app')->where('sys_name', '=', 'Demoapp'); if ($query->count() !== 1) { return; } $query->update(['name' => Serialize::encode($appData->name), 'configs' => Serialize::encode($appData->configs), 'disabled' => 0]); // create your own table in database App::$Database->schema()->create('demos', function ($table) { $table->increments('id'); $table->string('text', 1024); $table->timestamps(); }); $now = Date::convertToDatetime(time(), Date::FORMAT_SQL_DATE); // insert some data in table, id|text columns, id is autoincrement App::$Database->connection()->table('demos')->insert([['text' => 'Hello world 1', 'created_at' => $now, 'updated_at' => $now], ['text' => 'Hello world 2', 'created_at' => $now, 'updated_at' => $now]]); }