This commit is contained in:
Dennis Eichhorn 2020-02-15 02:00:12 +01:00
parent 36e7c7b592
commit 967a34dfeb
3 changed files with 41 additions and 17 deletions

View File

@ -14,10 +14,14 @@ declare(strict_types=1);
namespace Modules\Organization\Admin;
use Model\CoreSettings;
use Modules\Organization\Controller\ApiController;
use Modules\Organization\Models\SettingsEnum;
use Modules\Organization\Models\Unit;
use Modules\Organization\Models\UnitMapper;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\InfoManager;
use phpOMS\Module\InstallerAbstract;
@ -38,9 +42,39 @@ class Installer extends InstallerAbstract
{
parent::install($dbPool, $info);
self::installDefaultUnit();
self::installSettings($dbPool);
}
/**
* Install default unit
*
* @return void
*
* @since 1.0.0
*/
private static function installDefaultUnit() : void
{
$unit = new Unit();
$unit->setName('Orange Management');
UnitMapper::create($unit);
}
/**
* Install settings
*
* @param DatabasePool $dbPool Database pool
*
* @return void
*
* @since 1.0.0
*/
private static function installSettings(DatabasePool $dbPool) : void
{
$settings = new CoreSettings($dbPool->get('insert'));
$settings->create(['name' => SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_UNIT, 'content' => '1', 'module' => ApiController::MODULE_NAME]);
$settings->create(['name' => SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_DEPARTMENT, 'content' => '1', 'module' => ApiController::MODULE_NAME]);
$settings->create(['name' => SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_POSITION, 'content' => '1', 'module' => ApiController::MODULE_NAME]);
}
}

View File

@ -38,16 +38,6 @@ use phpOMS\Utils\Parser\Markdown\Markdown;
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*
* @todo Orange-Management/Modules#135
* Automatic group generation *optional*
* Whenever a new
* * Unit
* * Department
* * Position
* is created a new group is created and all of the possibilities (this should be a optional setting for the module).
* Group name strucutre: org:position-department-unit or org:unit-department-position
* This should be solvable through hooks.
*/
final class ApiController extends Controller
{
@ -186,7 +176,7 @@ final class ApiController extends Controller
$unit = $this->createUnitFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $unit, UnitMapper::class, 'unit');
if ($this->app->appSettings->get(SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_UNIT) === '1') {
if ($this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_UNIT) === '1') {
$newRequest = new HttpRequest();
$newRequest->setData('name', 'org:unit:' . \strtolower($unit->getName()));
$newRequest->setData('status', GroupStatus::ACTIVE);
@ -357,7 +347,7 @@ final class ApiController extends Controller
$position = $this->createPositionFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $position, PositionMapper::class, 'position');
if ($this->app->appSettings->get(SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_POSITION) === '1') {
if ($this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_POSITION) === '1') {
$newRequest = new HttpRequest();
$newRequest->setData('name', 'org:pos:' . \strtolower($position->getName()));
$newRequest->setData('status', GroupStatus::ACTIVE);
@ -530,7 +520,7 @@ final class ApiController extends Controller
$department = $this->createDepartmentFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $department, DepartmentMapper::class, 'department');
if ($this->app->appSettings->get(SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_DEPARTMENT) === '1') {
if ($this->app->appSettings->get(null, SettingsEnum::GROUP_GENERATE_AUTOMATICALLY_DEPARTMENT) === '1') {
$newRequest = new HttpRequest();
$newRequest->setData('name', 'org:dep:' . \strtolower($department->getName()));
$newRequest->setData('status', GroupStatus::ACTIVE);

View File

@ -26,7 +26,7 @@ use phpOMS\Stdlib\Base\Enum;
*/
abstract class SettingsEnum extends Enum
{
public const GROUP_GENERATE_AUTOMATICALLY_UNIT = 1004700001;
public const GROUP_GENERATE_AUTOMATICALLY_DEPARTMENT = 1004700002;
public const GROUP_GENERATE_AUTOMATICALLY_POSITION = 1004700003;
public const GROUP_GENERATE_AUTOMATICALLY_UNIT = '1004700001';
public const GROUP_GENERATE_AUTOMATICALLY_DEPARTMENT = '1004700002';
public const GROUP_GENERATE_AUTOMATICALLY_POSITION = '1004700003';
}