Initial import

This commit is contained in:
Admin Nasledstvo
2026-05-01 20:52:04 +03:00
commit ac168868ee
10028 changed files with 2337954 additions and 0 deletions
@@ -0,0 +1,101 @@
<?php
use app\models\Categories;
use app\models\CommonFields;
use app\models\History;
use app\services\Auth;
use app\widgets\FormWidget;
use app\widgets\services\Includes;
use app\widgets\TableWidget;
$model = CommonFields::getModel();
$tab = $_GET['tab'] ?? 'main';
TableWidget::widget([
'top' => [
'title' => 'Общи номенклатури',
'data' => [
'index/dashboard' => 'Начало',
'nomenclature/categories' => 'Номенклатури',
]
],
'actions' => [
'new' => 'Ново поле',
'edit' => 'Редакция на поле',
'delete' => 'Изтриване на поле'
],
'th' => [
'№' => 'c0 text-right',
'Име на поле (bg)' => '',
'Множествено избиране' => 'c1 ct',
],
'data' => CommonFields::find()->where(['IS', 'parent_id', NULL])->orderBy(['id' => SORT_DESC])->loop([
'id',
function (CommonFields $model) {
return '<a href="' . Yii::$app->setQueryString(['o' => 'w', 'id' => $model->id]) . '">' . $model->name . '</a>';
},
function (CommonFields $model) {
return $model->statusSwitch('multiple_filters', null, ['Добавена е възможност за многежествено избиране при филтриране', 'Премахната е възможност за многежествено избиране при филтриране']);
},
], $_GET['p'] ?? 1, 30)
]);
FormWidget::widget([
'top' => [
'title' => 'Ново поле',
'title_edit' => 'Редакция на поле',
'data' => [
'index/dashboard' => 'Начало',
'nomenclature/categories' => 'Номенклатури',
'nomenclature/common-fields' => 'Общи номенклатури',
],
],
'tabs' => $tabs ?? [],
'writeView' => empty($_GET['id']) && empty($_GET['type']) ? "nomenclature/tabs/main/common_fields_w" : "nomenclature/tabs/" . Includes::tab($tab) . "/common_fields_w",
'model' => CommonFields::class,
'validation' => function ($p) use ($tab) {
if ($tab == 'main') {
if (empty($p->{'name'}))
return ["name" => 'Моля, въведете име на полето'];
if (empty($p->{'ts_en_name'}))
return ["ts_en_name" => 'Моля, въведете име на полето'];
if (isset($p->{'sub'})) {
foreach ($p->{'sub'} as $indexId => $value) {
if (empty($p->{'sub'}{$indexId}{'name'}))
return ["sub[$indexId][name]" => 'Моля, въведете име на полето'];
if (empty($p->{'sub'}{$indexId}{'ts_en_name'}))
return ["sub[$indexId][ts_en_name]" => 'Моля, въведете име на полето'];
}
}
}
return null;
},
'postService' => function ($p, CommonFields $model) {
$model->setPostDataToModel();
$model->save();
if (!empty($p->{'sub'})) {
$orderIndex = 0;
if ($model->id) {
$last = CommonFields::find()->where(['parent_id' => $model->id])->orderBy(['order_index' => SORT_DESC])->one();
if ($last)
$orderIndex = $last->order_index;
}
foreach ($p->{'sub'} as $id => $name) {
$catToUpdate = empty($_GET['id']) ? new CommonFields() : CommonFields::findOne($id);
if ($catToUpdate) {
$catToUpdate->name = $name['name'];
$catToUpdate->ts_en_name = $name['ts_en_name'];
$catToUpdate->parent_id = $model->id;
if (empty($catToUpdate->id))
$catToUpdate->order_index = $orderIndex;
$catToUpdate->save();
}
}
}
History::addNew($model->id, 'common-fields', Auth::userAdminGlobal()->getFullName() . ' - Глобален администратор', !empty($_GET['id']));
Yii::$app->flash('success', isset($_GET['id']) ? 'Номенклатурата е актуализирана успешно' : 'Номенклатурата е създадена успешно');
$model->smartRedirect();
}
]);