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. 20
      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' => 'Просмотр на сайте',
]; ];

20
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,6 +38,11 @@ JS;
'options' => ['enctype'=>'multipart/form-data'] 'options' => ['enctype'=>'multipart/form-data']
]); ?> ]); ?>
<div class="row">
<div class="col-md-10">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div class="box box-default"> <div class="box box-default">
@ -139,6 +145,20 @@ JS;
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?> <?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?>
</div> </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>
<?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