Browse Source

Using zertex/yii2-avatar-generator

Updated dashboard avatars
master
Egorka 7 years ago
parent
commit
adce180c57
  1. 1
      .gitignore
  2. 1
      backend/messages/ru/main.php
  3. 6
      backend/views/layouts/header.php
  4. 4
      backend/views/layouts/left.php
  5. 9
      common/config/main.php
  6. 2
      common/modules/blog/entities/BlogPost.php
  7. 8
      common/modules/blog/entities/BlogTagAssignment.php
  8. 5
      common/modules/blog/forms/BlogPostForm.php
  9. 3
      common/modules/blog/forms/BlogTagForm.php
  10. 3
      common/modules/blog/messages/ru/blog.php
  11. 212
      common/modules/blog/views/manage/post/_form.php
  12. 3
      common/modules/blog/views/manage/post/view.php
  13. 3
      composer.json

1
.gitignore vendored

@ -33,5 +33,6 @@ phpunit.phar
# vagrant runtime # vagrant runtime
/.vagrant /.vagrant
/zertex
composer.lock composer.lock
todo.txt todo.txt

1
backend/messages/ru/main.php

@ -24,4 +24,5 @@ return [
'Updating Setting' => 'Редактирование параметра', 'Updating Setting' => 'Редактирование параметра',
'Editing' => 'Редактирование', 'Editing' => 'Редактирование',
'Change at your own risk' => 'Редактируйте на свой страх и риск', 'Change at your own risk' => 'Редактируйте на свой страх и риск',
'Online' => 'В сети',
]; ];

6
backend/views/layouts/header.php

@ -5,7 +5,7 @@ use core\components\avatar_generator\AvatarGenerator;
/* @var $this \yii\web\View */ /* @var $this \yii\web\View */
/* @var $content string */ /* @var $content string */
$avatar = new AvatarGenerator(); //$avatar = new AvatarGenerator();
?> ?>
<header class="main-header"> <header class="main-header">
@ -232,13 +232,13 @@ $avatar = new AvatarGenerator();
<li class="dropdown user user-menu"> <li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="<?= $avatar->avatar(Yii::$app->user->id) ?>" class="user-image" alt="User Image"/> <img src="<?= Yii::$app->avatar->show(Yii::$app->user->identity->user->username) ?>" class="user-image" alt="User Image"/>
<span class="hidden-xs"><?= Yii::$app->user->identity->user->username ?></span> <span class="hidden-xs"><?= Yii::$app->user->identity->user->username ?></span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<!-- User image --> <!-- User image -->
<li class="user-header"> <li class="user-header">
<img src="<?= $avatar->avatar(Yii::$app->user->id) ?>" class="img-circle" <img src="<?= Yii::$app->avatar->show(Yii::$app->user->identity->user->username) ?>" class="img-circle"
alt="User Image"/> alt="User Image"/>
<p> <p>

4
backend/views/layouts/left.php

@ -5,12 +5,12 @@
<!-- Sidebar user panel --> <!-- Sidebar user panel -->
<div class="user-panel"> <div class="user-panel">
<div class="pull-left image"> <div class="pull-left image">
<img src="<?= $directoryAsset ?>/img/user2-160x160.jpg" class="img-circle" alt="User Image"/> <img src="<?= Yii::$app->avatar->show(Yii::$app->user->identity->user->username) ?>" class="img-circle" alt="<?= Yii::$app->user->identity->user->username ?>"/>
</div> </div>
<div class="pull-left info"> <div class="pull-left info">
<p><?= Yii::$app->user->identity->user->username ?></p> <p><?= Yii::$app->user->identity->user->username ?></p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a> <a href="#"><i class="fa fa-circle text-success"></i> <?= Yii::t('main', 'Online') ?></a>
</div> </div>
</div> </div>

9
common/config/main.php

@ -24,5 +24,14 @@ return [
//'path' => '@runtime/queue', //'path' => '@runtime/queue',
'path' => '@common/runtime/queue', 'path' => '@common/runtime/queue',
], ],
'avatar' => [
'class' => \zertex\avatar_generator\AvatarGenerator::class,
'images_folder' => '@staticRoot/images/avatars',
'images_url' => '@static/images/avatars',
'size_width' => 300, // default: 300
'font_size' => 200, // default: 200
'salt' => 'my_cms_salt', // salt for image file names
'texture' => ['sun', 'rain'], // texture name
],
], ],
]; ];

2
common/modules/blog/entities/BlogPost.php

@ -283,7 +283,7 @@ class BlogPost extends ActiveRecord
public function getTags(): ActiveQuery public function getTags(): ActiveQuery
{ {
return $this->hasMany(BlogTag::className(), ['id' => 'tag_id'])->viaTable('post_tag_assignments', ['post_id' => 'id']); return $this->hasMany(BlogTag::className(), ['id' => 'tag_id'])->viaTable('blog_tag_assignments', ['post_id' => 'id']);
} }
public function getCategory(): ActiveQuery public function getCategory(): ActiveQuery

8
common/modules/blog/entities/BlogTagAssignment.php

@ -3,10 +3,13 @@
namespace common\modules\blog\entities; namespace common\modules\blog\entities;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use yii\db\ActiveQuery;
/** /**
* @property integer $post_id; * @property integer $post_id;
* @property integer $tag_id; * @property integer $tag_id;
*
* @property BlogTag $tag
*/ */
class BlogTagAssignment extends ActiveRecord class BlogTagAssignment extends ActiveRecord
{ {
@ -26,4 +29,9 @@ class BlogTagAssignment extends ActiveRecord
{ {
return '{{%blog_tag_assignments}}'; return '{{%blog_tag_assignments}}';
} }
public function getTag(): ActiveQuery
{
return $this->hasOne(BlogTag::className(), ['id' => 'tag_id']);
}
} }

5
common/modules/blog/forms/BlogPostForm.php

@ -26,6 +26,7 @@ class BlogPostForm extends CompositeForm
public $published_at; public $published_at;
public $slug; public $slug;
public $reset_image; public $reset_image;
public $status;
public $_post; public $_post;
@ -41,10 +42,12 @@ class BlogPostForm extends CompositeForm
$this->slug = $post->slug; $this->slug = $post->slug;
$this->meta = new MetaForm($post->meta); $this->meta = new MetaForm($post->meta);
$this->tags = new BlogTagForm($post); $this->tags = new BlogTagForm($post);
$this->status = $post->status;
$this->_post = $post; $this->_post = $post;
} else { } else {
$this->meta = new MetaForm(); $this->meta = new MetaForm();
$this->tags = new BlogTagForm(); $this->tags = new BlogTagForm();
$this->status = 0;
} }
parent::__construct($config); parent::__construct($config);
} }
@ -54,7 +57,7 @@ class BlogPostForm extends CompositeForm
return [ return [
[['category_id', 'title'], 'required'], [['category_id', 'title'], 'required'],
[['title', 'video'], 'string', 'max' => 255], [['title', 'video'], 'string', 'max' => 255],
[['category_id'], 'integer'], [['category_id', 'status'], 'integer'],
[['description', 'content'], 'string'], [['description', 'content'], 'string'],
[['image'], 'image'], [['image'], 'image'],
['reset_image', 'boolean'], ['reset_image', 'boolean'],

3
common/modules/blog/forms/BlogTagForm.php

@ -4,6 +4,7 @@ namespace common\modules\blog\forms;
use common\modules\blog\entities\BlogPost; use common\modules\blog\entities\BlogPost;
use common\modules\blog\entities\BlogTag; use common\modules\blog\entities\BlogTag;
use common\modules\blog\entities\BlogTagAssignment;
use yii\base\Model; use yii\base\Model;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -19,7 +20,7 @@ class BlogTagForm extends Model
public function __construct(BlogPost $post = null, $config = []) public function __construct(BlogPost $post = null, $config = [])
{ {
if ($post) { if ($post) {
$this->existing = ArrayHelper::getColumn($post->blogTagAssignments, 'tag_id'); $this->new_tags = ArrayHelper::map($post->blogTagAssignments, 'tag_id', 'tag.name');
} }
parent::__construct($config); parent::__construct($config);
} }

3
common/modules/blog/messages/ru/blog.php

@ -58,4 +58,7 @@ return [
'Video' => 'Видео', 'Video' => 'Видео',
'If a video link is specified, the image will be used as a preview image' => 'Если указана ссылка на видео, то изображение будет рассматриваться как картинка для предварительного просмотра', 'If a video link is specified, the image will be used as a preview image' => 'Если указана ссылка на видео, то изображение будет рассматриваться как картинка для предварительного просмотра',
'Reset Image' => 'Сбросить изображение', 'Reset Image' => 'Сбросить изображение',
'Set tags...' => 'Укажите теги...',
'Publish' => 'Публикация',
'Preview on site' => 'Просмотр на сайте',
]; ];

212
common/modules/blog/views/manage/post/_form.php

@ -10,6 +10,7 @@ use yii\helpers\Json;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use kartik\widgets\DateTimePicker; use kartik\widgets\DateTimePicker;
use kartik\widgets\Select2; use kartik\widgets\Select2;
use common\modules\blog\helpers\BlogPostHelper;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model \common\modules\blog\forms\BlogPostForm */ /* @var $model \common\modules\blog\forms\BlogPostForm */
@ -37,108 +38,127 @@ JS;
'options' => ['enctype'=>'multipart/form-data'] 'options' => ['enctype'=>'multipart/form-data']
]); ?> ]); ?>
<div class="row">
<div class="col-md-6"> <div class="row">
<div class="box box-default"> <div class="col-md-10">
<div class="box-header with-border"><?= Yii::t('blog', 'Common') ?></div>
<div class="box-body">
<?= $form->field($model, 'category_id')->dropDownList($model->categoriesList(), ['prompt' => '']) ?> <div class="row">
<?= $form->field($model, 'published_at')->widget(DateTimePicker::classname(), [ <div class="col-md-6">
'options' => [], <div class="box box-default">
'pluginOptions' => [ <div class="box-header with-border"><?= Yii::t('blog', 'Common') ?></div>
'autoclose' => true, <div class="box-body">
'format' => 'dd.mm.yyyy hh:ii:ss', <?= $form->field($model, 'category_id')->dropDownList($model->categoriesList(), ['prompt' => '']) ?>
] <?= $form->field($model, 'published_at')->widget(DateTimePicker::classname(), [
]); ?> 'options' => [],
</div> 'pluginOptions' => [
</div> 'autoclose' => true,
</div> 'format' => 'dd.mm.yyyy hh:ii:ss',
<div class="col-md-6"> ]
<div class="box box-default"> ]); ?>
<div class="box-header with-border"><?= Yii::t('blog', 'Tags') ?></div> </div>
<div class="box-body"> </div>
<?= $form->field($model->tags, 'new_tags')->widget(Select2::classname(), [ </div>
'options' => [ <div class="col-md-6">
'placeholder' => Yii::t('blog','Set tags...'), <div class="box box-default">
'multiple' => true, <div class="box-header with-border"><?= Yii::t('blog', 'Tags') ?></div>
], <div class="box-body">
'pluginOptions' => [ <?= $form->field($model->tags, 'new_tags')->widget(Select2::classname(), [
'tags' => true, 'options' => [
'tokenSeparators' => [',', ' '], 'placeholder' => Yii::t('blog','Set tags...'),
'maximumInputLength' => 12, 'multiple' => true,
'ajax' => [ ],
'url' => $fetchUrl, 'pluginOptions' => [
'dataType' => 'json', 'tags' => true,
'data' => new JsExpression('function(params) { return {q:params.term}; }') 'tokenSeparators' => [',', ' '],
], 'maximumInputLength' => 12,
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'ajax' => [
'templateResult' => new JsExpression('function(tag) { return tag.text; }'), 'url' => $fetchUrl,
'templateSelection' => new JsExpression('function (tag) { return tag.text; }'), 'dataType' => 'json',
], 'data' => new JsExpression('function(params) { return {q:params.term}; }')
])->label(false); ?> ],
</div> 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
</div> 'templateResult' => new JsExpression('function(tag) { return tag.text; }'),
</div> 'templateSelection' => new JsExpression('function (tag) { return tag.text; }'),
</div> ],
])->label(false); ?>
<div class="box box-default"> </div>
<div class="box-body"> </div>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> </div>
<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?> </div>
<?= $form->field($model, 'description')->textarea(['rows' => 5]) ?>
<?= $form->field($model, 'content')->widget(CKEditor::className()) ?> <div class="box box-default">
</div> <div class="box-body">
</div> <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
<div class="box box-default"> <?= $form->field($model, 'description')->textarea(['rows' => 5]) ?>
<div class="box-body"> <?= $form->field($model, 'content')->widget(CKEditor::className()) ?>
</div>
<ul class="nav nav-tabs"> </div>
<li class="active"><a data-toggle="tab" href="#field_image"><?= Yii::t('blog', 'Image') ?></a></li>
<li><a data-toggle="tab" href="#field_video"><?= Yii::t('blog', 'Video') ?></a></li> <div class="box box-default">
</ul> <div class="box-body">
<div class="tab-content"> <ul class="nav nav-tabs">
<div id="field_image" class="tab-pane fade in active" style="padding-top: 20px;"> <li class="active"><a data-toggle="tab" href="#field_image"><?= Yii::t('blog', 'Image') ?></a></li>
<?= $form->field($model, 'image')->label(false)->widget(FileInput::class, [ <li><a data-toggle="tab" href="#field_video"><?= Yii::t('blog', 'Video') ?></a></li>
'options' => [ </ul>
'accept' => 'image/*',
], <div class="tab-content">
'pluginOptions' => [ <div id="field_image" class="tab-pane fade in active" style="padding-top: 20px;">
'showUpload' => false, <?= $form->field($model, 'image')->label(false)->widget(FileInput::class, [
], 'options' => [
]) ?> 'accept' => 'image/*',
],
<?php if (isset($model->_post) && $model->_post->image): ?> 'pluginOptions' => [
<?= Html::img($model->_post->getThumbFileUrl('image', 'thumb_gallery_view'), [ 'showUpload' => false,
'class' => 'thumbnail', ],
'width' => 300, ]) ?>
]) ?>
<?php if (isset($model->_post) && $model->_post->image): ?>
<?= $form->field($model, 'reset_image')->checkbox() ?> <?= Html::img($model->_post->getThumbFileUrl('image', 'thumb_gallery_view'), [
<?php endif; ?> 'class' => 'thumbnail',
</div> 'width' => 300,
<div id="field_video" class="tab-pane fade" style="padding-top: 20px;"> ]) ?>
<?= $form->field($model, 'video')->textInput()->label(Yii::t('blog', 'YouTube URL'))->hint(Yii::t('blog', 'If a video link is specified, the image will be used as a preview image')) ?>
<?= $form->field($model, 'reset_image')->checkbox() ?>
<?php endif; ?>
</div>
<div id="field_video" class="tab-pane fade" style="padding-top: 20px;">
<?= $form->field($model, 'video')->textInput()->label(Yii::t('blog', 'YouTube URL'))->hint(Yii::t('blog', 'If a video link is specified, the image will be used as a preview image')) ?>
</div>
</div>
</div> </div>
</div> </div>
<div class="box box-default">
<div class="box-header with-border"><?= Yii::t('blog', 'SEO') ?></div>
<div class="box-body">
<?= $form->field($model->meta, 'title')->textInput() ?>
<?= $form->field($model->meta, 'description')->textarea(['rows' => 2]) ?>
<?= $form->field($model->meta, 'keywords')->textInput() ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?>
</div>
</div>
<div class="col-md-2">
<div class="box box-default">
<div class="box-header with-border"><?= Yii::t('blog', 'Publish') ?></div>
<div class="box-body">
<?= Html::button(Yii::t('blog', 'Preview on site')) ?>
<hr>
<?= $form->field($model, 'status')->radioList(BlogPostHelper::statusList()) ?>
</div>
</div>
</div> </div>
</div> </div>
<div class="box box-default">
<div class="box-header with-border"><?= Yii::t('blog', 'SEO') ?></div>
<div class="box-body">
<?= $form->field($model->meta, 'title')->textInput() ?>
<?= $form->field($model->meta, 'description')->textarea(['rows' => 2]) ?>
<?= $form->field($model->meta, 'keywords')->textInput() ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>

3
common/modules/blog/views/manage/post/view.php

@ -52,7 +52,8 @@ $this->params['breadcrumbs'][] = $title;
], ],
[ [
'label' => Yii::t('post', 'Tags'), 'label' => Yii::t('post', 'Tags'),
'value' => implode(', ', ArrayHelper::getColumn($post->tags, 'name')), 'format' => 'raw',
'value' => '<i class="fa fa-tag" aria-hidden="true"></i> ' . implode(' <i class="fa fa-tag" aria-hidden="true"></i> ', ArrayHelper::getColumn($post->tags, 'name')),
], ],
], ],
]) ?> ]) ?>

3
composer.json

@ -35,7 +35,8 @@
"bower-asset/jquery-migrate": "^3.0", "bower-asset/jquery-migrate": "^3.0",
"bower-asset/jquery-cookie": "^1.4", "bower-asset/jquery-cookie": "^1.4",
"drewm/mailchimp-api": "^2.4", "drewm/mailchimp-api": "^2.4",
"yiisoft/yii2-imagine": "^2.1" "yiisoft/yii2-imagine": "^2.1",
"zertex/yii2-avatar-generator": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

Loading…
Cancel
Save