public function indexAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     try {
         $appEmpRatingsModel = new Default_Model_Appraisalemployeeratings();
         $app_rating_model = new Default_Model_Appraisalratings();
         $appEmpRatingsData = $appEmpRatingsModel->getSelfAppraisalDataByEmpID($loginUserId);
         if (sizeof($appEmpRatingsData) > 0 && $appEmpRatingsData[0]['employee_id'] == $loginUserId && $appEmpRatingsData[0]['status'] == 1) {
             if ($appEmpRatingsData[0]['appraisal_status'] == 'Pending employee ratings') {
                 $this->_redirect('appraisalself/edit');
             } else {
                 // Check rating exist for appraisal.
                 $checkRatingsExists = $app_rating_model->getAppraisalRatingsbyInitId($appEmpRatingsData[0]['pa_initialization_id']);
                 // get all Categories Data based on category ids
                 $categories_data = $appEmpRatingsModel->getAppCateDataByIDs($appEmpRatingsData[0]['category_id']);
                 // get question previleges data of employee for that initialization
                 $appEmpQuesPrivData = $appEmpRatingsModel->getAppEmpQuesPrivData($appEmpRatingsData[0]['pa_initialization_id'], $appEmpRatingsData[0]['employee_id']);
                 // merging HR and Manager questions
                 $ques_csv = '';
                 if ($appEmpQuesPrivData[0]['hr_qs']) {
                     $ques_csv .= $appEmpQuesPrivData[0]['hr_qs'];
                 }
                 if ($appEmpQuesPrivData[0]['manager_qs']) {
                     if ($ques_csv) {
                         $ques_csv .= ',';
                     }
                     $ques_csv .= $appEmpQuesPrivData[0]['manager_qs'];
                 }
                 // get all questions data based on above question ids
                 $questions_data = $appEmpRatingsModel->getAppQuesDataByIDs($ques_csv);
                 // Employee and Manager response
                 $emp_response = array();
                 $mgr_response = array();
                 if ($appEmpRatingsData[0]['employee_response']) {
                     $emp_response = json_decode($appEmpRatingsData[0]['employee_response'], true);
                 }
                 if ($appEmpRatingsData[0]['manager_response']) {
                     $mgr_response = json_decode($appEmpRatingsData[0]['manager_response'], true);
                 }
                 // get rating details using configuration id
                 $ratingsData = $appEmpRatingsModel->getAppRatingsDataByConfgId($appEmpRatingsData[0]['pa_configured_id'], $appEmpRatingsData[0]['pa_initialization_id']);
                 $ratingType = "";
                 if (!empty($ratingsData)) {
                     $ratingType = $ratingsData[0]['rating_type'];
                 }
                 $ratingText = array();
                 $ratingTextDisplay = array();
                 $ratingValues = array();
                 foreach ($ratingsData as $rd) {
                     $ratingText[] = $rd['rating_text'];
                     $ratingTextDisplay[$rd['id']] = $rd['rating_text'];
                     $ratingValues[$rd['id']] = $rd['rating_value'];
                 }
                 // building managers names from Emp-Ques-Privileges data
                 $managerIDs = array();
                 $managerNames = array();
                 $line_unique_arr = array_filter(array_unique(array(1 => $appEmpQuesPrivData[0]['line_manager_1'], 2 => $appEmpQuesPrivData[0]['line_manager_2'], 3 => $appEmpQuesPrivData[0]['line_manager_3'], 4 => $appEmpQuesPrivData[0]['line_manager_4'], 5 => $appEmpQuesPrivData[0]['line_manager_5'])), 'strlen');
                 if (!empty($line_unique_arr)) {
                     for ($i = 1; $i <= count($line_unique_arr); $i++) {
                         $managerIDs[] = $line_unique_arr[$i];
                     }
                     $usersData = $appEmpRatingsModel->getUserNamesByIDs(implode($managerIDs, ','));
                     foreach ($managerIDs as $mi) {
                         foreach ($usersData as $ud) {
                             if ($ud['id'] == $mi) {
                                 //	$managerNames[] = $ud['userfullname'];
                                 $managerNames[$ud['id']] = $ud['userfullname'];
                             }
                         }
                     }
                 }
                 // Skill response data
                 $skill_response = array();
                 if ($appEmpRatingsData[0]['skill_response']) {
                     $skill_response = json_decode($appEmpRatingsData[0]['skill_response'], true);
                     $skill_ids = array_keys($skill_response);
                     $skData = $appEmpRatingsModel->getSkillNamesByIDs(implode($skill_ids, ','));
                     $skillData = array();
                     foreach ($skData as $s) {
                         $skillData[$s['id']] = $s['skill_name'];
                     }
                     $this->view->skillData = $skillData;
                 }
                 // get Appraisal history details
                 $appHistoryData = $appEmpRatingsModel->getAppHistoryData($appEmpRatingsData[0]['employee_id'], $appEmpRatingsData[0]['pa_initialization_id']);
                 $this->view->skill_response = $skill_response;
                 $this->view->appHistoryData = $appHistoryData;
                 $this->view->managerNames = $managerNames;
                 $this->view->appEmpRatingsData = $appEmpRatingsData;
                 $this->view->categories_data = $categories_data;
                 $this->view->questions_data = $questions_data;
                 $this->view->ratingType = $ratingType;
                 $this->view->ratingTextDisplay = $ratingTextDisplay;
                 $this->view->ratingText = json_encode($ratingText);
                 $this->view->ratingValues = $ratingValues;
                 $this->view->emp_response = $emp_response;
                 $this->view->mgr_response = $mgr_response;
                 $this->view->check_ratings_exists = $checkRatingsExists;
             }
         } else {
             $this->view->rowexist = "norows";
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         $this->view->rowexist = "norows";
     }
 }