This commit is contained in:
Dennis Eichhorn 2020-06-09 22:01:09 +02:00
parent ce41923e23
commit 24d96270dd
75 changed files with 200 additions and 4 deletions

0
.github/dev_bug_report.md vendored Normal file → Executable file
View File

0
.github/dev_feature_request.md vendored Normal file → Executable file
View File

0
.github/user_bug_report.md vendored Normal file → Executable file
View File

0
.github/user_feature_request.md vendored Normal file → Executable file
View File

0
.github/workflows/greetings.yml vendored Normal file → Executable file
View File

0
.github/workflows/image.yml vendored Normal file → Executable file
View File

0
.github/workflows/main.yml vendored Normal file → Executable file
View File

View File

@ -0,0 +1,7 @@
[
{
"name": "Organization",
"virtualPath": "/Modules",
"user": 1
}
]

43
Admin/Install/Media.php Executable file
View File

@ -0,0 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\Organization\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Organization\Admin\Install;
use phpOMS\DataStorage\Database\DatabasePool;
/**
* Media class.
*
* @package Modules\Organization\Admin\Install
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class Media
{
/**
* Install media providing
*
* @param string $path Module path
* @param DatabasePool $dbPool Database pool for database interaction
*
* @return void
*
* @since 1.0.0
*/
public static function install(string $path, DatabasePool $dbPool) : void
{
\Modules\Media\Admin\Installer::installExternal($dbPool, ['path' => __DIR__ . '/Media.install.json']);
}
}

0
Admin/Install/Navigation.install.json Normal file → Executable file
View File

0
Admin/Install/Navigation.php Normal file → Executable file
View File

0
Admin/Install/Settings.install.php Normal file → Executable file
View File

8
Admin/Install/db.json Normal file → Executable file
View File

@ -15,6 +15,14 @@
"default": null,
"null": true
},
"organization_unit_image": {
"name": "organization_unit_image",
"type": "INT",
"default": null,
"null": true,
"foreignTable": "media",
"foreignKey": "media_id"
},
"organization_unit_description": {
"name": "organization_unit_description",
"type": "TEXT",

0
Admin/Installer.php Normal file → Executable file
View File

14
Admin/Routes/Web/Api.php Normal file → Executable file
View File

@ -82,7 +82,7 @@ return [
],
],
],
'^.*/organization/unit.*$' => [
'^.*/organization/unit(\?.*|$)' => [
[
'dest' => '\Modules\Organization\Controller\ApiController:apiUnitCreate',
'verb' => RouteVerb::PUT,
@ -121,6 +121,18 @@ return [
],
],
'^.*/organization/unit/image(\?.*|$)' => [
[
'dest' => '\Modules\Organization\Controller\ApiController:apiUnitImageSet',
'verb' => RouteVerb::SET,
'permission' => [
'module' => ApiController::MODULE_NAME,
'type' => PermissionType::MODIFY,
'state' => PermissionState::UNIT,
],
],
],
'^.*/organization/find/unit.*$' => [
[
'dest' => '\Modules\Organization\Controller\ApiController:apiUnitFind',

0
Admin/Routes/Web/Backend.php Normal file → Executable file
View File

0
Admin/Status.php Normal file → Executable file
View File

0
Admin/Uninstaller.php Normal file → Executable file
View File

0
Admin/Updater.php Normal file → Executable file
View File

0
CODE_OF_CONDUCT.md Normal file → Executable file
View File

0
CONTRIBUTING.md Normal file → Executable file
View File

39
Controller/ApiController.php Normal file → Executable file
View File

@ -220,6 +220,45 @@ final class ApiController extends Controller
return $unit;
}
/**
* Routing end-point for application behaviour.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitImageSet(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$uploadedFiles = $request->getFiles() ?? [];
if (empty($uploadedFiles)) {
return;
}
/** @var Unit $unit */
$unit = UnitMapper::get((int) ($request->getData('id') ?? 0));
$old = clone $unit;
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
$request->getData('name') ?? '',
$uploadedFiles,
$request->getHeader()->getAccount(),
__DIR__ . '/../../../Modules/Media/Files',
'/Modules/Organization'
);
$unit->setImage(\reset($uploaded));
$this->updateModel($request->getHeader()->getAccount(), $old, $unit, UnitMapper::class, 'unit', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Unit', 'Unit successfully updated', $unit);
}
/**
* Validate position create request
*

0
Controller/BackendController.php Normal file → Executable file
View File

0
Controller/Controller.php Normal file → Executable file
View File

0
LICENSE.txt Normal file → Executable file
View File

0
Models/Department.php Normal file → Executable file
View File

0
Models/DepartmentMapper.php Normal file → Executable file
View File

0
Models/NullDepartment.php Normal file → Executable file
View File

0
Models/NullPosition.php Normal file → Executable file
View File

1
Models/NullUnit.php Normal file → Executable file
View File

@ -34,5 +34,6 @@ final class NullUnit extends Unit
public function __construct(int $id = 0)
{
$this->id = $id;
parent::__construct();
}
}

0
Models/PermissionState.php Normal file → Executable file
View File

0
Models/Position.php Normal file → Executable file
View File

0
Models/PositionMapper.php Normal file → Executable file
View File

0
Models/SettingsEnum.php Normal file → Executable file
View File

0
Models/Status.php Normal file → Executable file
View File

46
Models/Unit.php Normal file → Executable file
View File

@ -15,6 +15,8 @@ declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\Contract\ArrayableInterface;
use Modules\Media\Models\Media;
use Modules\Media\Models\NullMedia;
/**
* Organization unit class.
@ -42,6 +44,14 @@ class Unit implements ArrayableInterface, \JsonSerializable
*/
private string $name = '';
/**
* Unit image.
*
* @var Media
* @since 1.0.0
*/
protected Media $image;
/**
* Parent
*
@ -74,6 +84,16 @@ class Unit implements ArrayableInterface, \JsonSerializable
*/
protected int $status = Status::INACTIVE;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->image = new NullMedia();
}
/**
* Get id
*
@ -112,6 +132,32 @@ class Unit implements ArrayableInterface, \JsonSerializable
$this->name = $name;
}
/**
* Get unit image.
*
* @return Media
*
* @since 1.0.0
*/
public function getImage() : Media
{
return $this->image ?? new NullMedia();
}
/**
* Set unit image.
*
* @param Media $image Profile image
*
* @return void
*
* @since 1.0.0
*/
public function setImage(Media $image) : void
{
$this->image = $image;
}
/**
* Get parent
*

15
Models/UnitMapper.php Normal file → Executable file
View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use Modules\Media\Models\MediaMapper;
/**
* Organization unit mapper class.
@ -35,12 +36,26 @@ final class UnitMapper extends DataMapperAbstract
protected static array $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' => 'string', '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'],
];
/**
* Has one relation.
*
* @var array<string, array{mapper:string, self:string, by?:string, column?:string}>
* @since 1.0.0
*/
protected static array $ownsOne = [
'image' => [
'mapper' => MediaMapper::class,
'self' => 'organization_unit_image',
],
];
/**
* Belongs to.
*

0
README.md Normal file → Executable file
View File

View File

View File

View File

View File

View File

0
Theme/Backend/Lang/Navigation.en.lang.php Normal file → Executable file
View File

1
Theme/Backend/Lang/en.lang.php Normal file → Executable file
View File

@ -18,6 +18,7 @@ return ['Organization' => [
'Departments' => 'Departments',
'Description' => 'Description',
'Inactive' => 'Inactive',
'Logo' => 'Logo',
'Name' => 'Name',
'Parent' => 'Parent',
'Position' => 'Position',

0
Theme/Backend/css/styles.css Normal file → Executable file
View File

0
Theme/Backend/css/styles.scss Normal file → Executable file
View File

0
Theme/Backend/department-create.tpl.php Normal file → Executable file
View File

0
Theme/Backend/department-list.tpl.php Normal file → Executable file
View File

0
Theme/Backend/department-profile.tpl.php Normal file → Executable file
View File

0
Theme/Backend/organigram.tpl.php Normal file → Executable file
View File

0
Theme/Backend/position-create.tpl.php Normal file → Executable file
View File

0
Theme/Backend/position-list.tpl.php Normal file → Executable file
View File

0
Theme/Backend/position-profile.tpl.php Normal file → Executable file
View File

0
Theme/Backend/unit-create.tpl.php Normal file → Executable file
View File

5
Theme/Backend/unit-list.tpl.php Normal file → Executable file
View File

@ -13,6 +13,7 @@
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
use Modules\Media\Models\NullMedia;
/**
* @var \phpOMS\Views\View $this
@ -33,6 +34,7 @@ echo $this->getData('nav')->render(); ?>
<thead>
<tr>
<td><?= $this->getHtml('ID', '0', '0'); ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td><?= $this->getHtml('Logo') ?>
<td class="wf-100"><?= $this->getHtml('Name') ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<td><?= $this->getHtml('Parent') ?><i class="sort-asc fa fa-chevron-up"></i><i class="sort-desc fa fa-chevron-down"></i>
<tbody>
@ -40,6 +42,9 @@ echo $this->getData('nav')->render(); ?>
$url = \phpOMS\Uri\UriFactory::build('{/prefix}organization/unit/profile?{?}&id=' . $value->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getId()); ?></a>
<td><a href="<?= $url; ?>"><img class="profile-image" src="<?= $value->getImage() instanceof NullMedia ?
UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') :
UriFactory::build('{/prefix}' . $value->getImage()->getPath()); ?>"></a>
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getName()); ?></a>
<td data-label="<?= $this->getHtml('Parent') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getParent()->getName()); ?></a>
<?php endforeach; ?>

19
Theme/Backend/unit-profile.tpl.php Normal file → Executable file
View File

@ -13,6 +13,7 @@
declare(strict_types=1);
use phpOMS\Uri\UriFactory;
use Modules\Media\Models\NullMedia;
/**
* @var \phpOMS\Views\View $this
@ -22,11 +23,27 @@ $unit = $this->getData('unit');
echo $this->getData('nav')->render(); ?>
<form id="iUnitUploadForm" action="<?= UriFactory::build('{/api}organization/unit/image?id={?id}'); ?>" method="post"><input data-action='[{"listener": "change", "key": 1, "action": [{"key": 1, "type": "form.submit", "selector": "#iUnitUploadForm"}]}]' id="iUnitUpload" name="unitImage" type="file" accept="image/png,image/gif,image/jpeg" style="display: none;"></form>
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="portlet">
<form id="iUnit" action="<?= UriFactory::build('{/api}organization/unit') ?>" method="post">
<div class="portlet-head"><?= $this->getHtml('Unit') ?></div>
<div class="portlet-head row middle-xs">
<div class="col-xs-0">
<a id="iUnitUploadButton" href="#upload" data-action='[{"listener": "click", "key": 1, "action": [{"key": 1, "type": "event.prevent"}, {"key": 2, "type": "dom.click", "selector": "#iUnitUpload"}]}]'>
<img class="profile-image"
alt="<?= $this->getHtml('Logo'); ?>"
itemprop="logo"
data-lazyload="<?=
$unit->getImage() instanceof NullMedia ?
UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') :
UriFactory::build('{/prefix}' . $unit->getImage()->getPath()); ?>"
width="40x">
</a>
</div>
<div><?= $this->getHtml('Unit') ?></div>
</div>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iName"><?= $this->getHtml('Name') ?></label>

0
composer.json Normal file → Executable file
View File

0
composer.lock generated Normal file → Executable file
View File

6
info.json Normal file → Executable file
View File

@ -18,10 +18,12 @@
"directory": "Organization",
"dependencies": {
"Admin": "1.0.0",
"Editor": "1.0.0"
"Editor": "1.0.0",
"Media": "1.0.0"
},
"providing": {
"Navigation": "*"
"Navigation": "*",
"Media": "*"
},
"load": [
{

0
tests/Admin/AdminTest.php Normal file → Executable file
View File

0
tests/ControllerTest.php Normal file → Executable file
View File

0
tests/Models/DepartmentMapperTest.php Normal file → Executable file
View File

0
tests/Models/DepartmentTest.php Normal file → Executable file
View File

0
tests/Models/PositionMapperTest.php Normal file → Executable file
View File

0
tests/Models/PositionTest.php Normal file → Executable file
View File

0
tests/Models/UnitMapperTest.php Normal file → Executable file
View File

0
tests/Models/UnitTest.php Normal file → Executable file
View File