org -> unit change, some new functionality

This commit is contained in:
Dennis Eichhorn 2023-01-26 21:54:13 +01:00
parent 67424ec6cf
commit 8b153555af
4 changed files with 33 additions and 66 deletions

View File

@ -1,54 +1,4 @@
{
"organization_unit": {
"name": "organization_unit",
"fields": {
"organization_unit_id": {
"name": "organization_unit_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"organization_unit_name": {
"name": "organization_unit_name",
"type": "VARCHAR(50)",
"default": null,
"null": true
},
"organization_unit_image": {
"name": "organization_unit_image",
"type": "INT",
"default": null,
"null": true
},
"organization_unit_description": {
"name": "organization_unit_description",
"type": "TEXT",
"default": null,
"null": true
},
"organization_unit_descriptionraw": {
"name": "organization_unit_descriptionraw",
"type": "TEXT",
"default": null,
"null": true
},
"organization_unit_parent": {
"name": "organization_unit_parent",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "organization_unit",
"foreignKey": "organization_unit_id"
},
"organization_unit_status": {
"name": "organization_unit_status",
"type": "TINYINT",
"default": null,
"null": true
}
}
},
"organization_department": {
"name": "organization_department",
"fields": {
@ -95,8 +45,8 @@
"name": "organization_department_unit",
"type": "INT",
"null": false,
"foreignTable": "organization_unit",
"foreignKey": "organization_unit_id"
"foreignTable": "unit",
"foreignKey": "unit_id"
}
}
},

View File

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace Modules\Organization\Controller;
use Model\Setting;
use Model\SettingMapper;
use Modules\Admin\Models\SettingsEnum as ModelsSettingsEnum;
use Modules\Media\Models\PathSettings;
use Modules\Organization\Models\Department;
use Modules\Organization\Models\DepartmentMapper;
@ -28,6 +31,7 @@ use Modules\Organization\Models\Unit;
use Modules\Organization\Models\UnitMapper;
use phpOMS\Account\GroupStatus;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
@ -187,11 +191,24 @@ final class ApiController extends Controller
/** @var \Model\Setting $setting */
$setting = $this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_UNIT);
if ($setting->content === '1') {
$internalResponse = new HttpResponse();
$newRequest = new HttpRequest();
$newRequest->header->account = $request->header->account;
$newRequest->setData('name', 'org:unit:' . \strtolower($unit->name));
$newRequest->setData('name', 'unit:' . \strtolower($unit->name));
$newRequest->setData('status', GroupStatus::ACTIVE);
$this->app->moduleManager->get('Admin')->apiGroupCreate($newRequest, $response, $data);
$this->app->moduleManager->get('Admin')->apiGroupCreate($newRequest, $internalResponse, $data);
$group = $internalResponse->get($newRequest->uri->__toString())['response'];
$setting = new Setting(
0,
ModelsSettingsEnum::UNIT_DEFAULT_GROUPS,
\json_encode([$group->getId()]),
unit: $unit->getId(),
module: 'Admin'
);
$this->createModel($request->header->account, $setting, SettingMapper::class, 'setting', $request->getOrigin());
}
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Unit', 'Unit successfully created.', $unit);

View File

@ -34,13 +34,13 @@ final class UnitMapper extends DataMapperFactory
* @since 1.0.0
*/
public const COLUMNS = [
'organization_unit_id' => ['name' => 'organization_unit_id', 'type' => 'int', 'internal' => 'id'],
'organization_unit_name' => ['name' => 'organization_unit_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'organization_unit_image' => ['name' => 'organization_unit_image', 'type' => 'int', 'internal' => 'image'],
'organization_unit_description' => ['name' => 'organization_unit_description', 'type' => 'string', 'internal' => 'description'],
'organization_unit_descriptionraw' => ['name' => 'organization_unit_descriptionraw', 'type' => 'string', 'internal' => 'descriptionRaw'],
'organization_unit_parent' => ['name' => 'organization_unit_parent', 'type' => 'int', 'internal' => 'parent'],
'organization_unit_status' => ['name' => 'organization_unit_status', 'type' => 'int', 'internal' => 'status'],
'unit_id' => ['name' => 'unit_id', 'type' => 'int', 'internal' => 'id'],
'unit_name' => ['name' => 'unit_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'unit_image' => ['name' => 'unit_image', 'type' => 'int', 'internal' => 'image'],
'unit_description' => ['name' => 'unit_description', 'type' => 'string', 'internal' => 'description'],
'unit_descriptionraw' => ['name' => 'unit_descriptionraw', 'type' => 'string', 'internal' => 'descriptionRaw'],
'unit_parent' => ['name' => 'unit_parent', 'type' => 'int', 'internal' => 'parent'],
'unit_status' => ['name' => 'unit_status', 'type' => 'int', 'internal' => 'status'],
];
/**
@ -52,7 +52,7 @@ final class UnitMapper extends DataMapperFactory
public const OWNS_ONE = [
'image' => [
'mapper' => MediaMapper::class,
'external' => 'organization_unit_image',
'external' => 'unit_image',
],
];
@ -65,7 +65,7 @@ final class UnitMapper extends DataMapperFactory
public const BELONGS_TO = [
'parent' => [
'mapper' => self::class,
'external' => 'organization_unit_parent',
'external' => 'unit_parent',
],
];
@ -83,7 +83,7 @@ final class UnitMapper extends DataMapperFactory
* @var string
* @since 1.0.0
*/
public const TABLE = 'organization_unit';
public const TABLE = 'unit';
/**
* Primary field name.
@ -91,5 +91,5 @@ final class UnitMapper extends DataMapperFactory
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='organization_unit_id';
public const PRIMARYFIELD ='unit_id';
}

View File

@ -53,7 +53,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
};
$this->app->dbPool = $GLOBALS['dbpool'];
$this->app->orgId = 1;
$this->app->unitId = 1;
$this->app->accountManager = new AccountManager($GLOBALS['session']);
$this->app->appSettings = new CoreSettings();
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules/');