Merged in os-123-add-owned-property-to-department (pull request #91)
Os 123 add owned property to department
This commit is contained in:
commit
b424016721
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,12 @@ class DeleteStaffController extends Controller {
|
|||
$ticket->store();
|
||||
}
|
||||
|
||||
foreach($staff->sharedDepartmentList as $department) {
|
||||
$department->owners--;
|
||||
$department->store();
|
||||
}
|
||||
|
||||
|
||||
$staff->delete();
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@ class EditStaffController extends Controller {
|
|||
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
|
||||
];
|
||||
}
|
||||
}
|
|
@ -22,6 +22,10 @@ describe'/staff/add' do
|
|||
(row['email']).should.equal('tyrion@opensupports.com')
|
||||
(row['profile_pic']).should.equal('http://www.opensupports.com/profilepic.jpg')
|
||||
(row['level']).should.equal('2')
|
||||
|
||||
row = $database.getRow('department', 1, 'id')
|
||||
(row['owners']).should.equal('2')
|
||||
|
||||
end
|
||||
it 'should fail if staff member is alrady a staff' do
|
||||
result= request('/staff/add', {
|
||||
|
@ -38,5 +42,7 @@ describe'/staff/add' do
|
|||
(result['status']).should.equal('fail')
|
||||
(result['message']).should.equal('ALREADY_A_STAFF')
|
||||
|
||||
row = $database.getRow('department', 1, 'id')
|
||||
(row['owners']).should.equal('2')
|
||||
end
|
||||
end
|
|
@ -14,6 +14,9 @@ describe'/staff/delete' do
|
|||
row = $database.getRow('staff', 2, 'id')
|
||||
(row).should.equal(nil)
|
||||
|
||||
row = $database.getRow('department', 1, 'id')
|
||||
(row['owners']).should.equal('2')
|
||||
|
||||
end
|
||||
it 'should fail delete if staff member is does not exist' do
|
||||
result= request('/staff/delete', {
|
||||
|
@ -25,5 +28,7 @@ describe'/staff/delete' do
|
|||
(result['status']).should.equal('fail')
|
||||
(result['message']).should.equal('INVALID_STAFF')
|
||||
|
||||
row = $database.getRow('department', 1, 'id')
|
||||
(row['owners']).should.equal('2')
|
||||
end
|
||||
end
|
|
@ -23,6 +23,12 @@ describe'/staff/edit' do
|
|||
|
||||
(rows['department_id']).should.equal('1')
|
||||
|
||||
row = $database.getRow('department', 1, 'id')
|
||||
(row['owners']).should.equal('2')
|
||||
|
||||
row = $database.getRow('department', 2, 'id')
|
||||
(row['owners']).should.equal('2')
|
||||
|
||||
end
|
||||
|
||||
it 'should edit staff member ' do
|
||||
|
@ -52,5 +58,8 @@ describe'/staff/edit' do
|
|||
(row['email']).should.equal('newwstaff@opensupports.com')
|
||||
(row['level']).should.equal('2')
|
||||
|
||||
row = $database.getRow('department', 1, 'id')
|
||||
(row['owners']).should.equal('3')
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue