Guillermo - staff/add [skip ci]

This commit is contained in:
Ivan Diaz 2016-12-07 16:59:42 -03:00
parent 60211c2b3c
commit 630e121bfb

View File

@ -39,20 +39,19 @@ class AddStaffController extends Controller {
} }
public function handler() { public function handler() {
$this->storeRequestData(); $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([ $staff->setProperties([
'name'=> $this->name, 'name'=> $this->name,
'email' => $this->email, 'email' => $this->email,
'password'=> $this->password, 'password'=> $this->password,
'profilePic' => $this->profilePic, 'profilePic' => $this->profilePic,
'level' => $this->level, 'level' => $this->level,
'sharedDepartmentList'=> $this->departments, 'sharedDepartmentList'=> $this->getDepartmentList(),
]); ]);
$staff->store(); $staff->store();
@ -62,9 +61,8 @@ class AddStaffController extends Controller {
} }
Response::respondError(ERRORS::ALREADY_A_STAFF); Response::respondError(ERRORS::ALREADY_A_STAFF);
} }
public function storeRequestData() { public function storeRequestData() {
$this->name = Controller::request('name'); $this->name = Controller::request('name');
$this->email = Controller::request('email'); $this->email = Controller::request('email');
@ -73,4 +71,16 @@ class AddStaffController extends Controller {
$this->level = Controller::request('level'); $this->level = Controller::request('level');
$this->departments = Controller::request('departments'); $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;
}
} }