Refactor project structure

This commit is contained in:
Thilina Hasantha
2018-04-29 17:46:42 +02:00
parent 889baf124c
commit e3a7e18d9c
5513 changed files with 32 additions and 27 deletions

View File

@@ -0,0 +1,197 @@
<?php
/**
* Created by PhpStorm.
* User: Thilina
* Date: 8/27/17
* Time: 5:23 PM
*/
namespace Employees\Admin\Api;
use Attendance\Common\Model\Attendance;
use Classes\BaseService;
use Classes\IceResponse;
use Classes\SubActionManager;
use Dependents\Common\Model\EmployeeDependent;
use Documents\Common\Model\EmployeeDocument;
use EmergencyContacts\Common\Model\EmergencyContact;
use Employees\Common\Model\ArchivedEmployee;
use Employees\Common\Model\Employee;
use Projects\Common\Model\EmployeeProject;
use Qualifications\Common\Model\EmployeeCertification;
use Qualifications\Common\Model\EmployeeEducation;
use Qualifications\Common\Model\EmployeeLanguage;
use Qualifications\Common\Model\EmployeeSkill;
use Salary\Common\Model\EmployeeSalary;
use TimeSheets\Common\Model\EmployeeTimeEntry;
use TimeSheets\Common\Model\EmployeeTimeSheet;
use Travel\Common\Model\EmployeeTravelRecord;
class EmployeesActionManager extends SubActionManager
{
public function terminateEmployee($req)
{
$employee = new Employee();
$employee->Load("id = ?", array($req->id));
if (empty($employee->id)) {
return new IceResponse(IceResponse::ERROR, "Employee Not Found");
}
$employee->termination_date = date('Y-m-d H:i:s');
$employee->status = 'Terminated';
$ok = $employee->Save();
if (!$ok) {
return new IceResponse(IceResponse::ERROR, "Error occurred while terminating employee");
}
return new IceResponse(IceResponse::SUCCESS, $employee);
//$user = BaseService::getInstance()->getUserFromProfileId($employee->id);
}
public function activateEmployee($req)
{
$employee = new Employee();
$employee->Load("id = ?", array($req->id));
if (empty($employee->id)) {
return new IceResponse(IceResponse::ERROR, "Employee Not Found");
}
$employee->termination_date = null;
$employee->status = 'Active';
$ok = $employee->Save();
if (!$ok) {
return new IceResponse(IceResponse::ERROR, "Error occurred while activating employee");
}
return new IceResponse(IceResponse::SUCCESS, $employee);
//$user = BaseService::getInstance()->getUserFromProfileId($employee->id);
}
public function deleteEmployee($req)
{
$employee = new Employee();
$employee->Load("id = ?", array($req->id));
if (empty($employee->id)) {
return new IceResponse(IceResponse::ERROR, "Employee Not Found");
}
$archived = new ArchivedEmployee();
$archived->ref_id = $employee->id;
$archived->employee_id = $employee->employee_id;
$archived->first_name = $employee->first_name;
$archived->last_name = $employee->last_name;
$archived->gender = $employee->gender;
$archived->ssn_num = $employee->ssn_num;
$archived->nic_num = $employee->nic_num;
$archived->other_id = $employee->other_id;
$archived->work_email = $employee->work_email;
$archived->joined_date = $employee->joined_date;
$archived->confirmation_date = $employee->confirmation_date;
$archived->supervisor = $employee->supervisor;
$archived->department = $employee->department;
$archived->termination_date = $employee->termination_date;
$archived->notes = $employee->notes;
$mapping = '{"nationality":["Nationality","id","name"],'
.'"employment_status":["EmploymentStatus","id","name"],"job_title":["JobTitle","id","name"],'
.'"pay_grade":["PayGrade","id","name"],"country":["Country","code","name"],'
.'"province":["Province","id","name"],"department":["CompanyStructure","id","title"],'
.'"supervisor":["Employee","id","first_name+last_name"]}';
$employeeEnriched = BaseService::getInstance()->getElement('Employee', $employee->id, $mapping, true);
$employeeEnriched = BaseService::getInstance()->cleanUpAdoDB($employeeEnriched);
$data = new \stdClass();
$data->enrichedEmployee = $employeeEnriched;
$data->timesheets = $this->getEmployeeData($employee->id, new EmployeeTimeSheet());
$data->timesheetEntries = $this->getEmployeeData($employee->id, new EmployeeTimeEntry());
$data->attendance = $this->getEmployeeData($employee->id, new Attendance());
$data->documents = $this->getEmployeeData($employee->id, new EmployeeDocument());
$data->travelRecords = $this->getEmployeeData($employee->id, new EmployeeTravelRecord());
$data->qualificationSkills = $this->getEmployeeData($employee->id, new EmployeeSkill());
$data->qualificationEducation = $this->getEmployeeData($employee->id, new EmployeeEducation());
$data->qualificationCertifications = $this->getEmployeeData($employee->id, new EmployeeCertification());
$data->qualificationLanguages = $this->getEmployeeData($employee->id, new EmployeeLanguage());
$data->salary = $this->getEmployeeData($employee->id, new EmployeeSalary());
$data->dependants = $this->getEmployeeData($employee->id, new EmployeeDependent());
$data->emergencyContacts = $this->getEmployeeData($employee->id, new EmergencyContact());
$data->projects = $this->getEmployeeData($employee->id, new EmployeeProject());
$archived->data = json_encode($data, JSON_PRETTY_PRINT);
$ok = $archived->Save();
if (!$ok) {
return new IceResponse(IceResponse::ERROR, "Error occurred while archiving employee");
}
$ok = $employee->Delete();
if (!$ok) {
return new IceResponse(IceResponse::ERROR, "Error occurred while deleting employee");
}
return new IceResponse(IceResponse::SUCCESS, $archived);
}
public function downloadArchivedEmployee($req)
{
if ($this->baseService->currentUser->user_level != 'Admin') {
echo "Error: Permission denied";
exit();
}
$employee = new ArchivedEmployee();
$employee->Load("id = ?", array($req->id));
if (empty($employee->id)) {
return new IceResponse(IceResponse::ERROR, "Employee Not Found");
}
$employee->data = json_decode($employee->data);
$employee = $this->baseService->cleanUpAdoDB($employee);
$str = json_encode($employee, JSON_PRETTY_PRINT);
$filename = uniqid();
$file = fopen("/tmp/".$filename, "w");
fwrite($file, $str);
fclose($file);
$downloadFileName = "employee_".$employee->id."_"
.str_replace(" ", "_", $employee->first_name)."_"
.str_replace(" ", "_", $employee->last_name).".txt";
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Type: image/jpg");
header('Content-Disposition: attachment; filename="'.$downloadFileName.'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("/tmp/".$filename));
readfile("/tmp/".$filename);
exit();
}
private function getEmployeeData($id, $obj)
{
$data = array();
$objs = $obj->Find("employee = ?", array($id));
foreach ($objs as $entry) {
$data[] = BaseService::getInstance()->cleanUpAdoDB($entry);
}
return $data;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Created by PhpStorm.
* User: Thilina
* Date: 8/19/17
* Time: 10:43 AM
*/
namespace Employees\Admin\Api;
use Classes\AbstractModuleManager;
use Classes\UIManager;
use Employees\Common\Model\Employee;
use Employees\Rest\EmployeeRestEndPoint;
class EmployeesAdminManager extends AbstractModuleManager
{
public function initializeUserClasses()
{
}
public function initializeFieldMappings()
{
}
public function setupRestEndPoints()
{
\Classes\Macaw::get(REST_API_PATH.'employees/me', function () {
$empRestEndPoint = new EmployeeRestEndPoint();
$empRestEndPoint->process('get', 'me');
});
\Classes\Macaw::get(REST_API_PATH.'employees/(:num)', function ($pathParams) {
$empRestEndPoint = new EmployeeRestEndPoint();
$empRestEndPoint->process('get', $pathParams);
});
\Classes\Macaw::get(REST_API_PATH.'employees', function () {
$empRestEndPoint = new EmployeeRestEndPoint();
$empRestEndPoint->process('listAll');
});
\Classes\Macaw::post(REST_API_PATH.'employees', function () {
$empRestEndPoint = new EmployeeRestEndPoint();
$empRestEndPoint->process('post');
});
\Classes\Macaw::put(REST_API_PATH.'employees/(:num)', function ($pathParams) {
$empRestEndPoint = new EmployeeRestEndPoint();
$empRestEndPoint->process('put', $pathParams);
});
\Classes\Macaw::delete(REST_API_PATH.'employees/(:num)', function ($pathParams) {
$empRestEndPoint = new EmployeeRestEndPoint();
$empRestEndPoint->process('delete', $pathParams);
});
}
public function initializeDatabaseErrorMappings()
{
$this->addDatabaseErrorMapping(
'CONSTRAINT `Fk_User_Employee` FOREIGN KEY',
"Can not delete Employee, please delete the User for this employee first."
);
$this->addDatabaseErrorMapping("Duplicate entry|for key 'employee'", "A duplicate entry found");
}
public function setupModuleClassDefinitions()
{
$this->addModelClass('Employee');
$this->addModelClass('EmploymentStatus');
$this->addModelClass('EmployeeApproval');
$this->addModelClass('ArchivedEmployee');
}
public function getDashboardItemData()
{
$data = array();
$emp = new Employee();
$data['numberOfEmployees'] = $emp->Count("1 = 1");
return $data;
}
public function initQuickAccessMenu()
{
UIManager::getInstance()->addQuickAccessMenuItem(
"View Employees",
"fa-users",
CLIENT_BASE_URL."?g=admin&n=employees&m=admin_Employees",
array("Admin","Manager")
);
UIManager::getInstance()->addQuickAccessMenuItem(
"Add a New Employee",
"fa-edit",
CLIENT_BASE_URL."?g=admin&n=employees&m=admin_Employees&action=new",
array("Admin")
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Employees\Common\Model;
use Model\BaseModel;
class ArchivedEmployee extends BaseModel
{
public function getAdminAccess()
{
return array("get","element","save","delete");
}
public function getManagerAccess()
{
return array("get","element","save");
}
public function getUserAccess()
{
return array("get");
}
public function getUserOnlyMeAccess()
{
return array("element","save");
}
public function getUserOnlyMeAccessField()
{
return "id";
}
public $table = 'ArchivedEmployees';
}

View File

@@ -0,0 +1,217 @@
<?php
namespace Employees\Common\Model;
use Classes\BaseService;
use Classes\FileService;
use Classes\IceResponse;
use Model\BaseModel;
class Employee extends BaseModel
{
public $oldObj = null;
public $oldObjOrig = null;
public $historyUpdateList = array();
public $historyFieldsToTrack = array(
"employee_id"=>"employee_id",
"first_name"=>"first_name",
"middle_name"=>"middle_name",
"last_name"=>"last_name",
"nationality"=>"nationality_Name",
"birthday"=>"birthday",
"gender"=>"gender",
"marital_status"=>"marital_status",
"ssn_num"=>"ssn_num",
"nic_num"=>"nic_num",
"other_id"=>"other_id",
"employment_status"=>"employment_status_Name",
"job_title"=>"job_title_Name",
"pay_grade"=>"pay_grade_Name",
"work_station_id"=>"work_station_id",
"address1"=>"address1",
"address2"=>"address2",
"city"=>"city_Name",
"country"=>"country_Name",
"province"=>"province_Name",
"postal_code"=>"postal_code",
"home_phone"=>"home_phone",
"mobile_phone"=>"mobile_phone",
"work_phone"=>"work_phone",
"work_email"=>"work_email",
"private_email"=>"private_email",
"joined_date"=>"joined_date",
"confirmation_date"=>"confirmation_date",
"supervisor"=>"supervisor_Name",
"indirect_supervisors"=>"indirect_supervisors",
"department"=>"department_Name"
);
public function getAdminAccess()
{
return array("get","element","save","delete");
}
public function getManagerAccess()
{
return array("get","element","save");
}
public function getUserAccess()
{
return array("get");
}
public function getUserOnlyMeAccess()
{
return array("element","save");
}
public function getUserOnlyMeAccessField()
{
return "id";
}
private function initHistory($obj)
{
$oldObjOrig = new Employee();
$oldObjOrig->Load("id = ?", array($obj->id));
$this->oldObjOrig = $oldObjOrig;
$mapping = '{"nationality":["Nationality","id","name"],'
.'"employment_status":["EmploymentStatus","id","name"],"job_title":["JobTitle","id","name"],'
.'"pay_grade":["PayGrade","id","name"],"country":["Country","code","name"],'
.'"province":["Province","id","name"],"department":["CompanyStructure","id","title"],'
.'"supervisor":["Employee","id","first_name+last_name"]}';
$this->oldObj = BaseService::getInstance()->getElement('Employee', $obj->id, $mapping, true);
}
private function saveHistory($obj)
{
$oldObj = $this->oldObj;
$oldObjOrig = $this->oldObjOrig;
$mapping = '{"nationality":["Nationality","id","name"],'
.'"employment_status":["EmploymentStatus","id","name"],"job_title":["JobTitle","id","name"],'
.'"pay_grade":["PayGrade","id","name"],"country":["Country","code","name"],'
.'"province":["Province","id","name"],"department":["CompanyStructure","id","title"],'
.'"supervisor":["Employee","id","first_name+last_name"]}';
$objEnriched = BaseService::getInstance()->getElement('Employee', $obj->id, $mapping, true);
foreach ($this->historyFieldsToTrack as $k => $v) {
if (empty($oldObjOrig->$k) && $obj->$k = '[]') {
continue;
}
if (empty($obj->$k) && $oldObjOrig->$k == '0000-00-00') {
continue;
}
if ($oldObjOrig->$k != $obj->$k) {
$enrichNewVal = '';
$enrichOldVal = '';
if ($k == 'indirect_supervisors') {
if (!empty($obj->$k) && $obj->$k != '[]') {
$newIndeirectSupervisorIds = json_decode($obj->$k);
foreach ($newIndeirectSupervisorIds as $id) {
$item = BaseService::getInstance()->getItemFromCache("Employee", $id);
if ($enrichNewVal != "") {
$enrichNewVal .= ", ";
}
$enrichNewVal .= $item->first_name." ".$item->last_name;
}
}
if (!empty($oldObjOrig->$k) && $oldObjOrig->$k != '[]') {
$oldIndeirectSupervisorIds = json_decode($oldObjOrig->$k);
foreach ($oldIndeirectSupervisorIds as $id) {
$item = BaseService::getInstance()->getItemFromCache("Employee", $id);
if ($enrichOldVal != "") {
$enrichOldVal .= ", ";
}
$enrichOldVal .= $item->first_name." ".$item->last_name;
}
}
} else {
$enrichOldVal = $oldObj->$v;
$enrichNewVal = $objEnriched->$v;
}
$this->historyUpdateList[] = array($obj->id,$k,$enrichOldVal,$enrichNewVal);
}
}
while (count($this->historyUpdateList)) {
$ele = array_pop($this->historyUpdateList);
BaseService::getInstance()->addHistoryItem("Employee", "Employee", $ele[0], $ele[1], $ele[2], $ele[3]);
}
}
public function executePreSaveActions($obj)
{
if (empty($obj->status)) {
$obj->status = 'Active';
}
return new IceResponse(IceResponse::SUCCESS, $obj);
}
public function executePreUpdateActions($obj)
{
$this->initHistory($obj);
return new IceResponse(IceResponse::SUCCESS, $obj);
}
public function executePostUpdateActions($obj)
{
$this->saveHistory($obj);
}
public function postProcessGetData($obj)
{
$obj = FileService::getInstance()->updateSmallProfileImage($obj);
return $obj;
}
public function getVirtualFields()
{
return array(
"image"
);
}
public function getActiveEmployees()
{
$employee = new Employee();
$list = $employee->Find("status = ?", array('Active'));
return $list;
}
public function getActiveSubordinateEmployees()
{
$employee = new Employee();
if (BaseService::getInstance()->currentUser->user_level != 'Admin') {
$cemp = BaseService::getInstance()->getCurrentProfileId();
$list = $employee->Find("status = ? and supervisor = ?", array('Active', $cemp));
} else {
$list = $employee->Find("status = ?", array('Active'));
}
return $list;
}
public static function cleanEmployeeData($obj)
{
unset($obj->keysToIgnore);
unset($obj->historyFieldsToTrack);
unset($obj->historyUpdateList);
unset($obj->oldObjOrig);
unset($obj->oldObj);
return $obj;
}
public $table = 'Employees';
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: Thilina
* Date: 8/19/17
* Time: 10:41 AM
*/
namespace Employees\Common\Model;
use Model\BaseModel;
class EmployeeApproval extends BaseModel
{
public $table = 'EmployeeApprovals';
public function getAdminAccess()
{
return array("get","element","save","delete");
}
public function getManagerAccess()
{
return array("get","element","save");
}
public function getUserAccess()
{
return array();
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Created by PhpStorm.
* User: Thilina
* Date: 8/19/17
* Time: 10:40 AM
*/
namespace Employees\Common\Model;
use Model\BaseModel;
class EmploymentStatus extends BaseModel
{
public $table = 'EmploymentStatus';
public function getAdminAccess()
{
return array("get","element","save","delete");
}
public function getManagerAccess()
{
return array("get","element","save");
}
public function getUserAccess()
{
return array();
}
}

View File

@@ -0,0 +1,140 @@
<?php
namespace Employees\Rest;
use Classes\BaseService;
use Classes\Data\Query\DataQuery;
use Classes\IceResponse;
use Classes\PermissionManager;
use Classes\RestEndPoint;
use Employees\Common\Model\Employee;
use Users\Common\Model\User;
class EmployeeRestEndPoint extends RestEndPoint
{
const ELEMENT_NAME = 'Employee';
public function getModelObject($id)
{
$obj = new Employee();
$obj->Load("id = ?", array($id));
return $obj;
}
public function listAll(User $user)
{
$query = new DataQuery('Employee');
$limit = self::DEFAULT_LIMIT;
if (isset($_GET['limit']) && intval($_GET['limit']) > 0) {
$limit = intval($_GET['limit']);
}
$query->setLength($limit);
if ($user->user_level !== 'Admin') {
$query->setIsSubOrdinates(true);
}
return $this->listByQuery($query);
}
public function get(User $user, $parameter)
{
if (empty($parameter)) {
return new IceResponse(IceResponse::ERROR, "Employee not found", 404);
}
if ($parameter === 'me') {
$parameter = BaseService::getInstance()->getCurrentProfileId();
}
if ($user->user_level !== 'Admin' && !PermissionManager::manipulationAllowed(
BaseService::getInstance()->getCurrentProfileId(),
$this->getModelObject($parameter)
)
) {
return new IceResponse(IceResponse::ERROR, "Permission denied", 403);
}
$mapping = [
"nationality" => ["Nationality","id","name"],
"ethnicity" => ["Ethnicity","id","name"],
"immigration_status" => ["ImmigrationStatus","id","name"],
"employment_status" => ["EmploymentStatus","id","name"],
"job_title" => ["JobTitle","id","name"],
"pay_grade" => ["PayGrade","id","name"],
"country" => ["Country","code","name"],
"province" => ["Province","id","name"],
"department" => ["CompanyStructure","id","title"],
"supervisor" => [self::ELEMENT_NAME,"id","first_name+last_name"],
];
$emp = BaseService::getInstance()->getElement(
self::ELEMENT_NAME,
$parameter,
json_encode($mapping),
true
);
$emp = $this->enrichElement($emp, $mapping);
if (!empty($emp)) {
$emp = $this->cleanObject($emp);
$emp = $this->removeNullFields($emp);
return new IceResponse(IceResponse::SUCCESS, $emp);
}
return new IceResponse(IceResponse::ERROR, "Employee not found", 404);
}
public function post(User $user)
{
if ($user->user_level !== 'Admin') {
return new IceResponse(IceResponse::ERROR, "Permission denied", 403);
}
$body = $this->getRequestBody();
$response = BaseService::getInstance()->addElement(self::ELEMENT_NAME, $body);
if ($response->getStatus() === IceResponse::SUCCESS) {
$response = $this->get($user, $response->getData()->id);
$response->setCode(201);
return $response;
}
return new IceResponse(IceResponse::ERROR, $response->getData(), 400);
}
public function put(User $user, $parameter)
{
if ($user->user_level !== 'Admin' &&
!PermissionManager::manipulationAllowed(
BaseService::getInstance()->getCurrentProfileId(),
$this->getModelObject($parameter)
)
) {
return new IceResponse(IceResponse::ERROR, "Permission denied", 403);
}
$body = $this->getRequestBody();
$body['id'] = $parameter;
$response = BaseService::getInstance()->addElement(self::ELEMENT_NAME, $body);
if ($response->getStatus() === IceResponse::SUCCESS) {
return $this->get($user, $response->getData()->id);
}
return new IceResponse(IceResponse::ERROR, 'Error modifying employee', 400);
}
public function delete(User $user, $parameter)
{
if ($user->user_level !== 'Admin') {
return new IceResponse(IceResponse::ERROR, "Permission denied", 403);
}
$response = BaseService::getInstance()->deleteElement(
self::ELEMENT_NAME,
$parameter
);
if ($response->getStatus() === IceResponse::SUCCESS) {
return new IceResponse(IceResponse::SUCCESS, ['id' => $parameter], 200);
}
return new IceResponse(IceResponse::ERROR, $response->getData(), 400);
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* Created by PhpStorm.
* User: Thilina
* Date: 8/19/17
* Time: 10:52 AM
*/
namespace Employees\User\Api;
use Classes\BaseService;
use Classes\FileService;
use Classes\IceResponse;
use Classes\SettingsManager;
use Classes\SubActionManager;
use Company\Common\Model\CompanyStructure;
use Employees\Common\Model\Employee;
use Users\Common\Model\User;
class EmployeesActionManager extends SubActionManager
{
public function get($req)
{
$profileId = $this->getCurrentProfileId();
$cemp = $profileId;
$obj = new Employee();
$cempObj = new Employee();
$cempObj->Load("id = ?", array($cemp));
if ($obj->getUserOnlyMeAccessField() == 'id' &&
SettingsManager::getInstance()->getSetting('System: Company Structure Managers Enabled') == 1 &&
CompanyStructure::isHeadOfCompanyStructure($cempObj->department, $cemp)) {
$subordinates = $obj->Find("supervisor = ?", array($cemp));
if (empty($subordinates)) {
$subordinates = array();
}
$childCompaniesIds = array();
if (SettingsManager::getInstance()->getSetting('System: Child Company Structure Managers Enabled') == '1') {
$childCompaniesResp = CompanyStructure::getAllChildCompanyStructures($cempObj->department);
$childCompanies = $childCompaniesResp->getObject();
foreach ($childCompanies as $cc) {
$childCompaniesIds[] = $cc->id;
}
} else {
$childCompaniesIds[] = $cempObj->department;
}
if (!empty($childCompaniesIds)) {
$childStructureSubordinates
= $obj->Find(
"department in (" . implode(',', $childCompaniesIds) . ") and id != ?",
array($cemp)
);
$subordinates = array_merge($subordinates, $childStructureSubordinates);
}
foreach ($subordinates as $subordinate) {
if ($subordinate->id == $req->id) {
$id = $req->id;
break;
}
}
} else {
$subordinate = new Employee();
$subordinatesCount = $subordinate->Count("supervisor = ? and id = ?", array($profileId, $req->id));
if ($this->user->user_level == 'Admin' || $subordinatesCount > 0) {
$id = $req->id;
}
}
if (empty($id)) {
$id = $profileId;
}
$employee = $this->baseService->getElement('Employee', $id, $req->map, true);
$subordinate = new Employee();
$subordinates = $subordinate->Find("supervisor = ?", array($employee->id));
$employee->subordinates = $subordinates;
$fs = FileService::getInstance();
$employee = $fs->updateProfileImage($employee);
if (!empty($employee->birthday)) {
$employee->birthday = date("F jS, Y", strtotime($employee->birthday));
}
if (!empty($employee->driving_license_exp_date)) {
$employee->driving_license_exp_date = date("F jS, Y", strtotime($employee->driving_license_exp_date));
}
if (!empty($employee->joined_date)) {
$employee->joined_date = date("F jS, Y", strtotime($employee->joined_date));
}
//Read custom fields
try {
$employee = BaseService::getInstance()->customFieldManager->enrichObjectCustomFields('Employee', $employee);
} catch (\Exception $e) {
}
if (empty($employee->id)) {
return new IceResponse(IceResponse::ERROR, $employee);
}
return new IceResponse(
IceResponse::SUCCESS,
array($employee,$this->getCurrentProfileId(),$this->user->employee)
);
}
public function deleteProfileImage($req)
{
$profileId = $this->getCurrentProfileId();
$subordinate = new Employee();
$subordinatesCount = $subordinate->Count("supervisor = ? and id = ?", array($profileId, $req->id));
if ($this->user->user_level == 'Admin' || $this->user->employee == $req->id || $subordinatesCount == 1) {
$fs = FileService::getInstance();
$res = $fs->deleteProfileImage($req->id);
return new IceResponse(IceResponse::SUCCESS, $res);
}
return new IceResponse(IceResponse::ERROR, "Not allowed to delete profile image");
}
public function changePassword($req)
{
if ($this->getCurrentProfileId() != $this->user->employee || empty($this->user->employee)) {
return new IceResponse(IceResponse::ERROR, "You are not allowed to change passwords of other employees");
}
$user = new User();
$user->Load("id = ?", array($this->user->id));
if (empty($user->id)) {
return new IceResponse(IceResponse::ERROR, "Error occurred while changing password");
}
$user->password = md5($req->pwd);
$ok = $user->Save();
if (!$ok) {
return new IceResponse(IceResponse::ERROR, $user->ErrorMsg());
}
return new IceResponse(IceResponse::SUCCESS, $user);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: Thilina
* Date: 8/19/17
* Time: 10:45 AM
*/
namespace Employees\User\Api;
use Classes\AbstractModuleManager;
class EmployeesModulesManager extends AbstractModuleManager
{
public function initializeUserClasses()
{
}
public function initializeFieldMappings()
{
}
public function initializeDatabaseErrorMappings()
{
}
public function setupModuleClassDefinitions()
{
}
}