Guillermo - staff/add [skip ci]

This commit is contained in:
Ivan Diaz 2016-12-07 16:59:42 -03:00
parent 60211c2b3c
commit 630e121bfb
1 changed files with 17 additions and 7 deletions

View File

@ -39,20 +39,19 @@ class AddStaffController extends Controller {
}
public function handler() {
$this->storeRequestData();
$staff = new Staff();
$staff = new Staff();
$staffrow = Staff::getDataStore($this->email,'email');
$staffRow = Staff::getDataStore($this->email,'email');
if($staffrow->isNull()) {
if($staffRow->isNull()) {
$staff->setProperties([
'name'=> $this->name,
'email' => $this->email,
'password'=> $this->password,
'profilePic' => $this->profilePic,
'level' => $this->level,
'sharedDepartmentList'=> $this->departments,
'sharedDepartmentList'=> $this->getDepartmentList(),
]);
$staff->store();
@ -62,9 +61,8 @@ class AddStaffController extends Controller {
}
Response::respondError(ERRORS::ALREADY_A_STAFF);
}
public function storeRequestData() {
$this->name = Controller::request('name');
$this->email = Controller::request('email');
@ -73,4 +71,16 @@ class AddStaffController extends Controller {
$this->level = Controller::request('level');
$this->departments = Controller::request('departments');
}
public function getDepartmentList() {
$listDepartments = new DataStoreList();
$departmentIds = json_decode($this->departments);
foreach($departmentIds as $id) {
$department = Department::getDataStore($id);
$listDepartments->add($department);
}
return $listDepartments;
}
}