Merge branch 'blog-hashtag-filtr' into 'master'

транслиты для тнгов



See merge request !46
parents e105c6bd 404cc6da
......@@ -25,4 +25,19 @@ $('.checkbox_btn').on('change', function(e) {
});
}
});
})
\ No newline at end of file
})
$('#posttag-name').on("keyup", function(){
var $this = $(this);
var action = $this.attr('action');
$.ajax({
type: "get",
url: action,
data: {str: $this.val()},
success: function(msg){
$('#posttag-translit').val(msg);
}
});
});
\ No newline at end of file
......@@ -27,7 +27,8 @@ class PostAdminController extends AdminController
'Update' => 'Редактирование записи',
'Delete' => 'Удаление записи',
'View' => 'Просмотр записи',
'Autocomplete' => 'Автокомплит для поля тегов'
'Autocomplete' => 'Автокомплит для поля тегов',
'Translit' => 'Транслитерация',
];
}
......@@ -46,6 +47,11 @@ class PostAdminController extends AdminController
];
}
public function actionTranslit($str)
{
return PostTag::translit($str);
}
/**
* Lists all Post models.
* @return mixed
......
......@@ -14,6 +14,7 @@ use common\modules\blog\models\Post;
use common\modules\blog\models\PostTag;
use common\modules\blog\models\PostTagAssign;
/**
* PostController implements the CRUD actions for Post model.
*/
......@@ -42,7 +43,9 @@ class PostController extends BaseController
if(isset(Yii::$app->request->get()["tags"]))
{
$tag = Yii::$app->request->get()["tags"];
$explode = explode(Yii::$app->request->get()["tags"]);
$session = Yii::$app->session;
$session->set('blog_hashtag', null);
......
......@@ -95,7 +95,8 @@ class TagAdminController extends AdminController
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
// return $this->redirect(['view', 'id' => $model->id]);
return $this->redirect(['manage']);
} else {
return $this->render('update', [
'model' => $model,
......
......@@ -9,6 +9,7 @@ use yii\helpers\Url;
use common\modules\blog\models\Post;
use common\modules\blog\models\PostTagAssign;
use common\modules\languages\models\Languages;
use dosamigos\transliterator\TransliteratorHelper;
/**
* This is the model class for table "posts_tags".
......@@ -45,7 +46,7 @@ class PostTag extends \common\components\ActiveRecordModel
[['name'], 'required'],
[['lang_id'], 'safe'],
[['created_at', 'updated_at', 'lang_id'], 'integer'],
[['name'], 'string', 'max' => 255],
[['name', 'translit'], 'string', 'max' => 255],
];
}
......@@ -132,4 +133,10 @@ class PostTag extends \common\components\ActiveRecordModel
// use CustomerQuery instead of the default ActiveQuery
return new PostTagQuery(get_called_class());
}
public static function translit($string, $unknown = '?', $language = 'en')
{
$s = preg_replace("/\s\s+/", " ", TransliteratorHelper::process($string, $unknown, $language));
return str_replace(" ", "-", $s);
}
}
......@@ -5,7 +5,9 @@ use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use common\modules\languages\models\Languages;
use common\modules\blog\assets\GeneratorAsset;
GeneratorAsset::register($this);
/* @var $this yii\web\View */
/* @var $model common\modules\blog\models\PostTag */
/* @var $form yii\widgets\ActiveForm */
......@@ -15,7 +17,9 @@ use common\modules\languages\models\Languages;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true, 'action' => '/blog/post-admin/translit']) ?>
<?= $form->field($model, 'translit')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'lang_id')->dropDownList(ArrayHelper::map(Languages::find()->all(), 'id', 'name')) ?>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment