Refactor project structure
This commit is contained in:
211
core/src/Model/ApproveModel.php
Normal file
211
core/src/Model/ApproveModel.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
namespace Model;
|
||||
|
||||
use Classes\Approval\ApprovalStatus;
|
||||
use Classes\BaseService;
|
||||
use Classes\IceResponse;
|
||||
use Classes\SettingsManager;
|
||||
use Employees\Common\Model\EmployeeApproval;
|
||||
use Travel\Common\Model\EmployeeTravelRecord;
|
||||
|
||||
abstract class ApproveModel extends BaseModel
|
||||
{
|
||||
|
||||
public function isMultiLevelApprovalsEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function executePreSaveActions($obj)
|
||||
{
|
||||
$preApprove = SettingsManager::getInstance()->getSetting($this->preApproveSettingName);
|
||||
$sendNotificationEmail = true;
|
||||
if (empty($obj->status)) {
|
||||
if ($preApprove == "1") {
|
||||
$obj->status = "Approved";
|
||||
$sendNotificationEmail = false;
|
||||
} else {
|
||||
$obj->status = "Pending";
|
||||
}
|
||||
}
|
||||
|
||||
if ($preApprove) {
|
||||
return new IceResponse(IceResponse::SUCCESS, $obj);
|
||||
}
|
||||
|
||||
$currentEmpId = BaseService::getInstance()->getCurrentProfileId();
|
||||
|
||||
//Auto approve if the current user is an admin
|
||||
|
||||
if (!empty($currentEmpId)) {
|
||||
$employee = BaseService::getInstance()->getElement('Employee', $currentEmpId);
|
||||
|
||||
if (!empty($employee->supervisor)) {
|
||||
$notificationMsg = "A new "
|
||||
.$this->notificationUnitName." has been added by "
|
||||
. $employee->first_name . " " . $employee->last_name
|
||||
. ". Please visit ".$this->notificationModuleName." module to review it";
|
||||
|
||||
BaseService::getInstance()->notificationManager->addNotification(
|
||||
$employee->supervisor,
|
||||
$notificationMsg,
|
||||
'{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}',
|
||||
$this->notificationModuleName,
|
||||
null,
|
||||
false,
|
||||
$sendNotificationEmail
|
||||
);
|
||||
} else {
|
||||
$user = BaseService::getInstance()->getCurrentUser();
|
||||
|
||||
if ($user->user_level == "Admin") {
|
||||
//Auto approve
|
||||
$obj->status = "Approved";
|
||||
$notificationMsg = "Your ".$this->notificationUnitName
|
||||
." is auto approved since you are an administrator and do not have any supervisor assigned";
|
||||
BaseService::getInstance()->notificationManager->addNotification(
|
||||
null,
|
||||
$notificationMsg,
|
||||
'{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}',
|
||||
$this->notificationModuleName,
|
||||
$user->id,
|
||||
false,
|
||||
$sendNotificationEmail
|
||||
);
|
||||
} else {
|
||||
//If the user do not have a supervisor, notify all admins
|
||||
$admins = BaseService::getInstance()->getAllAdmins();
|
||||
foreach ($admins as $admin) {
|
||||
$notificationMsg = "A new ".$this->notificationUnitName." has been added by "
|
||||
.$employee->first_name . " " . $employee->last_name . ". Please visit "
|
||||
.$this->notificationModuleName
|
||||
." module to review it. You are getting this notification since you are an "
|
||||
."administrator and the user do not have any supervisor assigned.";
|
||||
BaseService::getInstance()->notificationManager->addNotification(
|
||||
null,
|
||||
$notificationMsg,
|
||||
'{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}',
|
||||
$this->notificationModuleName,
|
||||
$admin->id,
|
||||
false,
|
||||
$sendNotificationEmail
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new IceResponse(IceResponse::SUCCESS, $obj);
|
||||
}
|
||||
|
||||
public function executePreUpdateActions($obj)
|
||||
{
|
||||
|
||||
$preApprove = SettingsManager::getInstance()->getSetting($this->preApproveSettingName);
|
||||
$sendNotificationEmail = true;
|
||||
|
||||
$fieldsToCheck = $this->fieldsNeedToBeApproved();
|
||||
|
||||
$travelRequest = new EmployeeTravelRecord();
|
||||
$travelRequest->Load('id = ?', array($obj->id));
|
||||
|
||||
$needToApprove = false;
|
||||
if ($preApprove != "1") {
|
||||
foreach ($fieldsToCheck as $field) {
|
||||
if ($obj->$field != $travelRequest->$field) {
|
||||
$needToApprove = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sendNotificationEmail = false;
|
||||
}
|
||||
|
||||
if ($preApprove) {
|
||||
return new IceResponse(IceResponse::SUCCESS, $obj);
|
||||
}
|
||||
|
||||
if ($needToApprove && $obj->status != 'Pending') {
|
||||
$currentEmpId = BaseService::getInstance()->getCurrentProfileId();
|
||||
|
||||
//Auto approve if the current user is an admin
|
||||
|
||||
if (!empty($currentEmpId)) {
|
||||
$employee = BaseService::getInstance()->getElement('Employee', $currentEmpId);
|
||||
|
||||
if (!empty($employee->supervisor)) {
|
||||
$notificationMsg = $this->notificationUnitPrefix." "
|
||||
.$this->notificationUnitName." has been updated by "
|
||||
.$employee->first_name . " " . $employee->last_name
|
||||
.". Please visit ".$this->notificationModuleName." module to review it";
|
||||
|
||||
BaseService::getInstance()->notificationManager->addNotification(
|
||||
$employee->supervisor,
|
||||
$notificationMsg,
|
||||
'{"type":"url","url":"'.$this->notificationUnitAdminUrl.'"}',
|
||||
$this->notificationModuleName,
|
||||
null,
|
||||
false,
|
||||
$sendNotificationEmail
|
||||
);
|
||||
} else {
|
||||
$user = BaseService::getInstance()->getCurrentUser();
|
||||
|
||||
if ($user->user_level == "Admin") {
|
||||
} else {
|
||||
//If the user do not have a supervisor, notify all admins
|
||||
$admins = BaseService::getInstance()->getAllAdmins();
|
||||
foreach ($admins as $admin) {
|
||||
$notificationMsg = $this->notificationUnitPrefix." "
|
||||
.$this->notificationUnitName." request has been updated by "
|
||||
.$employee->first_name . " " . $employee->last_name
|
||||
.". Please visit ".$this->notificationModuleName
|
||||
." module to review it. You are getting this notification since you are "
|
||||
."an administrator and the user do not have any supervisor assigned.";
|
||||
BaseService::getInstance()->notificationManager->addNotification(
|
||||
null,
|
||||
$notificationMsg,
|
||||
'{"type":"url","url":"g=admin&n=travel&m=admin_Employees"}',
|
||||
"Travel Module",
|
||||
$admin->id,
|
||||
false,
|
||||
$sendNotificationEmail
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new IceResponse(IceResponse::SUCCESS, $obj);
|
||||
}
|
||||
|
||||
public function executePostSaveActions($obj)
|
||||
{
|
||||
$directAppr = ApprovalStatus::getInstance()->isDirectApproval($obj->employee);
|
||||
|
||||
if (!$directAppr && $this->isMultiLevelApprovalsEnabled()) {
|
||||
$classPaths = explode("\\", get_called_class());
|
||||
ApprovalStatus::getInstance()->initializeApprovalChain($classPaths[count($classPaths) - 1], $obj->id);
|
||||
}
|
||||
}
|
||||
|
||||
abstract public function getType();
|
||||
|
||||
public function findApprovals($obj, $whereOrderBy, $bindarr = false, $pkeysArr = false, $extra = array())
|
||||
{
|
||||
$currentEmployee = BaseService::getInstance()->getCurrentProfileId();
|
||||
$approveal = new EmployeeApproval();
|
||||
$approveals = $approveal->Find(
|
||||
"type = ? and approver = ? and status = -1 and active = 1",
|
||||
array($this->getType(), $currentEmployee)
|
||||
);
|
||||
$ids = array();
|
||||
foreach ($approveals as $appr) {
|
||||
$ids[] = $appr->element;
|
||||
}
|
||||
$data = $obj->Find("id in (".implode(",", $ids).")", array());
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
14
core/src/Model/Audit.php
Normal file
14
core/src/Model/Audit.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:35 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Audit extends BaseModel
|
||||
{
|
||||
public $table = 'AuditLog';
|
||||
}
|
||||
167
core/src/Model/BaseModel.php
Normal file
167
core/src/Model/BaseModel.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
namespace Model;
|
||||
|
||||
use Classes\IceResponse;
|
||||
|
||||
class BaseModel extends \ADOdb_Active_Record
|
||||
{
|
||||
|
||||
public $keysToIgnore = array(
|
||||
"_table",
|
||||
"_dbat",
|
||||
"_tableat",
|
||||
"_where",
|
||||
"_saved",
|
||||
"_lasterr",
|
||||
"_original",
|
||||
"foreignName",
|
||||
"a",
|
||||
"t"
|
||||
);
|
||||
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getOtherAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getManagerAccess()
|
||||
{
|
||||
return array("get","element");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array("get","element");
|
||||
}
|
||||
|
||||
public function getEmployeeAccess()
|
||||
{
|
||||
return $this->getUserAccess();
|
||||
}
|
||||
|
||||
public function getAnonymousAccess()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getUserOnlyMeAccess()
|
||||
{
|
||||
return array("get","element");
|
||||
}
|
||||
|
||||
public function getUserOnlyMeAccessField()
|
||||
{
|
||||
return "employee";
|
||||
}
|
||||
|
||||
public function getUserOnlyMeAccessRequestField()
|
||||
{
|
||||
return "employee";
|
||||
}
|
||||
|
||||
public function validateSave($obj)
|
||||
{
|
||||
return new IceResponse(IceResponse::SUCCESS, "");
|
||||
}
|
||||
|
||||
public function executePreSaveActions($obj)
|
||||
{
|
||||
return new IceResponse(IceResponse::SUCCESS, $obj);
|
||||
}
|
||||
|
||||
public function executePreUpdateActions($obj)
|
||||
{
|
||||
return new IceResponse(IceResponse::SUCCESS, $obj);
|
||||
}
|
||||
|
||||
public function executePreDeleteActions($obj)
|
||||
{
|
||||
return new IceResponse(IceResponse::SUCCESS, null);
|
||||
}
|
||||
|
||||
public function executePostSaveActions($obj)
|
||||
{
|
||||
}
|
||||
|
||||
public function executePostUpdateActions($obj)
|
||||
{
|
||||
}
|
||||
|
||||
public function postProcessGetData($obj)
|
||||
{
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function postProcessGetElement($obj)
|
||||
{
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getDefaultAccessLevel()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getVirtualFields()
|
||||
{
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
public function allowIndirectMapping()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDisplayName()
|
||||
{
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
public function getObjectKeys()
|
||||
{
|
||||
$keys = array();
|
||||
|
||||
foreach ($this as $k => $v) {
|
||||
if (in_array($k, $this->keysToIgnore)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($v) || is_object($v)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$keys[$k] = $k;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
public function getCustomFields($obj)
|
||||
{
|
||||
$keys = array();
|
||||
$objKeys = $this->getObjectKeys();
|
||||
foreach ($obj as $k => $v) {
|
||||
if (isset($objKeys[$k])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($v) || is_object($v)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($k, $this->keysToIgnore)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$keys[$k] = $v;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
14
core/src/Model/Cron.php
Normal file
14
core/src/Model/Cron.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:36 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Cron extends BaseModel
|
||||
{
|
||||
public $table = 'Crons';
|
||||
}
|
||||
14
core/src/Model/DataEntryBackup.php
Normal file
14
core/src/Model/DataEntryBackup.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:35 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class DataEntryBackup extends BaseModel
|
||||
{
|
||||
public $table = 'DataEntryBackups';
|
||||
}
|
||||
28
core/src/Model/File.php
Normal file
28
core/src/Model/File.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:32 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class File extends BaseModel
|
||||
{
|
||||
public $table = 'Files';
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getAnonymousAccess()
|
||||
{
|
||||
return array("save");
|
||||
}
|
||||
}
|
||||
14
core/src/Model/IceEmail.php
Normal file
14
core/src/Model/IceEmail.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:37 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class IceEmail extends BaseModel
|
||||
{
|
||||
public $table = 'Emails';
|
||||
}
|
||||
14
core/src/Model/Migration.php
Normal file
14
core/src/Model/Migration.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:38 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Migration extends BaseModel
|
||||
{
|
||||
public $table = 'Migrations';
|
||||
}
|
||||
14
core/src/Model/Notification.php
Normal file
14
core/src/Model/Notification.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:35 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Notification extends BaseModel
|
||||
{
|
||||
public $table = 'Notifications';
|
||||
}
|
||||
51
core/src/Model/Report.php
Normal file
51
core/src/Model/Report.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:34 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class Report extends BaseModel
|
||||
{
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getManagerAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function postProcessGetData($entry)
|
||||
{
|
||||
$entry->icon = '<img src="'.BASE_URL.'images/file-icons/'.strtolower($entry->output).".png".'"/>';
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public function getCustomFilterQuery($filter)
|
||||
{
|
||||
$filter = json_decode($filter, true);
|
||||
if ($filter['type'] === 'Reports') {
|
||||
$query = ' and report_group <> ?';
|
||||
} elseif ($filter['type'] === 'Exports') {
|
||||
$query = ' and report_group = ?';
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
$queryData = array('Payroll');
|
||||
|
||||
return array($query, $queryData);
|
||||
}
|
||||
|
||||
public $table = 'Reports';
|
||||
}
|
||||
41
core/src/Model/ReportFile.php
Normal file
41
core/src/Model/ReportFile.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:34 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class ReportFile extends BaseModel
|
||||
{
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getManagerAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserOnlyMeAccess()
|
||||
{
|
||||
return array("get","element","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array("get","element");
|
||||
}
|
||||
|
||||
public function postProcessGetData($entry)
|
||||
{
|
||||
$data = explode(".", $entry->name);
|
||||
$entry->icon = '<img src="'.BASE_URL.'images/file-icons/'.strtolower($data[count($data)-1]).".png".'"/>';
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public $table = 'ReportFiles';
|
||||
}
|
||||
14
core/src/Model/RestAccessToken.php
Normal file
14
core/src/Model/RestAccessToken.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:36 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class RestAccessToken extends BaseModel
|
||||
{
|
||||
public $table = 'RestAccessTokens';
|
||||
}
|
||||
40
core/src/Model/Setting.php
Normal file
40
core/src/Model/Setting.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:33 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
use Classes\BaseService;
|
||||
use Classes\RestApiManager;
|
||||
use Users\Common\Model\User;
|
||||
|
||||
class Setting extends BaseModel
|
||||
{
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function postProcessGetElement($obj)
|
||||
{
|
||||
if ($obj->name == 'Api: REST Api Token') {
|
||||
$user = BaseService::getInstance()->getCurrentUser();
|
||||
$dbUser = new User();
|
||||
$dbUser->Load("id = ?", array($user->id));
|
||||
$resp = RestApiManager::getInstance()->getAccessTokenForUser($dbUser);
|
||||
$obj->value = $resp->getData();
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public $table = 'Settings';
|
||||
}
|
||||
14
core/src/Model/StatusChangeLog.php
Normal file
14
core/src/Model/StatusChangeLog.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:37 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class StatusChangeLog extends BaseModel
|
||||
{
|
||||
public $table = 'StatusChangeLogs';
|
||||
}
|
||||
35
core/src/Model/UserReport.php
Normal file
35
core/src/Model/UserReport.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Thilina
|
||||
* Date: 8/21/17
|
||||
* Time: 2:34 AM
|
||||
*/
|
||||
|
||||
namespace Model;
|
||||
|
||||
class UserReport extends BaseModel
|
||||
{
|
||||
public function getAdminAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getManagerAccess()
|
||||
{
|
||||
return array("get","element","save","delete");
|
||||
}
|
||||
|
||||
public function getUserAccess()
|
||||
{
|
||||
return array("get","element");
|
||||
}
|
||||
|
||||
public function postProcessGetData($entry)
|
||||
{
|
||||
$entry->icon = '<img src="'.BASE_URL.'images/file-icons/'.strtolower($entry->output).".png".'"/>';
|
||||
return $entry;
|
||||
}
|
||||
|
||||
public $table = 'UserReports';
|
||||
}
|
||||
Reference in New Issue
Block a user