mirror of
https://github.com/Karaka-Management/oms-Organization.git
synced 2026-02-15 15:58:40 +00:00
Create units
This commit is contained in:
parent
7f5e9a8b85
commit
62c349d3d3
|
|
@ -263,29 +263,38 @@ class Controller extends ModuleAbstract implements WebInterface
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apiUnitCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
|
private function validateUnitCreate(RequestAbstract $request) : array
|
||||||
{
|
{
|
||||||
$val = [];
|
$val = [];
|
||||||
if (
|
if (
|
||||||
($val['name'] = empty($request->getData('name')))
|
($val['name'] = empty($request->getData('name')))
|
||||||
|| ($val['parent'] = (
|
|| ($val['parent'] = (
|
||||||
$request->getData('parent') !== null
|
!empty($request->getData('parent'))
|
||||||
&& !is_numeric($request->getData('parent'))
|
&& !is_numeric($request->getData('parent'))
|
||||||
))
|
))
|
||||||
|| ($val['status'] = (
|
|| ($val['status'] = (
|
||||||
$request->getData('status') === null
|
$request->getData('status') === null
|
||||||
|| !Status::isValidValue((int) $request->getData('status'))
|
|| !Status::isValidValue((int) $request->getData('status'))
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
$response->set('unit_create_validation', new FormValidation($val));
|
return $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apiUnitCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
|
||||||
|
{
|
||||||
|
if (!empty($val = $this->validateUnitCreate($request))) {
|
||||||
|
$response->set('unit_create', new FormValidation($val));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$unit = new Unit();
|
$unit = new Unit();
|
||||||
$unit->setName($request->getData('name'));
|
$unit->setName($request->getData('name'));
|
||||||
|
$unit->setDescription($request->getData('description') ?? '');
|
||||||
$unit->setStatus((int) $request->getData('status'));
|
$unit->setStatus((int) $request->getData('status'));
|
||||||
$unit->setDescription($request->getData('desc'));
|
|
||||||
|
|
||||||
UnitMapper::create($unit);
|
UnitMapper::create($unit);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class Unit implements ArrayableInterface, \JsonSerializable
|
||||||
|
|
||||||
private $name = '';
|
private $name = '';
|
||||||
|
|
||||||
private $parent = 0;
|
private $parent = null;
|
||||||
|
|
||||||
private $description = '';
|
private $description = '';
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ class Unit implements ArrayableInterface, \JsonSerializable
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParent() : int
|
public function getParent()
|
||||||
{
|
{
|
||||||
return $this->parent;
|
return $this->parent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" name="parent" id="iParent"></span>
|
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="text" name="parent" id="iParent"></span>
|
||||||
<tr><td><label for="iStatus"><?= $this->getText('Status'); ?></label>
|
<tr><td><label for="iStatus"><?= $this->getText('Status'); ?></label>
|
||||||
<tr><td><select name="status" id="iStatus">
|
<tr><td><select name="status" id="iStatus">
|
||||||
<option><?= $this->getText('Active'); ?>
|
<option value="<?= \Modules\Organization\Models\Status::ACTIVE; ?>"><?= $this->getText('Active'); ?>
|
||||||
<option><?= $this->getText('Inactive'); ?>
|
<option value="<?= \Modules\Organization\Models\Status::INACTIVE; ?>"><?= $this->getText('Inactive'); ?>
|
||||||
</select>
|
</select>
|
||||||
<tr><td><label for="iDescription"><?= $this->getText('Description'); ?></label>
|
<tr><td><label for="iDescription"><?= $this->getText('Description'); ?></label>
|
||||||
<tr><td><textarea name="description" id="iDescription" placeholder=""></textarea>
|
<tr><td><textarea name="description" id="iDescription" placeholder=""></textarea>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user