Guillermo - department add owners property[skip ci]
This commit is contained in:
parent
3b1529fee3
commit
49a4620457
|
@ -51,9 +51,11 @@ class AddStaffController extends Controller {
|
|||
'password'=> Hashing::hashPassword($this->password),
|
||||
'profilePic' => $this->profilePic,
|
||||
'level' => $this->level,
|
||||
'sharedDepartmentList'=> $this->getDepartmentList(),
|
||||
]);
|
||||
'sharedDepartmentList' => $this->getDepartmentList()
|
||||
|
||||
]);
|
||||
|
||||
$this->addOwner();
|
||||
|
||||
Response::respondSuccess([
|
||||
'id' => $staff->store()
|
||||
|
@ -84,4 +86,13 @@ class AddStaffController extends Controller {
|
|||
|
||||
return $listDepartments;
|
||||
}
|
||||
public function addOwner() {
|
||||
$departmentIds = json_decode($this->departments);
|
||||
|
||||
foreach($departmentIds as $id) {
|
||||
$departmentRow = Department::getDataStore($id);
|
||||
$departmentRow->owners++;
|
||||
$departmentRow->store();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,12 @@ class DeleteStaffController extends Controller {
|
|||
$ticket->true = true;
|
||||
$ticket->store();
|
||||
}
|
||||
|
||||
foreach($staff->sharedDepartmentList as $department) {
|
||||
$department->owners--;
|
||||
$department->store();
|
||||
}
|
||||
|
||||
|
||||
$staff->delete();
|
||||
Response::respondSuccess();
|
||||
|
|
|
@ -30,6 +30,10 @@ class EditStaffController extends Controller {
|
|||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
if(Controller::request('departments')) {
|
||||
$this->updateDepartmentsOwners();
|
||||
}
|
||||
|
||||
$this->editInformation();
|
||||
Response::respondSuccess();
|
||||
|
@ -68,4 +72,39 @@ class EditStaffController extends Controller {
|
|||
|
||||
return $listDepartments;
|
||||
}
|
||||
|
||||
public function updateDepartmentsOwners() {
|
||||
$list1 = $this->staffRow->sharedDepartmentList;
|
||||
$list2 = $this->getDepartmentList();
|
||||
|
||||
foreach ($list1 as $department1) {
|
||||
$match = false;
|
||||
|
||||
foreach ($list2 as $department2) {
|
||||
if($department1->id == $department2->id) {
|
||||
$match = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$match) {
|
||||
$department1->owners--;
|
||||
$department1->store();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($list2 as $department2) {
|
||||
$match = false;
|
||||
|
||||
foreach ($list1 as $department1) {
|
||||
if($department2->id == $department1->id) {
|
||||
$match = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$match) {
|
||||
$department2->owners++;
|
||||
$department2->store();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -93,6 +93,10 @@ class InitSettingsController extends Controller {
|
|||
'sharedDepartmentList' => Department::getAll(),
|
||||
'sharedTicketList' => []
|
||||
]);
|
||||
foreach(Department::getAll() as $department) {
|
||||
$department->owners++;
|
||||
$department->store();
|
||||
}
|
||||
$staff->store();
|
||||
}
|
||||
}
|
|
@ -7,7 +7,14 @@ class Department extends DataStore {
|
|||
public static function getProps() {
|
||||
return [
|
||||
'name',
|
||||
'sharedTicketList'
|
||||
'sharedTicketList',
|
||||
'owners'
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultProps() {
|
||||
return [
|
||||
'owners' => 0
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -18,7 +25,8 @@ class Department extends DataStore {
|
|||
foreach($departmentsList as $department) {
|
||||
$departmentsNameList[] = [
|
||||
'id' => $department->id,
|
||||
'name' => $department->name
|
||||
'name' => $department->name,
|
||||
'owners' => $department->owners
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -27,7 +35,8 @@ class Department extends DataStore {
|
|||
public function toArray() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name
|
||||
'name' => $this->name,
|
||||
'owners' => $this->owners
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue