$searchModel = new WikiArticleSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+ if (!WikiArticleSearch::hasCategories()) {
+ Yii::$app->session->setFlash('warning', 'Категории не найдены. Добавьте хотя бы одну категорию.');
+ }
$categories = WikiCategory::find()->all();
$tree = $this->buildTree($categories);
if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
- // Получаем slug категории и slug статьи
- $categorySlug = $model->category->slug; // Slug категории из связанной модели
- $articleSlug = $model->slug; // Slug созданной статьи
-
- // Перенаправляем на страницу просмотра с правильными параметрами
+ $categorySlug = $model->category->slug;
+ $articleSlug = $model->slug;
return $this->redirect(['view', 'parent_cat_slug' => $categorySlug, 'article_slug' => $articleSlug]);
}
} else {
$model = $this->findModel($id);
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
+ $categorySlug = $model->category->slug;
+ $articleSlug = $model->slug;
+ return $this->redirect(['view', 'parent_cat_slug' => $categorySlug, 'article_slug' => $articleSlug]);
}
return $this->render('update', [
{
return $this->hasOne(WikiCategory::class, ['id' => 'category_id']);
}
+
+ public static function hasCategories(): bool
+ {
+ return WikiCategory::find()->exists();
+ }
+
+ public function getCreatorName()
+ {
+ return $this->hasOne(Admin::class, ['id' => 'created_by'])->select('name')->scalar();
+ }
}
*/
public function search($params)
{
+ if (!self::hasCategories()) {
+ return new ActiveDataProvider([
+ 'query' => WikiArticle::find()->where('0=1'), // Возвращает пустой результат
+ ]);
+ }
$query = WikiArticle::find();
// add conditions that should always apply here
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="wiki-category-index p-4">
-
+ <?= Html::a('К статьям', ['/wiki/index'], ['class' => 'btn btn-secondary mb-4']) ?>
<h1><?= Html::encode($this->title) ?></h1>
<p>
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
+use yii_app\helpers\PrintBlockHelper;
use yii_app\records\WikiCategory;
/** @var yii\web\View $this */
/** @var yii_app\records\WikiArticle $model */
/** @var yii\widgets\ActiveForm $form */
-
+$this->registerJsFile('/js/wiki/_form.js', ['position' => \yii\web\View::POS_END]);
function getCategoriesWithHierarchy($categories, $parentId = null, $level = 0)
{
$result = [];
['prompt' => 'Выберите родительскую категорию']
) ?>
- <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
+ <?= $form->field($model, 'description')->textarea(['rows' => 3]) ?>
- <?= $form->field($model, 'content')->widget(CKEditor::class, [
- 'options' => ['rows' => 6],
- 'uploadUrl' => '/files/upload'
- ]) ?>
+ <?= $form->field($model, 'content')->hiddenInput()->label('Содержание') ?>
+ <div id="summernote"><?= $model->content ?></div>
<div class="form-group">
/** @var yii_app\records\WikiArticleSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
/** @var array $tree */
+\yii\web\YiiAsset::register($this);
+$this->registerCssFile('/css/wiki/customWiki.css');
+$this->registerJsFile('/js/wiki/view.js', ['position' => \yii\web\View::POS_END]);
$this->title = 'Документация';
$this->params['breadcrumbs'][] = $this->title;
$user = Yii::$app->user->identity;
?>
<div class="wiki-category-index p-4">
- <h1><?= Html::encode($this->title) ?></h1>
- <?php if ($user->group_id == 81) : ?>
- <p>
- <?= Html::a('Создать категорию', ['wiki-category/create'], ['class' => 'btn btn-success']) ?>
- <?= Html::a('Создать статью', ['create'], ['class' => 'btn btn-success']) ?>
- </p>
- <?php endif; ?>
+ <div class="row mb-4">
+ <div class="col-8"><h1><?= Html::encode($this->title) ?></h1></div>
+ <div class="col-3">
+ <?php if ($user->group_id == 81) : ?>
+ <p>
+ <?= Html::a('Создать категорию', ['wiki-category/create'], ['class' => 'btn btn-success']) ?>
+ <?= Html::a('Создать статью', ['create'], ['class' => 'btn btn-success']) ?>
+ <?= Html::a('Категории', ['wiki-category/index'], ['class' => 'btn btn-primary']) ?>
+ </p>
+ <?php endif; ?>
+ </div>
+ </div>
+
+
<!-- Вывод дерева -->
<div class="row">
<div class="col-3 tree-container">
<?= $this->render('tree', ['tree' => $tree]) ?>
</div>
- <div class="col-9">
- <?= GridView::widget([
- 'dataProvider' => $dataProvider,
- 'filterModel' => $searchModel,
- 'columns' => [
- 'title',
- [
- 'attribute' => 'category_id',
- 'value' => function ($model) {
- return $model->category ? $model->category->title : '';
- },
- 'label' => 'Категория',
- ],
- ['class' => 'yii\grid\ActionColumn'],
- ],
- ]) ?>
+ <div class="col-9 d-flex align-items-center flex-column">
+ <h2 class="mb-1 ">Справочник ERP</h2>
+ <h3 class="mb-2 text-muted">для сотрудников</h3>
+ <p class="lead">В меню слева выберите статью по интересующей вас теме</p>
+ <img class="my-3" src="/web/uploads/screen.jpg" alt="">
+ <?php if ($user->group_id == 81) : ?>
+ <p class="lead">Для добавления статей сначала добавьте категорию</p>
+ <p>
+ <?= Html::a('Создать категорию', ['wiki-category/create'], ['class' => 'btn btn-success']) ?>
+ <?= Html::a('Создать статью', ['create'], ['class' => 'btn btn-success']) ?>
+ </p>
+ <?php endif; ?>
</div>
</div>
-
-
- <style>
- .tree-container {
- font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
- line-height: 1.6;
- }
- .tree-level-0 {
- margin-left: 0;
- }
- .tree-level-1 {
- margin-left: 20px;
- }
- .tree-level-2 {
- margin-left: 40px;
- }
- /* Категории */
- .category-title {
- font-weight: bold;
- cursor: pointer;
- padding: 8px 12px;
- background-color: #f4f4f4;
- border-radius: 4px;
- transition: background-color 0.3s ease;
- }
- .category-title:hover {
- background-color: #e0e0e0;
- }
-
- /* Стрелочка */
- .category-title.toggleable svg {
- margin-left: 8px;
- transition: transform 0.3s ease;
- transform: rotate(0deg);
- }
- .category-title.toggleable.open svg {
- transform: rotate(90deg);
- }
-
- /* Скрытые подкатегории и статьи */
- .subcategories.hidden {
- display: none;
- }
- .subcategories.visible {
- display: block;
- }
-
- /* Статьи */
- .articles-list {
- list-style-type: none;
- padding-left: 20px;
- }
- .article-link {
- display: block;
- padding: 6px 12px;
- text-decoration: none;
- color: #337ab7;
- border-radius: 4px;
- transition: background-color 0.3s ease, color 0.3s ease;
- }
- .article-link:hover {
- background-color: #e0e0e0;
- color: #23527c;
- }
- .article-description {
- color: #666;
- font-size: 0.9em;
- margin-top: 4px;
- }
- </style>
- <script>
- function copyToClipboard(text) {
- navigator.clipboard.writeText(text).then(function() {
- alert('Ссылка скопирована: ' + text);
- }, function(err) {
- console.error('Ошибка копирования: ', err);
- });
- }
- document.addEventListener('DOMContentLoaded', function () {
- const categoryTitles = document.querySelectorAll('.category-title.toggleable');
- categoryTitles.forEach(title => {
- title.addEventListener('click', function () {
- const parentLi = this.closest('li');
- const subcategories = parentLi.querySelector('.subcategories');
-
- if (subcategories) {
- subcategories.classList.toggle('visible');
- subcategories.classList.toggle('hidden');
- this.classList.toggle('open');
- }
- });
- });
- });
- </script>
-
/** @var array $tree */
/** @var int $level */
-
+$this->registerJsFile('/js/wiki/tree.js', ['position' => \yii\web\View::POS_END]);
if (!isset($level)) {
$level = 0;
}
<div
class="category-title open <?= $hasContent ? 'toggleable' : '' ?>"
data-has-content="<?= $hasContent ? 'true' : 'false' ?>"
+ title="<?= $category->description ?>"
+ data-toggle="tooltip"
+ data-placement="top"
>
<?= Html::encode($category->title) ?>
<?php if ($hasContent): ?>
<?php if (!empty($category->description)): ?>
- <div class="category-description"><?= Html::encode($category->description) ?></div>
+<!-- <div class="category-description">--><?php //= Html::encode($category->description) ?><!--</div>-->
<?php endif; ?>
<?php if ($hasContent): ?>
'view',
'parent_cat_slug' => $category->slug,
'article_slug' => $article->slug
- ], true), ['class' => 'article-link']) ?>
+ ], true), [
+ 'class' => 'article-link',
+ 'title' => Html::encode($article->description),
+ 'data-toggle' => 'tooltip',
+ 'data-placement' => 'top'
+ ]) ?>
</li>
<?php endforeach; ?>
</ul>
/** @var yii_app\records\WikiArticle $model */
/** @var array $tree */
+$this->registerCssFile('/css/wiki/customWiki.css');
+$this->registerJsFile('/js/wiki/view.js', ['position' => \yii\web\View::POS_END]);
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Wiki Articles', 'url' => ['index']];
</div>
<div class="text-muted mb-3">
- <strong>Автор:</strong> <?= Html::encode($model->created_by) ?> |
+ <strong>Автор:</strong> <?= Html::encode($model->creatorName) ?> |
<strong>Дата создания:</strong> <?= date('d.m.Y H:i', strtotime($model->created_at)) ?>
</div>
- <div class="article-content border p-3 rounded bg-light">
+ <div class="article-content border p-3 rounded bg-white">
<?= nl2br($model->content) ?>
</div>
<?php if ($user->group_id == 81) : ?>
</div>
-
-<style>
- .tree-container {
- font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
- line-height: 1.6;
- }
- .tree-level-0 {
- margin-left: 0;
- }
- .tree-level-1 {
- margin-left: 20px;
- }
- .tree-level-2 {
- margin-left: 40px;
- }
- /* Категории */
- .category-title {
- font-weight: bold;
- cursor: pointer;
- padding: 8px 12px;
- background-color: #f4f4f4;
- border-radius: 4px;
- transition: background-color 0.3s ease;
- }
- .category-title:hover {
- background-color: #e0e0e0;
- }
-
- /* Стрелочка */
- .category-title.toggleable svg {
- margin-left: 8px;
- transition: transform 0.3s ease;
- transform: rotate(0deg);
- }
- .category-title.toggleable.open svg {
- transform: rotate(90deg);
- }
-
- /* Скрытые подкатегории и статьи */
- .subcategories.hidden {
- display: none;
- }
- .subcategories.visible {
- display: block;
- }
-
- /* Статьи */
- .articles-list {
- list-style-type: none;
- padding-left: 20px;
- }
- .article-link {
- display: block;
- padding: 6px 12px;
- text-decoration: none;
- color: #337ab7;
- border-radius: 4px;
- transition: background-color 0.3s ease, color 0.3s ease;
- }
- .article-link:hover {
- background-color: #e0e0e0;
- color: #23527c;
- }
- .article-description {
- color: #666;
- font-size: 0.9em;
- margin-top: 4px;
- }
-</style>
-<script>
- function copyToClipboard(text) {
- navigator.clipboard.writeText(text).then(function() {
- alert('Ссылка скопирована: ' + text);
- }, function(err) {
- console.error('Ошибка копирования: ', err);
- });
- }
- document.addEventListener('DOMContentLoaded', function () {
- const categoryTitles = document.querySelectorAll('.category-title.toggleable');
- categoryTitles.forEach(title => {
- title.addEventListener('click', function () {
- const parentLi = this.closest('li');
- const subcategories = parentLi.querySelector('.subcategories');
-
- if (subcategories) {
- subcategories.classList.toggle('visible');
- subcategories.classList.toggle('hidden');
- this.classList.toggle('open');
- }
- });
- });
- });
-</script>
--- /dev/null
+.tree-container {
+ font-family: Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
+ line-height: 1.6;
+}
+.tree-level-0 {
+ margin-left: 0;
+}
+.tree-level-1 {
+ margin-left: 20px;
+}
+.tree-level-2 {
+ margin-left: 40px;
+}
+/* Категории */
+.category-title {
+ font-weight: bold;
+ cursor: pointer;
+ padding: 8px 12px;
+ background-color: #f4f4f4;
+ border-radius: 4px;
+ transition: background-color 0.3s ease;
+}
+.category-title:hover {
+ background-color: #e0e0e0;
+}
+
+/* Стрелочка */
+.category-title.toggleable svg {
+ margin-left: 8px;
+ transition: transform 0.3s ease;
+ transform: rotate(0deg);
+}
+.category-title.toggleable.open svg {
+ transform: rotate(90deg);
+}
+
+/* Скрытые подкатегории и статьи */
+.subcategories.hidden {
+ display: none;
+}
+.subcategories.visible {
+ display: block;
+}
+
+/* Статьи */
+.articles-list {
+ list-style-type: none;
+ padding-left: 20px;
+}
+.article-link {
+ display: block;
+ padding: 6px 12px;
+ text-decoration: none;
+ color: #337ab7;
+ border-radius: 4px;
+ transition: background-color 0.3s ease, color 0.3s ease;
+}
+.article-link:hover {
+ background-color: #e0e0e0;
+ color: #23527c;
+}
+.article-description {
+ color: #666;
+ font-size: 0.9em;
+ margin-top: 4px;
+}
\ No newline at end of file
--- /dev/null
+$(document).ready(() => {
+ $('#summernote').summernote({maxHeight: 400});
+ setInterval(() => {
+ $('#wikiarticle-content').val($('#summernote').summernote('code'));
+ }, 1000);
+})
\ No newline at end of file
--- /dev/null
+$(function () {
+ $('[data-toggle="tooltip"]').tooltip();
+});
\ No newline at end of file
--- /dev/null
+function copyToClipboard(text) {
+ navigator.clipboard.writeText(text).then(function() {
+ alert('Ссылка скопирована: ' + text);
+ }, function(err) {
+ console.error('Ошибка копирования: ', err);
+ });
+}
+document.addEventListener('DOMContentLoaded', function () {
+ const categoryTitles = document.querySelectorAll('.category-title.toggleable');
+ categoryTitles.forEach(title => {
+ title.addEventListener('click', function () {
+ const parentLi = this.closest('li');
+ const subcategories = parentLi.querySelector('.subcategories');
+
+ if (subcategories) {
+ subcategories.classList.toggle('visible');
+ subcategories.classList.toggle('hidden');
+ this.classList.toggle('open');
+ }
+ });
+ });
+});
\ No newline at end of file