Exemplo n.º 1
0
 /**
  * Get User role manager instance
  * @return AbstractUserRoleManager
  */
 public function getUserRoleManager()
 {
     if (!$this->userRoleManager instanceof AbstractUserRoleManager) {
         $this->userRoleManager = UserRoleManagerFactory::getUserRoleManager();
     }
     return $this->userRoleManager;
 }
 /**
  * Get array of operational country and location choices
  */
 public function getChoices()
 {
     if (is_null($this->choices)) {
         $operationalCountries = $this->getOperationalCountryService()->getOperationalCountryList();
         $manager = UserRoleManagerFactory::getUserRoleManager();
         $accessibleCountryIds = $manager->getAccessibleEntityIds('OperationalCountry');
         $user = sfContext::getInstance()->getUser();
         // Special case for supervisor - can see all operational countries
         $showAll = false;
         if ($user->getAttribute('auth.isSupervisor')) {
             $showAll = true;
         }
         $choices = array();
         foreach ($operationalCountries as $operationalCountry) {
             $countryId = $operationalCountry->getId();
             if ($showAll || in_array($countryId, $accessibleCountryIds)) {
                 $country = $operationalCountry->getCountry();
                 $locations = $country->getLocation();
                 if (count($locations) > 0) {
                     $locationChoices = array();
                     foreach ($locations as $location) {
                         $locationChoices[$location->getId()] = $location->getName();
                     }
                     asort($locationChoices);
                     $choices[$country->getCouName()] = $locationChoices;
                 }
             }
         }
         $this->choices = $choices;
     }
     return $this->choices;
 }
Exemplo n.º 3
0
 public function getUserRoleManager()
 {
     if (is_null($this->userRoleManager)) {
         $this->userRoleManager = UserRoleManagerFactory::getUserRoleManager();
     }
     return $this->userRoleManager;
 }
 /**
  * Index action. Displays employee list
  *      `
  * @param sfWebRequest $request
  */
 public function execute($request)
 {
     if ($this->getUser()->hasFlash('templateMessage')) {
         list($this->messageType, $this->message) = $this->getUser()->getFlash('templateMessage');
     }
     $empNumber = $request->getParameter('empNumber');
     $isPaging = $request->getParameter('hdnAction') == 'search' ? 1 : $request->getParameter('pageNo', 1);
     $pageNumber = $isPaging;
     if (!empty($empNumber) && $this->getUser()->hasAttribute('pageNumber')) {
         $pageNumber = $this->getUser()->getAttribute('pageNumber');
     }
     $sortField = $request->getParameter('sortField');
     $sortOrder = $request->getParameter('sortOrder');
     $noOfRecords = sfConfig::get('app_items_per_page');
     $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $noOfRecords : ($request->getParameter('pageNo', 1) - 1) * $noOfRecords;
     // Reset filters if requested to
     if ($request->hasParameter('reset')) {
         $this->setFilters(array());
         $this->setPage(1);
     }
     $this->form = new EmployeeSearchForm($this->getFilters());
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $this->setFilters($this->form->getValues());
         } else {
             $this->setFilters(array());
         }
         $this->setPage(1);
     }
     $filters = $this->getFilters();
     if (isset($filters['employee_name'])) {
         $filters['employee_name'] = str_replace(' (' . __('Past Employee') . ')', '', $filters['employee_name']['empName']);
     }
     $this->filterApply = !empty($filters);
     $accessibleEmployees = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Employee');
     if (count($accessibleEmployees) > 0) {
         $filters['employee_id_list'] = $accessibleEmployees;
         $count = $this->getEmployeeService()->getSearchEmployeeCount($filters);
         $list = $this->getEmployeeService()->searchEmployeeList($sortField, $sortOrder, $filters, $offset, $noOfRecords);
         //$table = Doctrine::getTable('Employee');
         //$count = $table->getEmployeeCount($filters);
         //$list = $table->getEmployeeList($sortField, $sortOrder, $filters, $offset, $noOfRecords);
     } else {
         $count = 0;
         $list = array();
     }
     $this->setListComponent($list, $count, $noOfRecords, $pageNumber);
     // Show message if list is empty, and we don't already have a message.
     if (empty($this->message) && count($list) == 0) {
         // Check to see if we have any employees in system
         $employeeCount = $this->getEmployeeService()->getEmployeeCount();
         $this->messageType = "warning";
         if (empty($employeeCount)) {
             $this->message = __("No Employees Available");
         } else {
             $this->message = __(TopLevelMessages::NO_RECORDS_FOUND);
         }
     }
 }
 public static function getUserRoleManager()
 {
     if (empty(self::$userRoleManager)) {
         $userRoleManagerService = new UserRoleManagerService();
         self::$userRoleManager = $userRoleManagerService->getUserRoleManager();
     }
     return self::$userRoleManager;
 }
Exemplo n.º 6
0
 public function addLogin($form = null)
 {
     $user = UserRoleManagerFactory::getUserRoleManager()->getUser();
     $login = new Login();
     $login->setUserId($user->getId());
     $login->setUserName($user->getName());
     $login->setUserRoleName($user->getUserRole()->getName());
     $login->setUserRolePredefined($user->getUserRole()->getIsPredefined());
     $login->save();
 }
 /**
  *
  * @param <type> $request
  */
 public function execute($request)
 {
     $isPaging = $request->getParameter('pageNo');
     $sortField = $request->getParameter('sortField');
     $sortOrder = $request->getParameter('sortOrder');
     $userId = $request->getParameter('userId');
     $this->setForm(new SearchSystemUserForm());
     $pageNumber = $isPaging;
     if ($userId > 0 && $this->getUser()->hasAttribute('pageNumber')) {
         $pageNumber = $this->getUser()->getAttribute('pageNumber');
     }
     $limit = SystemUser::NO_OF_RECORDS_PER_PAGE;
     $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $limit : ($request->getParameter('pageNo', 1) - 1) * $limit;
     $searchClues = $this->_setSearchClues($sortField, $sortOrder, $offset, $limit);
     if (!empty($sortField) && !empty($sortOrder) || $isPaging > 0 || $userId > 0) {
         if ($this->getUser()->hasAttribute('searchClues')) {
             $searchClues = $this->getUser()->getAttribute('searchClues');
             $searchClues['offset'] = $offset;
             $searchClues['sortField'] = $sortField;
             $searchClues['sortOrder'] = $sortOrder;
             $this->form->setDefaultDataToWidgets($searchClues);
         }
     } else {
         $this->getUser()->setAttribute('searchClues', $searchClues);
     }
     $userIds = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('SystemUser');
     $params = array();
     $this->parmetersForListCompoment = $params;
     if ($this->getUser()->hasFlash('templateMessage')) {
         list($this->messageType, $this->message) = $this->getUser()->getFlash('templateMessage');
     }
     if ($request->isMethod('post')) {
         if (empty($isPaging)) {
             $offset = 0;
             $pageNumber = 1;
             $this->form->bind($request->getParameter($this->form->getName()));
             if ($this->form->isValid()) {
                 $searchClues = $this->_setSearchClues($sortField, $sortOrder, $offset, $limit);
                 $this->getUser()->setAttribute('searchClues', $searchClues);
             } else {
                 $this->redirect('admin/viewSystemUsers');
             }
         }
     }
     $this->getUser()->setAttribute('pageNumber', $pageNumber);
     if (empty($userIds)) {
         $systemUserList = array();
         $systemUserListCount = 0;
     } else {
         $searchClues['user_ids'] = $userIds;
         $systemUserList = $this->getSystemUserService()->searchSystemUsers($searchClues);
         $systemUserListCount = $this->getSystemUserService()->getSearchSystemUsersCount($searchClues);
     }
     $this->_setListComponent($systemUserList, $limit, $pageNumber, $systemUserListCount);
 }
Exemplo n.º 8
0
 protected function _getMenuItemDetails()
 {
     if (!$this->getUser()->hasAttribute(self::MAIN_MENU_USER_ATTRIBUTE)) {
         // $menuItemArray = $this->getContext()->getUserRoleManager()->getAccessibleMenuItemDetails();
         // Above leads to an internal error when ESS tries to access unauthorized URL
         // Try http://localhost/orangehrm/symfony/web/index.php/performance/saveReview as ESS
         $menuItemArray = UserRoleManagerFactory::getUserRoleManager()->getAccessibleMenuItemDetails();
         $this->getUser()->setAttribute(self::MAIN_MENU_USER_ATTRIBUTE, $menuItemArray);
     }
     return $this->getUser()->getAttribute(self::MAIN_MENU_USER_ATTRIBUTE);
 }
Exemplo n.º 9
0
 /**
  * Get Pre Defined User Role List
  * 
  * @return array
  */
 private function getAssignableUserRoleList()
 {
     $list = array();
     $userRoles = $this->getSystemUserService()->getAssignableUserRoles();
     $accessibleRoleIds = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('UserRole');
     foreach ($userRoles as $userRole) {
         if (in_array($userRole->getId(), $accessibleRoleIds)) {
             $list[$userRole->getId()] = $userRole->getDisplayName();
         }
     }
     return $list;
 }
 /**
  * get Red hat location by country
  * 
  */
 public function execute($request)
 {
     $jsonArray = array();
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee');
     foreach ($employeeList as $employee) {
         $jsonArray[] = array('name' => $employee->getFullName(), 'id' => $employee->getEmpNumber());
     }
     usort($jsonArray, array($this, 'compareByName'));
     $jsonString = json_encode($jsonArray);
     echo $jsonString;
     exit;
 }
Exemplo n.º 11
0
 /**
  * Get Location list
  * @param type $showAll
  * @return type
  */
 public function getLocationList($showAll = true)
 {
     $locationList = array();
     $locations = $this->getLocationService()->getLocationList();
     $accessibleLocations = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Location', BasicUserRoleManager::OPERATION_VIEW);
     foreach ($locations as $location) {
         if ($showAll || in_array($location->id, $accessibleLocations)) {
             $locationDetailsArray = array('id' => $location->getId(), 'locationName' => $location->getName(), 'country_code' => $location->getCountryCode(), 'province' => $location->getProvince(), 'city' => $location->getCity(), 'address' => $location->getAddress());
             $locationList[] = $locationDetailsArray;
         }
     }
     return $locationList;
 }
 /**
  * Executes the authorization filter.
  *
  * @param sfFilterChain $filterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     $moduleName = $this->context->getModuleName();
     $actionName = $this->context->getActionName();
     // disable security on login and secure actions
     if (sfConfig::get('sf_login_module') == $moduleName && sfConfig::get('sf_login_action') == $actionName || sfConfig::get('sf_secure_module') == $moduleName && sfConfig::get('sf_secure_action') == $actionName || 'auth' == $moduleName && ($actionName == 'retryLogin' || $actionName == 'validateCredentials' || $actionName == 'logout')) {
         $filterChain->execute();
         return;
     }
     $logger = Logger::getLogger('filter.ohrmAuthorizationFilter');
     try {
         $userRoleManager = UserRoleManagerFactory::getUserRoleManager();
         $this->context->setUserRoleManager($userRoleManager);
     } catch (Exception $e) {
         $logger->error('Exception: ' . $e);
         $this->forwardToSecureAction();
     }
     // disable security on non-secure actions
     try {
         $secure = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance()->getSecurityValue('is_secure');
         if (!$secure || $secure === "false" || $secure === "off") {
             $filterChain->execute();
             return;
         }
     } catch (sfStopException $e) {
         // sfStopException is a symfony internal exception and
         //  shouldn't be treated as a normal exception
         throw $e;
     } catch (Exception $e) {
         $logger->error('Error getting is_secure value for action: ' . $e);
         $this->forwardToSecureAction();
     }
     try {
         $permissions = $userRoleManager->getScreenPermissions($moduleName, $actionName);
     } catch (Exception $e) {
         $logger->error('Exception: ' . $e);
         $this->forwardToSecureAction();
     }
     // user does not have read permissions
     if (!$permissions->canRead()) {
         $logger->warn('User does not have access read access to ' . $moduleName . ' - ' . $actionName);
         // the user doesn't have access
         $this->forwardToSecureAction();
     } else {
         // set permissions in context
         $this->context->set('screen_permissions', $permissions);
     }
     // the user has access, continue
     $filterChain->execute();
 }
 protected function _getMenuItemDetails()
 {
     $menuItemArray = $this->getUser()->getAttribute(self::MAIN_MENU_USER_ATTRIBUTE);
     // If menu items not set or menu items are empty, recreate them.
     // We check if the menu items are empty, because in some scenarios, we can get an
     // empty menu item list when accessing some login related urls where user role manager
     // is not properly initialized yet, and does not have any user roles set.
     if (!isset($menuItemArray['menuItemArray']) || empty($menuItemArray['menuItemArray'])) {
         // $menuItemArray = $this->getContext()->getUserRoleManager()->getAccessibleMenuItemDetails();
         // Above leads to an internal error when ESS tries to access unauthorized URL
         // Try http://localhost/orangehrm/symfony/web/index.php/performance/saveReview as ESS
         $menuItemArray = UserRoleManagerFactory::getUserRoleManager()->getAccessibleMenuItemDetails();
         $this->getUser()->setAttribute(self::MAIN_MENU_USER_ATTRIBUTE, $menuItemArray);
     }
     return $menuItemArray;
 }
 /**
  * get Red hat location by country
  * 
  */
 public function execute($request)
 {
     $jsonArray = array();
     $properties = array("empNumber", "firstName", "middleName", "lastName", "termination_id");
     $employeeNameList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityProperties('Employee', $properties);
     foreach ($employeeNameList as $id => $attributes) {
         $name = trim(trim($attributes['firstName'] . ' ' . $attributes['middleName'], ' ') . ' ' . $attributes['lastName']);
         if ($attributes['termination_id']) {
             $name = $name . ' (' . __('Past Employee') . ')';
         }
         $jsonArray[$attributes['empNumber']] = array('name' => $name, 'id' => $attributes['empNumber']);
     }
     usort($jsonArray, array($this, 'compareByName'));
     $jsonString = json_encode($jsonArray);
     echo $jsonString;
     exit;
 }
Exemplo n.º 15
0
 public function getEmployeeListAsJson()
 {
     $jsonArray = array();
     $employeeService = new EmployeeService();
     $employeeService->setEmployeeDao(new EmployeeDao());
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee');
     $employeeUnique = array();
     $jsonArray[] = array('name' => __('All'), 'id' => '');
     foreach ($employeeList as $employee) {
         if (!isset($employeeUnique[$employee->getEmpNumber()])) {
             $name = $employee->getFullName();
             $employeeUnique[$employee->getEmpNumber()] = $name;
             $jsonArray[] = array('name' => $name, 'id' => $employee->getEmpNumber());
         }
     }
     $jsonString = json_encode($jsonArray);
     return $jsonString;
 }
 public function execute($request)
 {
     $this->timesheetPermissions = $this->getDataGroupPermissions('time_employee_timesheets');
     $this->form = new viewEmployeeTimesheetForm();
     if ($request->isMethod("post")) {
         $this->form->bind($request->getParameter('time'));
         if ($this->form->isValid()) {
             $this->employeeId = $this->form->getValue('employeeId');
             $startDaysListForm = new startDaysListForm(array(), array('employeeId' => $this->employeeId));
             $dateOptions = $startDaysListForm->getDateOptions();
             if ($dateOptions == null) {
                 $this->getContext()->getUser()->setFlash('warning.nofade', __('No Timesheets Found'));
                 $this->redirect('time/createTimesheetForSubourdinate?' . http_build_query(array('employeeId' => $this->employeeId)));
             }
             $this->redirect('time/viewTimesheet?' . http_build_query(array('employeeId' => $this->employeeId)));
         }
     }
     $userRoleManager = $this->getContext()->getUserRoleManager();
     $properties = array("empNumber", "firstName", "middleName", "lastName", "termination_id");
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityProperties('Employee', $properties);
     $this->form->employeeList = $employeeList;
     $this->pendingApprovelTimesheets = $this->getActionableTimesheets($employeeList);
 }
 public function isEmployeeLeaveEntitlementEditable()
 {
     $empNumber = $this->getEmployee()->getEmpNumber();
     $manager = UserRoleManagerFactory::getUserRoleManager();
     // Supervisor cannot edit leave entitlement even when employee is accessible (subordinate)
     // Note: This can now be handled through requiredPermissions array
     if ($manager->isEntityAccessible('Employee', $empNumber, null, array('Supervisor'))) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 18
0
 public function getPathAfterLoggingIn(sfContext $context)
 {
     $logger = Logger::getLogger('core.homepageservice');
     $redirectToReferer = true;
     $request = $context->getRequest();
     $referer = $request->getReferer();
     $host = $request->getHost();
     // get base url: ie something like: http://host:port/symfony/web/index.php
     $baseUrl = $request->getUriPrefix() . $request->getPathInfoPrefix();
     if ($logger->isDebugEnabled()) {
         $logger->debug("referer: {$referer}, host: {$host}, base url: {$baseUrl}");
     }
     if (strpos($referer, $this->loginPath)) {
         // Check whether referer is login page
         $redirectToReferer = false;
         if ($logger->isDebugEnabled()) {
             $logger->debug("referrer is the login page. Skipping redirect:" . $this->loginPath);
         }
     } elseif (strpos($referer, $this->validatePath)) {
         // Check whether referer is validate action
         $redirectToReferer = false;
         if ($logger->isDebugEnabled()) {
             $logger->debug("referrer is the validate action. Skipping redirect:" . $this->validatePath);
         }
     } else {
         if (false === strpos($referer, $baseUrl)) {
             // Check whether from same host
             $redirectToReferer = false;
             if ($logger->isDebugEnabled()) {
                 $logger->debug("referrer does not have same base url. Skipping redirect");
             }
         }
     }
     /* 
      * Try to get action and module, skip redirecting to referrer and show homepage if:
      * 1) Action is not secure (probably a login related url we should not redirect to)
      * 2) Action is not accessible to current user.
      */
     if ($redirectToReferer) {
         try {
             $moduleAndAction = str_replace($baseUrl, '', $referer);
             if ($logger->isDebugEnabled()) {
                 $logger->debug('referrer module and action: ' . $moduleAndAction);
             }
             $params = $context->getRouting()->parse($moduleAndAction);
             if ($params && isset($params['module']) && isset($params['action'])) {
                 $moduleName = $params['module'];
                 $actionName = $params['action'];
                 if ($logger->isDebugEnabled()) {
                     $logger->debug("module: {$moduleName}, action: {$actionName}");
                 }
                 if ($context->getController()->actionExists($moduleName, $actionName)) {
                     $action = $context->getController()->getAction($moduleName, $actionName);
                     if ($action instanceof sfAction) {
                         if ($action->isSecure()) {
                             $permissions = UserRoleManagerFactory::getUserRoleManager()->getScreenPermissions($moduleName, $actionName);
                             if ($permissions instanceof ResourcePermission) {
                                 if ($permissions->canRead()) {
                                     return $referer;
                                 }
                             } else {
                                 $logger->debug("action does not exist");
                             }
                         } else {
                             $logger->debug("action is not secure");
                         }
                     } else {
                         $logger->debug("action not an instance of sfAction");
                     }
                 } else {
                     $logger->debug("action does not exist");
                 }
             } else {
                 $logger->debug("referrer does not match a route");
             }
         } catch (Exception $e) {
             $logger->warn('Error when trying to get referrer action: ' . $e);
         }
     }
     return $this->getHomePagePath();
 }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $empName = null;
        $empId = null;
        if ($value != null) {
            $service = new EmployeeService();
            if (is_array($value)) {
                $empId = isset($value['empId']) ? $value['empId'] : '';
                $empName = isset($value['empName']) ? $value['empName'] : '';
            } else {
                $empId = $value;
                $employee = $service->getEmployee($value);
                if (!empty($employee)) {
                    $empName = $employee->getFirstName() . " " . $employee->getMiddleName();
                    $empName = trim(trim($empName) . " " . $employee->getLastName());
                }
            }
        }
        $values = array_merge(array('empName' => '', 'empId' => ''), is_null($value) ? array() : array('empName' => $empName, 'empId' => $empId));
        $html = strtr($this->translate($this->getOption('template')), array('%empId%' => $this->getOption($this->attributes['id'] . '_' . 'empId')->render($name . '[empId]', $values['empId'], array('id' => $this->attributes['id'] . '_' . 'empId')), '%empName%' => $this->getOption($this->attributes['id'] . '_' . 'empName')->render($name . '[empName]', $values['empName'], array('id' => $this->attributes['id'] . '_' . 'empName'))));
        $noEmployeeMessage = __('No Employees Available');
        $requiredMessage = __(ValidationMessages::REQUIRED);
        $invalidMessage = __(ValidationMessages::INVALID);
        $typeHint = __('Type for hints') . ' ...';
        $userRoleManager = UserRoleManagerFactory::getUserRoleManager();
        $requiredPermissions = array();
        $dataGroups = $this->getOption('data_groups');
        if (is_array($dataGroups) && count($dataGroups) > 0) {
            $permission = new ResourcePermission(true, false, false, false);
            $dataGroupPermissions = array();
            foreach ($dataGroups as $dataGroup) {
                $dataGroupPermissions[$dataGroup] = $permission;
            }
            $requiredPermissions[BasicUserRoleManager::PERMISSION_TYPE_DATA_GROUP] = $dataGroupPermissions;
        }
        $employeeList = $userRoleManager->getAccessibleEntities('Employee', null, null, array(), array(), $requiredPermissions);
        $javaScript = $javaScript = sprintf(<<<EOF
<script type="text/javascript">

    var employees = %s;
    var employeesArray = eval(employees);
    var errorMsge;
    var employeeFlag;
    var empId;
    var valid = false; 

\$(document).ready(function() {

            if (\$("#%s" + "_empName").val() == '') {
                \$("#%s" + "_empName").val('%s')
                .addClass("inputFormatHint");
            }

            \$("#%s" + "_empName").one('focus', function() {

                if (\$(this).hasClass("inputFormatHint")) {
                    \$(this).val("");
                    \$(this).removeClass("inputFormatHint");
                }
            })
            .data('typeHint', "{$typeHint}");
            

    \$("#%s" + "_empName").autocomplete(employees, {

            formatItem: function(item) {
                return \$('<div/>').text(item.name).html();
            },
            formatResult: function(item) {
                return item.name
            }
            ,matchContains:true
        }).result(function(event, item) {
            \$("#%s" + "_empId").val(item.id);
        }
    );

    \$('#btnSav').click(function() {
                \$('#defineReportForm input.inputFormatHint').val('');
                \$('#defineReportForm').submit();
        });

        \$('#defineReportFor').submit(function(){
            \$('#validationMsg').removeAttr('class');
            \$('#validationMsg').html("");
            var employeeFlag = validateInput();
            if(!employeeFlag) {
                \$('#validationMsg').attr('class', "messageBalloon_failure");
                \$('#validationMsg').html(errorMsge);
                return false;
            }
        });

 });

function validateInput(){

        var errorStyle = "background-color:#FFDFDF;";
        var empDateCount = employeesArray.length;
        var temp = false;
        var i;

        if(empDateCount==0){

            errorMsge = "{$noEmployeeMessage}";
            return false;
        }
        for (i=0; i < empDateCount; i++) {
            empName = \$.trim(\$('#%s' + '_empName').val()).toLowerCase();
            arrayName = employeesArray[i].name.toLowerCase();

            if (empName == arrayName) {
                \$('#%s' + '_empId').val(employeesArray[i].id);
                empId = employeesArray[i].id
                temp = true
                break;
            }
        }
        if(temp){
            valid = true;
            return true;
        }else if(empName == "" || empName == \$.trim("{$typeHint}").toLowerCase()){
            errorMsge = "{$requiredMessage}";
            return false;
        }else{
            if(valid != true){
            errorMsge = "{$invalidMessage}";
            return false;
            }else{
            return true;
            }
        }
    }
 </script>
EOF
, $this->getEmployeeListAsJson($employeeList), $this->attributes['id'], $this->attributes['id'], $typeHint, $this->attributes['id'], $this->attributes['id'], $this->attributes['id'], $this->attributes['id'], $this->attributes['id']);
        return $html . $javaScript;
    }
 public function execute($request)
 {
     $this->userObj = $this->getContext()->getUser()->getAttribute('user');
     $accessibleMenus = $this->userObj->getAccessibleAttendanceSubMenus();
     $hasRight = false;
     $this->parmetersForListCompoment = array();
     $this->showEdit = false;
     foreach ($accessibleMenus as $menu) {
         if ($menu->getDisplayName() === __("Employee Records")) {
             $hasRight = true;
             break;
         }
     }
     if (!$hasRight) {
         return $this->renderText(__("You are not allowed to view this page") . "!");
     }
     $this->trigger = $request->getParameter('trigger');
     if ($this->trigger) {
         $this->showEdit = true;
     }
     $this->date = $request->getParameter('date');
     $this->employeeId = $request->getParameter('employeeId');
     $this->employeeService = $this->getEmployeeService();
     $values = array('date' => $this->date, 'employeeId' => $this->employeeId, 'trigger' => $this->trigger);
     $this->form = new AttendanceRecordSearchForm(array(), $values);
     $this->actionRecorder = "viewEmployee";
     $isPaging = $request->getParameter('pageNo');
     $pageNumber = $isPaging;
     $noOfRecords = $noOfRecords = sfConfig::get('app_items_per_page');
     $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $noOfRecords : ($request->getParameter('pageNo', 1) - 1) * $noOfRecords;
     $records = array();
     $this->_setListComponent($records, $noOfRecords, $pageNumber, null, $this->showEdit);
     if (!$this->trigger) {
         if ($request->isMethod('post')) {
             $this->form->bind($request->getParameter('attendance'));
             if ($this->form->isValid()) {
                 $this->allowedToDelete = array();
                 $this->allowedActions = array();
                 $this->allowedActions['Delete'] = false;
                 $this->allowedActions['Edit'] = false;
                 $this->allowedActions['PunchIn'] = false;
                 $this->allowedActions['PunchOut'] = false;
                 $this->userObj = $this->getContext()->getUser()->getAttribute('user');
                 $userId = $this->userObj->getUserId();
                 $userEmployeeNumber = $this->userObj->getEmployeeNumber();
                 $post = $this->form->getValues();
                 if (!$this->employeeId) {
                     $empData = $post['employeeName'];
                     $this->employeeId = $empData['empId'];
                 }
                 if (!$this->date) {
                     $this->date = $post['date'];
                 }
                 if ($this->employeeId) {
                     $this->showEdit = true;
                 }
                 $userRoleFactory = new UserRoleFactory();
                 $this->decoratedUser = $decoratedUser = $userRoleFactory->decorateUserRole($userId, $this->employeeId, $userEmployeeNumber);
                 $isPaging = $request->getParameter('hdnAction') == 'search' ? 1 : $request->getParameter('pageNo', 1);
                 $pageNumber = $isPaging;
                 $noOfRecords = sfConfig::get('app_items_per_page');
                 $offset = $pageNumber >= 1 ? ($pageNumber - 1) * $noOfRecords : ($request->getParameter('pageNo', 1) - 1) * $noOfRecords;
                 $empRecords = array();
                 if (!$this->employeeId) {
                     //                        $empRecords = $this->employeeService->getEmployeeList('firstName', 'ASC', false);
                     $empRecords = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee');
                     $count = count($empRecords);
                 } else {
                     $empRecords = $this->employeeService->getEmployee($this->employeeId);
                     $empRecords = array($empRecords);
                     $count = 1;
                 }
                 $records = array();
                 foreach ($empRecords as $employee) {
                     $hasRecords = false;
                     $attendanceRecords = $employee->getAttendanceRecord();
                     $total = 0;
                     foreach ($attendanceRecords as $attendance) {
                         $from = $this->date . " " . "00:" . "00:" . "00";
                         $end = $this->date . " " . "23:" . "59:" . "59";
                         if (strtotime($attendance->getPunchInUserTime()) >= strtotime($from) && strtotime($attendance->getPunchInUserTime()) <= strtotime($end)) {
                             if ($attendance->getPunchOutUtcTime()) {
                                 $total = $total + round((strtotime($attendance->getPunchOutUtcTime()) - strtotime($attendance->getPunchInUtcTime())) / 3600, 2);
                             }
                             $records[] = $attendance;
                             $hasRecords = true;
                         }
                     }
                     if ($hasRecords) {
                         $last = end($records);
                         $last->setTotal($total);
                     } else {
                         $attendance = new AttendanceRecord();
                         $attendance->setEmployee($employee);
                         $attendance->setTotal('---');
                         $records[] = $attendance;
                     }
                 }
                 $params = array();
                 $this->parmetersForListCompoment = $params;
                 $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_OUT_TIME, PluginWorkflowStateMachine::ATTENDANCE_ACTION_EDIT_PUNCH_IN_TIME);
                 $actionableStates = $decoratedUser->getActionableAttendanceStates($actions);
                 $recArray = array();
                 if ($records != null) {
                     if ($actionableStates != null) {
                         foreach ($actionableStates as $state) {
                             foreach ($records as $record) {
                                 if ($state == $record->getState()) {
                                     $this->allowedActions['Edit'] = true;
                                     break;
                                 }
                             }
                         }
                     }
                     $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_DELETE);
                     $actionableStates = $decoratedUser->getActionableAttendanceStates($actions);
                     if ($actionableStates != null) {
                         foreach ($actionableStates as $state) {
                             foreach ($records as $record) {
                                 if ($state == $record->getState()) {
                                     $this->allowedActions['Delete'] = true;
                                     break;
                                 }
                             }
                         }
                     }
                     foreach ($records as $record) {
                         $this->allowedToDelete[] = $this->allowedToPerformAction(WorkflowStateMachine::FLOW_ATTENDANCE, PluginWorkflowStateMachine::ATTENDANCE_ACTION_DELETE, $record->getState(), $decoratedUser);
                         $recArray[] = $record;
                     }
                 } else {
                     $attendanceRecord = null;
                 }
                 $actions = array(PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, PluginWorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT);
                 $allowedActionsList = array();
                 $actionableStates = $decoratedUser->getActionableAttendanceStates($actions);
                 if ($actionableStates != null) {
                     if (!empty($recArray)) {
                         $lastRecordPunchOutTime = $recArray[count($records) - 1]->getPunchOutUserTime();
                         if (empty($lastRecordPunchOutTime)) {
                             $attendanceRecord = "";
                         } else {
                             $attendanceRecord = null;
                         }
                     }
                     foreach ($actionableStates as $actionableState) {
                         $allowedActionsArray = $decoratedUser->getAllowedActions(PluginWorkflowStateMachine::FLOW_ATTENDANCE, $actionableState);
                         if (!is_null($allowedActionsArray)) {
                             $allowedActionsList = array_unique(array_merge($allowedActionsArray, $allowedActionsList));
                         }
                     }
                     if (is_null($attendanceRecord) && in_array(WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_IN, $allowedActionsList)) {
                         $this->allowedActions['PunchIn'] = true;
                     }
                     if (!is_null($attendanceRecord) && in_array(WorkflowStateMachine::ATTENDANCE_ACTION_PROXY_PUNCH_OUT, $allowedActionsList)) {
                         $this->allowedActions['PunchOut'] = true;
                     }
                 }
                 if ($this->employeeId == '') {
                     $this->showEdit = FALSE;
                 }
                 $this->_setListComponent($records, $noOfRecords, $pageNumber, $count, $this->showEdit, $this->allowedActions);
             }
         }
     }
 }
Exemplo n.º 21
0
 protected function getEmployeeListAsJson()
 {
     $jsonArray = array();
     $employeeService = $this->getEmployeeService();
     $locationService = new LocationService();
     $properties = array("empNumber", "firstName", "middleName", "lastName", 'termination_id');
     $requiredPermissions = array(BasicUserRoleManager::PERMISSION_TYPE_ACTION => array('assign_leave'));
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityProperties('Employee', $properties, null, null, array(), array(), $requiredPermissions);
     $employeeUnique = array();
     foreach ($employeeList as $employee) {
         $workShiftLength = 0;
         $employeeCountry = null;
         $terminationId = $employee['termination_id'];
         $empNumber = $employee['empNumber'];
         if (!isset($employeeUnique[$empNumber]) && empty($terminationId)) {
             $name = trim(trim($employee['firstName'] . ' ' . $employee['middleName'], ' ') . ' ' . $employee['lastName']);
             $employeeUnique[$empNumber] = $name;
             $jsonArray[] = array('name' => $name, 'id' => $empNumber);
         }
     }
     $jsonString = json_encode($jsonArray);
     return $jsonString;
 }
Exemplo n.º 22
0
 /**
  *
  * @param <type> $vacnacyArray
  * @param <type> $candidateId
  */
 private function _saveCandidateVacancies($vacnacy, $candidateId)
 {
     if ($vacnacy != null) {
         $candidateVacancy = new JobCandidateVacancy();
         $candidateVacancy->candidateId = $candidateId;
         $candidateVacancy->vacancyId = $vacnacy;
         // Get correct status for candidate vacancy
         $userRoleManager = UserRoleManagerFactory::getUserRoleManager();
         $workflowItems = $userRoleManager->getAllowedActions(WorkflowStateMachine::FLOW_RECRUITMENT, 'INITIAL');
         if (isset($workflowItems[WorkflowStateMachine::RECRUITMENT_APPLICATION_ACTION_ATTACH_VACANCY])) {
             $workflowItem = $workflowItems[WorkflowStateMachine::RECRUITMENT_APPLICATION_ACTION_ATTACH_VACANCY];
             $candidateVacancy->status = $workflowItem->getResultingState();
             if ($this->getValue('appliedDate') == "") {
                 $candidateVacancy->appliedDate = date('Y-m-d');
             } else {
                 $candidateVacancy->appliedDate = $this->getValue('appliedDate');
             }
             $candidateService = $this->getCandidateService();
             $candidateService->saveCandidateVacancy($candidateVacancy);
             $history = new CandidateHistory();
             $history->candidateId = $candidateId;
             $history->action = WorkflowStateMachine::RECRUITMENT_APPLICATION_ACTION_ATTACH_VACANCY;
             $history->vacancyId = $candidateVacancy->getVacancyId();
             $history->performedBy = $this->addedBy;
             $date = date('Y-m-d');
             $history->performedDate = $date . " " . date('H:i:s');
             $history->candidateVacancyName = $candidateVacancy->getVacancyName();
             $this->getCandidateService()->saveCandidateHistory($history);
         } else {
             throw new RecruitmentExeption('No workflow items found for job vacancy INITIAL state');
         }
     }
 }
 protected function getEmployeeList()
 {
     $employeeList = $this->getOption('employeeList');
     $loadingMethod = $this->getOption('loadingMethod');
     $requiredPermissions = $this->getOption('requiredPermissions');
     if (is_array($employeeList) || $employeeList instanceof Doctrine_Collection) {
         return $employeeList;
     }
     if ($loadingMethod != 'ajax') {
         $properties = array("empNumber", "firstName", "middleName", "lastName", "termination_id");
         $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityProperties('Employee', $properties, null, null, array(), array(), $requiredPermissions);
         return $employeeList;
     } else {
         return array();
     }
 }
 protected function getEmployeeList()
 {
     $employeeService = new EmployeeService();
     $employeeList = array();
     if (Auth::instance()->hasRole(Auth::ADMIN_ROLE)) {
         $properties = array("empNumber", "firstName", "middleName", "lastName", 'termination_id');
         $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityProperties('Employee', $properties);
     }
     if ($_SESSION['isSupervisor'] && trim(Auth::instance()->getEmployeeNumber()) != "") {
         $employeeList = $employeeService->getSubordinateList(Auth::instance()->getEmployeeNumber());
     }
     return $employeeList;
 }
Exemplo n.º 25
0
 protected function getEmployeeList()
 {
     $employeeService = $this->getEmployeeService();
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee');
     $finalEmployeeList = array();
     /* Populating already assigned sup & sub */
     $assignedReportTo = array();
     $supervisors = $employeeService->getSupervisorListForEmployee($this->empNumber);
     $subordinates = $employeeService->getSubordinateListForEmployee($this->empNumber);
     foreach ($subordinates as $subordinate) {
         $assignedReportTo[$subordinate->getSubordinateId()] = true;
     }
     foreach ($supervisors as $supervisor) {
         $assignedReportTo[$supervisor->getSupervisorId()] = true;
     }
     /* Populating final list */
     foreach ($employeeList as $employee) {
         if (!isset($assignedReportTo[$employee->getEmpNumber()]) && $employee->getEmpNumber() != $this->empNumber) {
             $finalEmployeeList[] = $employee;
         }
     }
     return $finalEmployeeList;
 }
 /**
  * Gets all locations.
  * @return string[] $locationList
  */
 private function _getLocationList()
 {
     $locationService = new LocationService();
     $showAll = $this->getOption('show_all_locations');
     $locationList = array();
     $locations = $locationService->getLocationList();
     $accessibleLocations = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Location', BasicUserRoleManager::OPERATION_VIEW);
     foreach ($locations as $location) {
         if ($showAll || in_array($location->id, $accessibleLocations)) {
             $locationList[$location->getCountry()->getCouName()][] = $location;
         }
     }
     ksort($locationList);
     return $locationList;
 }
 public function getEmployeeListAsJson()
 {
     $jsonArray = array();
     $employeeService = $this->getEmployeeService();
     $locationService = new LocationService();
     $properties = array("empNumber", "firstName", "middleName", "lastName", 'termination_id');
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityProperties('Employee', $properties, null, null, array(), array(), array());
     $employeeUnique = array();
     foreach ($employeeList as $employee) {
         $terminationId = $employee['termination_id'];
         $empNumber = $employee['empNumber'];
         if (!isset($employeeUnique[$empNumber]) && empty($terminationId)) {
             $name = trim(trim($employee['firstName'] . ' ' . $employee['middleName'], ' ') . ' ' . $employee['lastName']);
             $employeeUnique[$empNumber] = $name;
             $jsonArray[] = array('name' => $name, 'id' => $empNumber);
         }
     }
     $jsonString = json_encode($jsonArray);
     return $jsonString;
 }
 /**
  * Gets all locations.
  * @return string[] $locationList
  */
 private function _getLocationList()
 {
     $locationService = new LocationService();
     $showAll = $this->getOption('show_all_locations');
     $locationList = array();
     $locations = $locationService->getLocationList();
     $accessibleLocations = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Location');
     foreach ($locations as $location) {
         if ($showAll || in_array($location->id, $accessibleLocations)) {
             $locationList[$location->id] = $location->name;
         }
     }
     return $locationList;
 }
Exemplo n.º 29
0
 protected function getEmployeeListAsJson()
 {
     $jsonArray = array();
     $employeeService = $this->getEmployeeService();
     $locationService = new LocationService();
     $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee');
     $employeeUnique = array();
     foreach ($employeeList as $employee) {
         $workShiftLength = 0;
         $employeeCountry = null;
         $terminationId = $employee->getTerminationId();
         if (!isset($employeeUnique[$employee->getEmpNumber()]) && empty($terminationId)) {
             $employeeWorkShift = $employeeService->getWorkShift($employee->getEmpNumber());
             if ($employeeWorkShift != null) {
                 $workShiftLength = $employeeWorkShift->getWorkShift()->getHoursPerDay();
             } else {
                 $workShiftLength = WorkShift::DEFAULT_WORK_SHIFT_LENGTH;
             }
             /*$operatinalCountry = $employee->getOperationalCountry();
               if ($employee->getOperationalCountry() instanceof OperationalCountry) {
                   $employeeCountry = $operatinalCountry->getId();
               }*/
             $employeeLocations = $employee->getLocations();
             if ($employeeLocations[0] instanceof Location) {
                 $location = $locationService->getLocationById($employeeLocations[0]->getId());
                 if ($location instanceof Location) {
                     $country = $location->getCountry();
                     if ($country instanceof Country) {
                         $employeeOperationalCountry = $country->getOperationalCountry();
                         if ($employeeOperationalCountry instanceof OperationalCountry) {
                             $employeeCountry = $employeeOperationalCountry->getId();
                         }
                     }
                 }
             }
             $name = $employee->getFullName();
             $employeeUnique[$employee->getEmpNumber()] = $name;
             $jsonArray[] = array('name' => $name, 'id' => $employee->getEmpNumber(), 'workShift' => $workShiftLength, 'country' => $employeeCountry);
         }
     }
     $jsonString = json_encode($jsonArray);
     return $jsonString;
 }
Exemplo n.º 30
0
 protected function setupEmployeeList()
 {
     $employeeList = array();
     $idList = array();
     $userRoleManager = UserRoleManagerFactory::getUserRoleManager();
     $properties = array("empNumber", "firstName", "middleName", "lastName", 'termination_id');
     $requiredPermissions = array(BasicUserRoleManager::PERMISSION_TYPE_DATA_GROUP => array('leave_summary' => new ResourcePermission(true, false, false, false)));
     $employeeList = $userRoleManager->getAccessibleEntityProperties('Employee', $properties, null, null, array(), array(), $requiredPermissions);
     $employeeIdList = $userRoleManager->getAccessibleEntityIds('Employee', null, null, array(), array(), $requiredPermissions);
     $this->hasAdministrativeFilters = count($employeeList) > 0;
     $hasSelf = false;
     if (in_array($this->loggedUserId, $employeeIdList)) {
         $hasSelf = true;
     }
     if (!$hasSelf) {
         $employeeService = $this->getEmployeeService();
         $loggedInEmployee = $employeeService->getEmployee($this->loggedUserId);
         if ($loggedInEmployee instanceof Employee) {
             $employeeIdList[] = $this->loggedUserId;
             $empProperties = array('empNumber' => $loggedInEmployee->getEmpNumber(), 'firstName' => $loggedInEmployee->getFirstName(), 'middleName' => $loggedInEmployee->getMiddleName(), 'lastName' => $loggedInEmployee->getLastName());
             $employeeList[$loggedInEmployee->getEmpNumber()] = $empProperties;
         }
     }
     $this->employeeList = $employeeList;
     $this->employeeIdList = $employeeIdList;
     return $employeeList;
 }