diff --git a/Controller/ApiController.php b/Controller/ApiController.php index e62b60e..a610116 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -17,6 +17,9 @@ namespace Modules\Organization\Controller; use Model\Setting; use Model\SettingMapper; use Modules\Admin\Models\AddressMapper; +use Modules\Admin\Models\Contact; +use Modules\Admin\Models\ContactMapper; +use Modules\Admin\Models\ContactType; use Modules\Admin\Models\SettingsEnum as ModelsSettingsEnum; use Modules\Media\Models\PathSettings; use Modules\Organization\Models\Department; @@ -731,7 +734,7 @@ final class ApiController extends Controller /** @var \Modules\Organization\Models\Unit[] $units */ $units = UnitMapper::getAll() ->where('name', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') - ->execute(); + ->executeGetArray(); $response->header->set('Content-Type', MimeType::M_JSON, true); $response->set( @@ -758,7 +761,7 @@ final class ApiController extends Controller /** @var \Modules\Organization\Models\Department[] $departments */ $departments = DepartmentMapper::getAll() ->where('name', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') - ->execute(); + ->executeGetArray(); $response->header->set('Content-Type', MimeType::M_JSON, true); $response->set( @@ -785,7 +788,7 @@ final class ApiController extends Controller /** @var \Modules\Organization\Models\Position[] $positions */ $positions = PositionMapper::getAll() ->where('name', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE') - ->execute(); + ->executeGetArray(); $response->header->set('Content-Type', MimeType::M_JSON, true); $response->set( @@ -793,4 +796,81 @@ final class ApiController extends Controller \array_values($positions) ); } + + /** + * Routing end-point for application behavior. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiUnitContactCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + if (!empty($val = $this->validateUnitContactCreate($request))) { + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); + + return; + } + + $contact = $this->createUnitContactFromRequest($request); + $this->createModel($request->header->account, $contact, ContactMapper::class, 'unit_contact', $request->getOrigin()); + + $this->createModelRelation( + $request->header->account, + (int) $request->getData('unit'), + $contact->id, + UnitMapper::class, 'contacts', '', $request->getOrigin() + ); + + $this->createStandardCreateResponse($request, $response, $contact); + } + + /** + * Validate contact element create request + * + * @param RequestAbstract $request Request + * + * @return array + * + * @since 1.0.0 + */ + public function validateUnitContactCreate(RequestAbstract $request) : array + { + $val = []; + if (($val['unit'] = !$request->hasData('unit')) + || ($val['type'] = !\is_numeric($request->getData('type'))) + || ($val['content'] = !$request->hasData('content')) + ) { + return $val; + } + + return []; + } + + /** + * Method to create a account element from request. + * + * @param RequestAbstract $request Request + * + * @return Contact + * + * @since 1.0.0 + */ + public function createUnitContactFromRequest(RequestAbstract $request) : Contact + { + /** @var Contact $element */ + $element = new Contact(); + $element->type = ContactType::tryFromValue($request->getDataInt('type')) ?? ContactType::EMAIL; + $element->subtype = $request->getDataInt('subtype') ?? 0; + $element->content = $request->getDataString('content') ?? ''; + + return $element; + } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 5b8c894..f57cf0e 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -62,9 +62,9 @@ final class BackendController extends Controller ->limit(25); if ($request->getData('ptype') === 'p') { - $view->data['units'] = $mapper->where('id', $request->getDataInt('id') ?? 0, '<')->execute(); + $view->data['units'] = $mapper->where('id', $request->getDataInt('offset') ?? 0, '<')->execute(); } elseif ($request->getData('ptype') === 'n') { - $view->data['units'] = $mapper->where('id', $request->getDataInt('id') ?? 0, '>')->execute(); + $view->data['units'] = $mapper->where('id', $request->getDataInt('offset') ?? 0, '>')->execute(); } else { $view->data['units'] = $mapper->where('id', 0, '>')->execute(); } @@ -94,18 +94,21 @@ final class BackendController extends Controller $selectorView = new \Modules\Organization\Theme\Backend\Components\UnitTagSelector\UnitTagSelectorView($this->app->l11nManager, $request, $response); $view->data['unit-selector'] = $selectorView; - $unit = UnitMapper::get() + $view->data['unit'] = UnitMapper::get() ->with('parent') ->with('mainAddress') + ->with('address') + ->with('contacts') ->with('image') ->where('id', (int) $request->getData('id')) ->execute(); - $view->data['unit'] = $unit; - $editor = new \Modules\Editor\Theme\Backend\Components\Editor\BaseView($this->app->l11nManager, $request, $response); $view->data['editor'] = $editor; + $view->data['address-component'] = new \Modules\Admin\Theme\Backend\Components\AddressEditor\AddressView($this->app->l11nManager, $request, $response); + $view->data['contact-component'] = new \Modules\Admin\Theme\Backend\Components\ContactEditor\ContactView($this->app->l11nManager, $request, $response); + return $view; } @@ -130,17 +133,17 @@ final class BackendController extends Controller $view->setTemplate('/Modules/Organization/Theme/Backend/organigram'); /** @var Unit[] $units */ - $units = UnitMapper::getAll()->with('parent')->execute(); + $units = UnitMapper::getAll()->with('parent')->executeGetArray(); $unitTree = $this->createOrgTree($units); $view->data['unitTree'] = $unitTree; /** @var Department[] $departments */ - $departments = DepartmentMapper::getAll()->with('parent')->with('unit')->execute(); + $departments = DepartmentMapper::getAll()->with('parent')->with('unit')->executeGetArray(); $depTree = $this->createOrgTree($departments); $view->data['departmentTree'] = $depTree; /** @var Position[] $positions */ - $positions = PositionMapper::getAll()->with('parent')->with('unit')->with('department')->execute(); + $positions = PositionMapper::getAll()->with('parent')->with('unit')->with('department')->executeGetArray(); $posTree = $this->createOrgTree($positions); $view->data['positionTree'] = $posTree; @@ -233,9 +236,9 @@ final class BackendController extends Controller $mapper = DepartmentMapper::getAll()->with('parent')->with('unit')->limit($pageLimit + 1); if ($request->getData('ptype') === 'p') { - $mapper->where('id', $request->getDataInt('id') ?? 0, '<'); + $mapper->where('id', $request->getDataInt('offset') ?? 0, '<'); } elseif ($request->getData('ptype') === 'n') { - $mapper->where('id', $request->getDataInt('id') ?? 0, '>'); + $mapper->where('id', $request->getDataInt('offset') ?? 0, '>'); } else { $mapper->where('id', 0, '>'); } @@ -337,11 +340,11 @@ final class BackendController extends Controller $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1004705001, $request, $response); if ($request->getData('ptype') === 'p') { - $view->data['positions'] = PositionMapper::getAll()->with('parent')->with('department')->where('id', $request->getDataInt('id') ?? 0, '<')->limit(25)->execute(); + $view->data['positions'] = PositionMapper::getAll()->with('parent')->with('department')->where('id', $request->getDataInt('offset') ?? 0, '<')->limit(25)->executeGetArray(); } elseif ($request->getData('ptype') === 'n') { - $view->data['positions'] = PositionMapper::getAll()->with('parent')->with('department')->where('id', $request->getDataInt('id') ?? 0, '>')->limit(25)->execute(); + $view->data['positions'] = PositionMapper::getAll()->with('parent')->with('department')->where('id', $request->getDataInt('offset') ?? 0, '>')->limit(25)->executeGetArray(); } else { - $view->data['positions'] = PositionMapper::getAll()->with('parent')->with('department')->where('id', 0, '>')->limit(25)->execute(); + $view->data['positions'] = PositionMapper::getAll()->with('parent')->with('department')->where('id', 0, '>')->limit(25)->executeGetArray(); } return $view; diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php deleted file mode 100755 index 3600fe7..0000000 --- a/Models/AttributeValueType.php +++ /dev/null @@ -1,40 +0,0 @@ -address; + foreach ($this->contacts as $element) { + if ($element->type === $type) { + return $element; + } + } + + return new NullContact(); } /** diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php index ee5622d..ba4a0ae 100755 --- a/Theme/Backend/Lang/de.lang.php +++ b/Theme/Backend/Lang/de.lang.php @@ -35,4 +35,6 @@ return ['Organization' => [ 'Unit' => 'Einheit', 'UnitLogo' => 'Einheit-Logo', 'Units' => 'Einheiten', + 'Profile' => 'Profil', + 'Addresses' => 'Addressen', ]]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index d591859..ae67c3b 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -35,4 +35,6 @@ return ['Organization' => [ 'Unit' => 'Unit', 'UnitLogo' => 'Unit Logo', 'Units' => 'Units', + 'Profile' => 'Profile', + 'Addresses' => 'Addresses', ]]; diff --git a/Theme/Backend/department-list.tpl.php b/Theme/Backend/department-list.tpl.php index 4a83731..dd9bfdf 100755 --- a/Theme/Backend/department-list.tpl.php +++ b/Theme/Backend/department-list.tpl.php @@ -22,7 +22,7 @@ $departments = $this->data['departments'] ?? []; $previous = empty($departments) ? 'organization/department/list' - : 'organization/department/list?{?}&id=' . \reset($departments)->id . '&ptype=p'; + : 'organization/department/list?{?}&offset=' . \reset($departments)->id . '&ptype=p'; $next = empty($departments) ? 'organization/department/list' : 'organization/department/list?{?}&id=' diff --git a/Theme/Backend/position-list.tpl.php b/Theme/Backend/position-list.tpl.php index 2e2435b..9b909bf 100755 --- a/Theme/Backend/position-list.tpl.php +++ b/Theme/Backend/position-list.tpl.php @@ -20,8 +20,8 @@ use phpOMS\Uri\UriFactory; */ $positions = $this->data['positions'] ?? []; -$previous = empty($positions) ? 'organization/position/list' : '{/base}/organization/position/list?{?}&id=' . \reset($positions)->id . '&ptype=p'; -$next = empty($positions) ? 'organization/position/list' : '{/base}/organization/position/list?{?}&id=' . \end($positions)->id . '&ptype=n'; +$previous = empty($positions) ? 'organization/position/list' : '{/base}/organization/position/list?{?}&offset=' . \reset($positions)->id . '&ptype=p'; +$next = empty($positions) ? 'organization/position/list' : '{/base}/organization/position/list?{?}&offset=' . \end($positions)->id . '&ptype=n'; echo $this->data['nav']->render(); ?> diff --git a/Theme/Backend/unit-list.tpl.php b/Theme/Backend/unit-list.tpl.php index b540503..97005d0 100755 --- a/Theme/Backend/unit-list.tpl.php +++ b/Theme/Backend/unit-list.tpl.php @@ -20,8 +20,8 @@ use phpOMS\Uri\UriFactory; */ $units = $this->data['units'] ?? []; -$previous = empty($units) ? 'organization/unit/list' : '{/base}/organization/unit/list?{?}&id=' . \reset($units)->id . '&ptype=p'; -$next = empty($units) ? 'organization/unit/list' : '{/base}/organization/unit/list?{?}&id=' . \end($units)->id . '&ptype=n'; +$previous = empty($units) ? 'organization/unit/list' : '{/base}/organization/unit/list?{?}&offset=' . \reset($units)->id . '&ptype=p'; +$next = empty($units) ? 'organization/unit/list' : '{/base}/organization/unit/list?{?}&offset=' . \end($units)->id . '&ptype=n'; echo $this->data['nav']->render(); ?> diff --git a/Theme/Backend/unit-view.tpl.php b/Theme/Backend/unit-view.tpl.php index ecff064..86ff229 100644 --- a/Theme/Backend/unit-view.tpl.php +++ b/Theme/Backend/unit-view.tpl.php @@ -12,6 +12,7 @@ */ declare(strict_types=1); +use Modules\Organization\Models\NullUnit; use Modules\Organization\Models\Status; use phpOMS\Localization\ISO3166NameEnum; use phpOMS\Localization\ISO3166TwoEnum; @@ -21,122 +22,144 @@ use phpOMS\Uri\UriFactory; * @var \phpOMS\Views\View $this * @var \Modules\Organization\Models\Unit $unit; */ -$unit = $this->data['unit']; +$unit = $this->data['unit'] ?? new NullUnit(); +$isNew = $unit->id === 0; $countryCodes = ISO3166TwoEnum::getConstants(); $countries = ISO3166NameEnum::getConstants(); echo $this->data['nav']->render(); ?> -
- -
-
-
-
-
-
- - <?= $this->getHtml('Logo'); ?> - -
-
getHtml('Unit'); ?>
-
-
-
- - -
- -
- - getData('unit-selector')->render('iParent', 'parent', false); ?> -
- -
- - -
- -
- getData('editor')->render('unit-editor'); ?> -
- - getData('editor')->getData('text')->render( - 'unit-editor', - 'description', - 'iUnit', - $unit->descriptionRaw, - $unit->description - ); ?> -
-
- - -
-
-
+
+ +
+
+ +
+ request->uri->fragment === 'c-tab-1' ? ' checked' : ''; ?>> +
+
+
+
+
+
+
+
+ + <?= $this->getHtml('Logo'); ?> + +
+
getHtml('Unit'); ?>
+
+
+
+ + +
-
-
-
getHtml('MainAddress'); ?>
- -
-
- - -
+
+ + getData('unit-selector')->render('iParent', 'parent', false); ?> +
-
- - -
+
+ + +
-
- - -
+
+ getData('editor')->render('unit-editor'); ?> +
-
- - -
- -
- - + getData('editor')->getData('text')->render( + 'unit-editor', + 'description', + 'iUnit', + $unit->descriptionRaw, + $unit->description + ); ?> +
+
+ + +
+
-
- - + +
+
+
getHtml('MainAddress'); ?>
+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + +
+
+
- +
+ getData('unit-selector')->getData('unit-selector-popup')->render(); ?>
+ + + request->uri->fragment === 'c-tab-2' ? ' checked' : ''; ?>> +
+ data['contact-component']->render('unit-contact', 'contacts', $unit->contacts); ?> + data['address-component']->render('unit-address', 'addresses', $unit->address); ?> +
+
- -getData('unit-selector')->getData('unit-selector-popup')->render(); ?>