public function actionIndex()
 {
     $model = Config::getConfig(Module::className());
     if ($model->load(Yii::$app->request->post())) {
         //$validate = $model->validate();
         foreach (I18N::getAvailableLanguages() as $language) {
             $modelI18n = $model->getTranslation($language['locale']);
             $modelI18n->load(Yii::$app->request->post());
         }
         if ($model->save()) {
             Yii::$app->session->addFlash('success', Yii::t('maddoger/website', 'Saved.'));
             return $this->refresh();
         }
     }
     return $this->render('index', ['model' => $model]);
 }
Example #2
0
<?php

/* @var $this yii\web\View */
use maddoger\core\i18n\I18N;
use maddoger\website\backend\Module as BackendModule;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $model maddoger\website\common\models\Page */
$this->title = Yii::t('maddoger/website', 'Configuration');
$availableLanguages = I18N::getAvailableLanguages();
$activeLanguage = $availableLanguages[0]['locale'];
$layouts = BackendModule::getInstance()->getConfiguration()->layouts;
$layouts = $layouts ? array_merge(['' => Yii::t('maddoger/website', 'Default')], $layouts) : ['' => Yii::t('maddoger/website', 'Default')];
$textFormats = BackendModule::getInstance()->textFormats;
$textFormats = array_merge(['' => Yii::t('maddoger/website', 'Default')], $textFormats ? ArrayHelper::getColumn($textFormats, 'label', true) : []);
?>
<div class="page-update">

    <div class="page-form">

        <?php 
$form = ActiveForm::begin();
?>
        <div class="row">
            <div class="col-md-6">

                <div class="nav-tabs-custom" id="translations">
                    <ul class="nav nav-tabs">
                        <li class="header"><?php 
echo Yii::t('maddoger/website', 'SEO');
Example #3
0
 /**
  * @param null $language
  * @return string
  */
 public function getUrl($language = null)
 {
     if (!$language) {
         $language = $this->language;
     }
     $languages = I18N::getAvailableLanguages();
     $url = count($languages) > 1 ? $this->urlWithLanguageTemplate : $this->urlTemplate;
     $languageArray = I18N::getLanguageByLocale($language);
     $url = strtr($url, ['{slug}' => ltrim($this->slug, '/'), '{languageLocale}' => $languageArray['locale'], '{languageSlug}' => $languageArray['slug']]);
     $url = preg_replace('/([^:])\\/{2,}/', '$1/', $url);
     return Url::to($url);
 }
Example #4
0
 /**
  * Load model from backup
  * @param Page $model
  * @return bool if success
  */
 protected function loadBackup($model)
 {
     $data = Yii::$app->session->get('WEBSITE_PAGE_BACKUP_' . $model->id);
     if ($data && $model->load($data)) {
         $isDirty = count($model->getDirtyAttributes(['slug'])) > 0;
         foreach (I18N::getAvailableLanguages() as $language) {
             $modelI18n = $model->getTranslation($language['locale'], true);
             if ($modelI18n->load($data)) {
                 //Meta data
                 if ($modelI18n->meta_data && isset($modelI18n->meta_data['name']) && isset($modelI18n->meta_data['value'])) {
                     $metaData = array_filter(array_combine($modelI18n->meta_data['name'], $modelI18n->meta_data['value']));
                     if ($metaData) {
                         ksort($metaData);
                         $modelI18n->meta_data = $metaData;
                     } else {
                         $modelI18n->meta_data = null;
                     }
                 } else {
                     $modelI18n->meta_data = null;
                 }
                 $isDirty = $isDirty || count($modelI18n->getDirtyAttributes()) > 0;
             }
         }
         if ($isDirty) {
             if (isset($data['time'])) {
                 return $data['time'];
             } else {
                 return 0;
             }
         }
     }
     return false;
 }