Updating employee data from view #20

Merged
PootisPenserHere merged 9 commits from updatingEmployeeDataFromView into master 2018-08-13 05:18:48 +00:00
2 changed files with 38 additions and 6 deletions
Showing only changes of commit 68723e82fe - Show all commits

View File

@ -233,6 +233,33 @@ class EmployeeApplication{
return $results[0]['id']; return $results[0]['id'];
} }
/**
* @param $code string
* @return integer
*/
function getIdEmployeeByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty.");
$stmt = $this->pdo->prepare("SELECT
COALESCE((SELECT
id
FROM
employees
WHERE
code = :code),
0) AS id;
");
$stmt->execute(array(':code' => $code));
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
}
$stmt = null;
return $results[0]['id'];
}
/** /**
* Gets the data associated with the employee * Gets the data associated with the employee
* *
@ -243,18 +270,23 @@ class EmployeeApplication{
$this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0"); $this->asserts->higherThanZero($idEmployee, "idEmployee must be higher than 0");
$stmt = $this->pdo->prepare("SELECT $stmt = $this->pdo->prepare("SELECT
e.id AS idEmployee,
p.id AS idPerson, p.id AS idPerson,
p.firstName, p.firstName,
p.middleName, p.middleName,
IFNULL(p.lastName, '') AS lastName, IFNULL(p.lastName, '') AS lastName,
p.birthDate,
p.email, p.email,
p.phone, p.phone,
e.code, e.code,
et.name AS employeeType,
e.contractType e.contractType
FROM FROM
employees e employees e
INNER JOIN INNER JOIN
persons p ON p.id = e.idPerson persons p ON p.id = e.idPerson
INNER JOIN
employeeType et ON et.id = e.idEmployeeType
WHERE WHERE
e.id = :idEmployee"); e.id = :idEmployee");
@ -281,6 +313,7 @@ class EmployeeApplication{
$employeeData = $this->getEmployeeDataById($idEmployee); $employeeData = $this->getEmployeeDataById($idEmployee);
$response = array( $response = array(
"idEmployee" => (int)$employeeData['idEmployee'],
"idPerson" => (int)$employeeData['idPerson'], "idPerson" => (int)$employeeData['idPerson'],
"firstName" => $this->cryptographyService->decryptString($employeeData['firstName']), "firstName" => $this->cryptographyService->decryptString($employeeData['firstName']),
"middleName" => $this->cryptographyService->decryptString($employeeData['middleName']), "middleName" => $this->cryptographyService->decryptString($employeeData['middleName']),
@ -289,9 +322,11 @@ class EmployeeApplication{
? $this->cryptographyService->decryptString($employeeData['lastName']) ? $this->cryptographyService->decryptString($employeeData['lastName'])
: '', : '',
"birthDate" => $employeeData['birthDate'],
"email" => $this->cryptographyService->decryptString($employeeData['email']), "email" => $this->cryptographyService->decryptString($employeeData['email']),
"phone" => $employeeData['phone'], "phone" => $employeeData['phone'],
"code" => $employeeData['code'], "code" => $employeeData['code'],
"employeeType" => $employeeData['employeeType'],
"contractType" => $employeeData['contractType'] "contractType" => $employeeData['contractType']
); );
@ -306,7 +341,7 @@ class EmployeeApplication{
function getEmployeeDataByCode($code){ function getEmployeeDataByCode($code){
$this->asserts->isNotEmpty($code, "The code can't be empty."); $this->asserts->isNotEmpty($code, "The code can't be empty.");
$idEmployee = $this->getIdEmployeeTypeByCode($code); $idEmployee = $this->getIdEmployeeByCode($code);
return $this->proxyGetEmployeeDataById($idEmployee); return $this->proxyGetEmployeeDataById($idEmployee);
} }
@ -519,14 +554,10 @@ class EmployeeApplication{
$currentEmployee = $this->proxyGetEmployeeDataById($row['id']); $currentEmployee = $this->proxyGetEmployeeDataById($row['id']);
$result[] = array( $result[] = array(
'idPerson' => $currentEmployee['idPerson'],
'fullName' => $currentEmployee['firstName']." ". 'fullName' => $currentEmployee['firstName']." ".
$currentEmployee['middleName']." ". $currentEmployee['middleName']." ".
$currentEmployee['lastName'], $currentEmployee['lastName'],
'email' => $currentEmployee['email'], 'code' => $currentEmployee['code']
'phone' => $currentEmployee['phone'],
'code' => $currentEmployee['code'],
'contractType' => $currentEmployee['contractType']
); );
} }

View File

@ -45,6 +45,7 @@ return [
// Employee settings // Employee settings
'employee' => [ 'employee' => [
'codeLength' => '3', 'codeLength' => '3',
'contractTypes' => array('INTERNO', 'EXTERNO'),
], ],
], ],
]; ];