diff --git a/Admin/Installer.php b/Admin/Installer.php index 70432ef..b675b8b 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -49,6 +49,7 @@ class Installer extends InstallerAbstract `organization_unit_name` varchar(50) DEFAULT NULL, `organization_unit_description` varchar(255) DEFAULT NULL, `organization_unit_parent` int(11) DEFAULT NULL, + `organization_unit_status` int(3) DEFAULT NULL, PRIMARY KEY (`organization_unit_id`), KEY `organization_unit_parent` (`organization_unit_parent`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' @@ -65,6 +66,7 @@ class Installer extends InstallerAbstract `organization_department_name` varchar(30) DEFAULT NULL, `organization_department_description` varchar(255) DEFAULT NULL, `organization_department_parent` int(11) DEFAULT NULL, + `organization_department_status` int(3) DEFAULT NULL, `organization_department_unit` int(11) NOT NULL, PRIMARY KEY (`organization_department_id`), KEY `organization_department_parent` (`organization_department_parent`), @@ -84,6 +86,7 @@ class Installer extends InstallerAbstract `organization_position_name` varchar(50) DEFAULT NULL, `organization_position_description` varchar(255) DEFAULT NULL, `organization_position_parent` int(11) DEFAULT NULL, + `organization_position_status` int(3) DEFAULT NULL, PRIMARY KEY (`organization_position_id`), KEY `organization_position_parent` (`organization_position_parent`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php new file mode 100644 index 0000000..cff7c8e --- /dev/null +++ b/Admin/Routes/Web/Api.php @@ -0,0 +1,24 @@ + [ + [ + 'dest' => '\Modules\Organization\Controller:apiPositionCreate', + 'verb' => RouteVerb::SET, + ], + ], + '^.*/api/organization/department.*$' => [ + [ + 'dest' => '\Modules\Organization\Controller:apiDepartmentCreate', + 'verb' => RouteVerb::SET, + ], + ], + '^.*/api/organization/unit.*$' => [ + [ + 'dest' => '\Modules\Organization\Controller:apiUnitCreate', + 'verb' => RouteVerb::SET, + ], + ], +]; diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 428da30..47b2ee1 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -57,23 +57,4 @@ return [ 'verb' => RouteVerb::GET, ], ], - - '^.*/api/organization/position.*$' => [ - [ - 'dest' => '\Modules\Organization\Controller:apiPositionCreate', - 'verb' => RouteVerb::SET, - ], - ], - '^.*/api/organization/department.*$' => [ - [ - 'dest' => '\Modules\Organization\Controller:apiDepartmentCreate', - 'verb' => RouteVerb::SET, - ], - ], - '^.*/api/organization/unit.*$' => [ - [ - 'dest' => '\Modules\Organization\Controller:apiUnitCreate', - 'verb' => RouteVerb::SET, - ], - ], ]; diff --git a/Controller.php b/Controller.php index 78cddd4..044a150 100644 --- a/Controller.php +++ b/Controller.php @@ -15,10 +15,12 @@ */ namespace Modules\Organization; +use Model\Message\FormValidation; use Modules\Organization\Models\Department; use Modules\Organization\Models\DepartmentMapper; use Modules\Organization\Models\Position; use Modules\Organization\Models\PositionMapper; +use Modules\Organization\Models\Status; use Modules\Organization\Models\Unit; use Modules\Organization\Models\UnitMapper; use phpOMS\Message\RequestAbstract; @@ -263,8 +265,26 @@ class Controller extends ModuleAbstract implements WebInterface public function apiUnitCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) { + $val = []; + if ( + $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')) + ) + ) { + $response->set('unit_create_validation', new FormValidation($val)); + + return; + } + $unit = new Unit(); $unit->setName($request->getData('name')); + $unit->setStatus((int) $request->getData('status')); $unit->setDescription($request->getData('desc')); UnitMapper::create($unit); @@ -274,8 +294,26 @@ class Controller extends ModuleAbstract implements WebInterface public function apiPositionCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) { + $val = []; + if ( + $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')) + ) + ) { + $response->set('position_create_validation', new FormValidation($val)); + + return; + } + $position = new Position(); $position->setName($request->getData('name')); + $position->setStatus((int) $request->getData('status')); $position->setDescription($request->getData('desc')); PositionMapper::create($position); @@ -285,8 +323,26 @@ class Controller extends ModuleAbstract implements WebInterface public function apiDepartmentCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) { + $val = []; + if ( + $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')) + ) + ) { + $response->set('department_create_validation', new FormValidation($val)); + + return; + } + $department = new Department(); $department->setName($request->getData('name')); + $department->setStatus((int) $request->getData('status')); $department->setDescription($request->getData('desc')); DepartmentMapper::create($department); diff --git a/Models/Department.php b/Models/Department.php index 1cdcf2d..97e1873 100644 --- a/Models/Department.php +++ b/Models/Department.php @@ -23,6 +23,8 @@ class Department protected $parent = null; + protected $status = Status::INACTIVE; + protected $unit = 1; protected $description = ''; @@ -52,6 +54,16 @@ class Department $this->parent = $parent; } + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) + { + $this->status = $status; + } + public function getUnit() : int { return $this->unit; diff --git a/Models/DepartmentMapper.php b/Models/DepartmentMapper.php index 25bd3d0..0790d87 100644 --- a/Models/DepartmentMapper.php +++ b/Models/DepartmentMapper.php @@ -30,6 +30,7 @@ class DepartmentMapper extends DataMapperAbstract 'organization_department_name' => ['name' => 'organization_department_name', 'type' => 'string', 'internal' => 'name'], 'organization_department_description' => ['name' => 'organization_department_description', 'type' => 'string', 'internal' => 'description'], 'organization_department_parent' => ['name' => 'organization_department_parent', 'type' => 'int', 'internal' => 'parent'], + 'organization_department_status' => ['name' => 'organization_department_status', 'type' => 'int', 'internal' => 'status'], 'organization_department_unit' => ['name' => 'organization_department_unit', 'type' => 'int', 'internal' => 'unit'], ]; diff --git a/Models/Position.php b/Models/Position.php index a37f649..5223f63 100644 --- a/Models/Position.php +++ b/Models/Position.php @@ -27,6 +27,8 @@ class Position implements ArrayableInterface, \JsonSerializable private $description = ''; + protected $status = Status::INACTIVE; + public function getId() : int { return $this->id; @@ -52,6 +54,16 @@ class Position implements ArrayableInterface, \JsonSerializable $this->parent = $parent; } + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) + { + $this->status = $status; + } + public function getDescription() : string { return $this->description; diff --git a/Models/PositionMapper.php b/Models/PositionMapper.php index df6ee5a..9b441c3 100644 --- a/Models/PositionMapper.php +++ b/Models/PositionMapper.php @@ -31,6 +31,7 @@ class PositionMapper extends DataMapperAbstract 'organization_position_name' => ['name' => 'organization_position_name', 'type' => 'string', 'internal' => 'name'], 'organization_position_description' => ['name' => 'organization_position_description', 'type' => 'string', 'internal' => 'description'], 'organization_position_parent' => ['name' => 'organization_position_parent', 'type' => 'int', 'internal' => 'parent'], + 'organization_position_status' => ['name' => 'organization_position_status', 'type' => 'int', 'internal' => 'status'], ]; /** diff --git a/Models/Status.php b/Models/Status.php new file mode 100644 index 0000000..1826a9c --- /dev/null +++ b/Models/Status.php @@ -0,0 +1,38 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Organization\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Accept status enum. + * + * @category Calendar + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class Status extends Enum +{ + const ACTIVE = 1; + + const INACTIVE = 2; + + const HIDDEN = 4; +} diff --git a/Models/Unit.php b/Models/Unit.php index 6fe6f18..62ebeb2 100644 --- a/Models/Unit.php +++ b/Models/Unit.php @@ -27,6 +27,8 @@ class Unit implements ArrayableInterface, \JsonSerializable private $description = ''; + protected $status = Status::INACTIVE; + public function getId() : int { return $this->id; @@ -52,6 +54,16 @@ class Unit implements ArrayableInterface, \JsonSerializable $this->parent = $parent; } + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) + { + $this->status = $status; + } + public function getDescription() : string { return $this->description; diff --git a/Models/UnitMapper.php b/Models/UnitMapper.php index f7148c7..df38f35 100644 --- a/Models/UnitMapper.php +++ b/Models/UnitMapper.php @@ -30,6 +30,7 @@ class UnitMapper extends DataMapperAbstract 'organization_unit_name' => ['name' => 'organization_unit_name', 'type' => 'string', 'internal' => 'name'], 'organization_unit_description' => ['name' => 'organization_unit_description', 'type' => 'string', 'internal' => 'description'], 'organization_unit_parent' => ['name' => 'organization_unit_parent', 'type' => 'int', 'internal' => 'parent'], + 'organization_unit_status' => ['name' => 'organization_unit_status', 'type' => 'int', 'internal' => 'status'], ]; /** diff --git a/Theme/Backend/unit-create.tpl.php b/Theme/Backend/unit-create.tpl.php index bc5658f..7f9af81 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'); ?>

-
+