diff --git a/Controller.php b/Controller.php index 966b167..a93880c 100644 --- a/Controller.php +++ b/Controller.php @@ -222,6 +222,8 @@ class Controller extends ModuleAbstract implements WebInterface $view->setTemplate('/Modules/Organization/Theme/Backend/position-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004704001, $request, $response)); + $view->addData('list:elements', PositionMapper::getAll()); + return $view; } @@ -241,6 +243,8 @@ class Controller extends ModuleAbstract implements WebInterface $view->setTemplate('/Modules/Organization/Theme/Backend/position-profile'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004704001, $request, $response)); + $view->addData('position', PositionMapper::get((int) $request->getData('id'))); + return $view; } @@ -301,21 +305,30 @@ class Controller extends ModuleAbstract implements WebInterface $response->set('unit', $unit->jsonSerialize()); } - public function apiPositionCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) + private function validatePositionCreate(RequestAbstract $request) : array { $val = []; if ( - ($val['name'] = empty($request->getData('name'))) + ($val['name'] = empty($request->getData('name'))) || ($val['parent'] = ( - $request->getData('parent') !== null - && !is_numeric($request->getData('parent')) - )) - || ($val['status'] = ( - $request->getData('status') === null - || !Status::isValidValue((int) $request->getData('status')) - )) + !empty($request->getData('parent')) + && !is_numeric($request->getData('parent')) + )) + || ($val['status'] = ( + $request->getData('status') === null + || !Status::isValidValue((int) $request->getData('status')) + )) ) { - $response->set('position_create_validation', new FormValidation($val)); + return $val; + } + + return []; + } + + public function apiPositionCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) + { + if (!empty($val = $this->validatePositionCreate($request))) { + $response->set('position_create', new FormValidation($val)); return; } @@ -323,28 +336,36 @@ class Controller extends ModuleAbstract implements WebInterface $position = new Position(); $position->setName($request->getData('name')); $position->setStatus((int) $request->getData('status')); - $position->setDescription($request->getData('desc')); + $position->setDescription($request->getData('description') ?? ''); PositionMapper::create($position); $response->set('position', $position->jsonSerialize()); } - public function apiDepartmentCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) + private function validateDepartmentCreate(RequestAbstract $request) : array { $val = []; if ( - ($val['name'] = empty($request->getData('name'))) + ($val['name'] = empty($request->getData('name'))) || ($val['parent'] = ( - $request->getData('parent') !== null - && !is_numeric((int) $request->getData('parent')) - )) - || ($val['status'] = ( - $request->getData('status') === null - || !Status::isValidValue($request->getData('status'))) - ) + !empty($request->getData('parent')) + && !is_numeric($request->getData('parent')) + )) + || ($val['unit'] = ( + !is_numeric((int) $request->getData('unit')) + )) ) { - $response->set('department_create_validation', new FormValidation($val)); + return $val; + } + + return []; + } + + public function apiDepartmentCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) + { + if (!empty($val = $this->validateDepartmentCreate($request))) { + $response->set('department_create', new FormValidation($val)); return; } @@ -352,7 +373,7 @@ class Controller extends ModuleAbstract implements WebInterface $department = new Department(); $department->setName($request->getData('name')); $department->setStatus((int) $request->getData('status')); - $department->setDescription($request->getData('desc')); + $department->setDescription($request->getData('description') ?? ''); DepartmentMapper::create($department); diff --git a/Theme/Backend/department-create.tpl.php b/Theme/Backend/department-create.tpl.php index 63da223..a9683dc 100644 --- a/Theme/Backend/department-create.tpl.php +++ b/Theme/Backend/department-create.tpl.php @@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>

getText('Department'); ?>

-
+ getData('list:elements') as $key => $value) : $c++; - $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/business/department/profile?id=' . $value->getId()); ?> + $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/organization/department/profile?id=' . $value->getId()); ?>
diff --git a/Theme/Backend/department-list.tpl.php b/Theme/Backend/department-list.tpl.php index 0ec3185..7f4d2a8 100644 --- a/Theme/Backend/department-list.tpl.php +++ b/Theme/Backend/department-list.tpl.php @@ -39,7 +39,7 @@ echo $this->getData('nav')->render(); ?>
render(); ?>
getId(); ?> getName(); ?> diff --git a/Theme/Backend/department-profile.php b/Theme/Backend/department-profile.tpl.php similarity index 96% rename from Theme/Backend/department-profile.php rename to Theme/Backend/department-profile.tpl.php index c51790d..5b4936e 100644 --- a/Theme/Backend/department-profile.php +++ b/Theme/Backend/department-profile.tpl.php @@ -22,7 +22,7 @@ $department = $this->getData('department'); echo $this->getData('nav')->render(); ?>
-

getText('Position'); ?>

+

getText('Department'); ?>

diff --git a/Theme/Backend/position-create.tpl.php b/Theme/Backend/position-create.tpl.php index 20bcbf7..64d38be 100644 --- a/Theme/Backend/position-create.tpl.php +++ b/Theme/Backend/position-create.tpl.php @@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>

getText('Position'); ?>

- +
$value) : $count++; - $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/business/unit/profile?id=' . $value->getId()); ?> + $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/organization/position/profile?id=' . $value->getId()); ?>
@@ -30,8 +30,8 @@ echo $this->getData('nav')->render(); ?>
diff --git a/Theme/Backend/position-list.tpl.php b/Theme/Backend/position-list.tpl.php index 135dec5..4590659 100644 --- a/Theme/Backend/position-list.tpl.php +++ b/Theme/Backend/position-list.tpl.php @@ -40,7 +40,7 @@ echo $this->getData('nav')->render(); ?>
render(); ?>
getId(); ?> getName(); ?> diff --git a/Theme/Backend/position-profile.tpl.php b/Theme/Backend/position-profile.tpl.php index 237d815..a778d8d 100644 --- a/Theme/Backend/position-profile.tpl.php +++ b/Theme/Backend/position-profile.tpl.php @@ -17,7 +17,7 @@ * @var \phpOMS\Views\View $this */ -$unit = $this->getData('unit'); +$position = $this->getData('position'); echo $this->getData('nav')->render(); ?> @@ -27,16 +27,16 @@ echo $this->getData('nav')->render(); ?>
-
+
-
+
-
+
diff --git a/Theme/Backend/unit-create.tpl.php b/Theme/Backend/unit-create.tpl.php index 6a827f3..8ebd9b0 100644 --- a/Theme/Backend/unit-create.tpl.php +++ b/Theme/Backend/unit-create.tpl.php @@ -22,7 +22,7 @@ echo $this->getData('nav')->render(); ?>

getText('Unit'); ?>

-
+