/**
  *
  * @param <type> $request
  */
 public function execute($request)
 {
     $userObj = $this->getUser()->getAttribute('user');
     $allowedVacancyList = $userObj->getAllowedVacancyList();
     $allowedCandidateListToDelete = $userObj->getAllowedCandidateListToDelete();
     $this->candidateId = $request->getParameter('id');
     $this->invalidFile = false;
     $reDirect = false;
     $this->edit = true;
     if ($this->candidateId > 0 && !in_array($this->candidateId, $allowedCandidateListToDelete)) {
         $reDirect = true;
         $this->edit = false;
     }
     $param = array('candidateId' => $this->candidateId, 'allowedVacancyList' => $allowedVacancyList, 'empNumber' => $userObj->getEmployeeNumber(), 'isAdmin' => $userObj->isAdmin());
     $this->setForm(new AddCandidateForm(array(), $param, true));
     if ($this->getUser()->hasFlash('templateMessage')) {
         list($this->messageType, $this->message) = $this->getUser()->getFlash('templateMessage');
     }
     $this->jobVacancyList = $this->getVacancyService()->getAllVacancies();
     $this->candidateStatus = JobCandidate::ACTIVE;
     if ($this->candidateId > 0) {
         $allowedCandidateList = $userObj->getAllowedCandidateList();
         if (!in_array($this->candidateId, $allowedCandidateList)) {
             $this->redirect('recruitment/viewCandidates');
         }
         $this->actionForm = new ViewCandidateActionForm(array(), $param, true);
         $allowedHistoryList = $userObj->getAllowedCandidateHistoryList($this->candidateId);
         $candidateHistory = $this->getCandidateService()->getCandidateHistoryForCandidateId($this->candidateId, $allowedHistoryList);
         $candidateHistoryService = new CandidateHistoryService();
         $this->_setListComponent($candidateHistoryService->getCandidateHistoryList($candidateHistory));
         $params = array();
         $this->parmetersForListCompoment = $params;
         $this->candidateStatus = $this->getCandidateService()->getCandidateById($this->candidateId)->getStatus();
     } else {
         if (!($userObj->isAdmin() || $userObj->isHiringManager())) {
             $this->redirect('recruitment/viewCandidates');
         }
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         $file = $request->getFiles($this->form->getName());
         if ($_FILES['addCandidate']['size']['resume'] > 1024000 || $_FILES['addCandidate']['error']['resume'] && $_FILES['addCandidate']['name']['resume']) {
             $title = $this->candidateId > 0 ? __('Editing Candidate') : __('Adding Candidate');
             $this->templateMessage = array('WARNING', '' . __(TopLevelMessages::FILE_SIZE_SAVE_FAILURE));
         } elseif ($_FILES == null) {
             $title = $this->candidateId > 0 ? __('Editing Candidate') : __('Adding Candidate');
             $this->getUser()->setFlash('templateMessage', array('warning', __(TopLevelMessages::FILE_SIZE_SAVE_FAILURE)));
             $this->redirect('recruitment/addCandidate');
         } else {
             $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
             $file = $request->getFiles($this->form->getName());
             if ($this->form->isValid()) {
                 $result = $this->form->save();
                 if (isset($result['messageType'])) {
                     $this->messageType = $result['messageType'];
                     $this->message = $result['message'];
                     $this->invalidFile = true;
                 } else {
                     $this->candidateId = $result['candidateId'];
                     $this->getUser()->setFlash('templateMessage', array('success', __(TopLevelMessages::SAVE_SUCCESS)));
                     $this->redirect('recruitment/addCandidate?id=' . $this->candidateId);
                 }
             }
         }
     }
 }
 /**
  *
  * @param <type> $request
  */
 public function execute($request)
 {
     /* For highlighting corresponding menu item */
     $request->setParameter('initialActionName', 'viewCandidates');
     $userRoleManager = $this->getContext()->getUserRoleManager();
     $requiredPermissions = array(BasicUserRoleManager::PERMISSION_TYPE_DATA_GROUP => array('recruitment_candidates' => new ResourcePermission(true, false, false, false)));
     $allowedVacancyList = $userRoleManager->getAccessibleEntityIds('Vacancy', null, null, array(), array(), $requiredPermissions);
     $this->candidatePermissions = $this->getDataGroupPermissions('recruitment_candidates');
     $userObj = $this->getUser()->getAttribute('user');
     $allowedCandidateListToDelete = $userObj->getAllowedCandidateListToDelete();
     $this->candidateId = $request->getParameter('id');
     $this->invalidFile = false;
     $reDirect = false;
     $this->edit = true;
     if ($this->candidateId > 0 && !in_array($this->candidateId, $allowedCandidateListToDelete)) {
         $reDirect = true;
         $this->edit = false;
     }
     $param = array('candidateId' => $this->candidateId, 'allowedVacancyList' => $allowedVacancyList, 'empNumber' => $userObj->getEmployeeNumber(), 'isAdmin' => $userObj->isAdmin(), 'candidatePermissions' => $this->candidatePermissions);
     $this->setForm(new AddCandidateForm(array(), $param, true));
     $vacancyProperties = array('name', 'id', 'status');
     $this->jobVacancyList = $this->getVacancyService()->getVacancyPropertyList($vacancyProperties);
     $this->candidateStatus = JobCandidate::ACTIVE;
     if ($this->candidateId > 0) {
         $allowedCandidateList = $userObj->getAllowedCandidateList();
         if (!in_array($this->candidateId, $allowedCandidateList)) {
             $this->redirect('recruitment/viewCandidates');
         }
         $this->actionForm = new ViewCandidateActionForm(array(), $param, true);
         $allowedHistoryList = $userObj->getAllowedCandidateHistoryList($this->candidateId);
         $candidateHistory = $this->getCandidateService()->getCandidateHistoryForCandidateId($this->candidateId, $allowedHistoryList);
         $candidateHistoryService = new CandidateHistoryService();
         if ($this->candidatePermissions->canRead()) {
             $this->_setListComponent($candidateHistoryService->getCandidateHistoryList($candidateHistory));
         }
         $params = array();
         $this->parmetersForListCompoment = $params;
         $this->candidateStatus = $this->getCandidateService()->getCandidateById($this->candidateId)->getStatus();
     } else {
         if (!($userObj->isAdmin() || $userObj->isHiringManager() || $this->candidatePermissions->canRead())) {
             $this->redirect('recruitment/viewCandidates');
         }
     }
     if ($request->isMethod('post')) {
         if ($this->candidatePermissions->canCreate() || $this->candidatePermissions->canUpdate()) {
             $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
             $file = $request->getFiles($this->form->getName());
             if ($_FILES['addCandidate']['size']['resume'] > 1024000 || $_FILES['addCandidate']['error']['resume'] && $_FILES['addCandidate']['name']['resume']) {
                 $title = $this->candidateId > 0 ? __('Editing Candidate') : __('Adding Candidate');
                 $this->getUser()->setFlash('addcandidate.warning', __(TopLevelMessages::FILE_SIZE_SAVE_FAILURE));
             } elseif ($_FILES == null) {
                 $title = $this->candidateId > 0 ? __('Editing Candidate') : __('Adding Candidate');
                 $this->getUser()->setFlash('addcandidate.warning', __(TopLevelMessages::FILE_SIZE_SAVE_FAILURE));
                 $this->redirect('recruitment/addCandidate');
             } else {
                 $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
                 $file = $request->getFiles($this->form->getName());
                 if ($this->form->isValid()) {
                     $result = $this->form->save();
                     if (isset($result['messageType'])) {
                         $this->getUser()->setFlash('addcandidate.warning', $result['message']);
                         $this->invalidFile = true;
                     } else {
                         $this->candidateId = $result['candidateId'];
                         $this->getUser()->setFlash('addcandidate.success', __(TopLevelMessages::SAVE_SUCCESS));
                         $this->redirect('recruitment/addCandidate?id=' . $this->candidateId);
                     }
                 }
             }
         }
     }
 }