public function onekeycalculateAction()
 {
     $this->view->disable();
     $manager = $this->session->get('Manager');
     if (empty($manager)) {
         $this->dataReturn(array('error' => '获取用户信息失败,请重新登陆'));
         return;
     }
     // 获取项目下的人员名单 ----所有
     $examinees = $this->modelsManager->createBuilder()->columns(array('id', 'state', 'number', 'name'))->from('Examinee')->where('Examinee.project_id = ' . $manager->project_id . ' AND Examinee.type = 0 ')->getQuery()->execute()->toArray();
     $not_exam = array();
     //未参加考试人员
     //         $not_finish_calculate = array(); //未算分完成人员
     $calcual_error = array();
     // 在算分过程中出现错误的人员
     foreach ($examinees as $examinee_record) {
         if ($examinee_record['state'] == 0) {
             $not_exam[] = $examinee_record['number'] . '-' . $examinee_record['name'] . '-还未参加测评';
         } else {
             if ($examinee_record['state'] < 4) {
                 try {
                     BasicScore::handlePapers($examinee_record['id']);
                     BasicScore::finishedBasic($examinee_record['id']);
                     FactorScore::handleFactors($examinee_record['id']);
                     FactorScore::finishedFactor($examinee_record['id']);
                     IndexScore::handleIndexs($examinee_record['id']);
                     IndexScore::finishedIndex($examinee_record['id']);
                 } catch (Exception $e) {
                     $calcual_error[] = $examinee_record['number'] . '-' . $examinee_record['name'] . '-算分过程中失败,原因:' . $e->getMessage();
                 }
             } else {
                 //...
             }
         }
     }
     //先反馈回未参与考试的人员
     if (!empty($not_exam)) {
         $this->dataReturn(array('error' => $not_exam));
         return;
     }
     //后反馈回算分失败的人员
     if (!empty($calcual_error)) {
         $this->dataReturn(array('error' => $calcual_error));
         return;
     }
     $this->dataReturn(array('success' => 'true'));
     return;
 }
 public function getpersonalresultAction()
 {
     $this->view->disable();
     $examinee_id = $this->request->getPost('examinee_id', 'int');
     $examinee_info = Examinee::findFirst(array('id=?1', 'bind' => array(1 => $examinee_id)));
     if (!isset($examinee_info->id)) {
         $this->dataReturn(array('error' => '不存在的被试编号-' . $examinee_id));
         return;
     }
     //个体报告的导出必须是manager pm & interviwer
     $manager = $this->session->get('Manager');
     if (empty($manager)) {
         $this->dataReturn(array('error' => '用户信息失效,请重新登录!'));
         return;
     }
     //判断个人状态
     if ($examinee_info->state == 0) {
         //还未开始答题
         $this->dataReturn(array('error' => '被试还未答题'));
         return;
     } else {
         if ($examinee_info->state < 4) {
             //算分流程未完成
             try {
                 BasicScore::handlePapers($examinee_info->id);
                 BasicScore::finishedBasic($examinee_info->id);
                 FactorScore::handleFactors($examinee_info->id);
                 FactorScore::finishedFactor($examinee_info->id);
                 IndexScore::handleIndexs($examinee_info->id);
                 IndexScore::finishedIndex($examinee_info->id);
             } catch (Exception $e) {
                 $this->dataReturn(array('error' => '被试算分流程未完成,原因:' . $e->getMessage()));
                 return;
             }
         } else {
             //算分流程已完成
             //add nothing
         }
     }
     // 根据目录结构判断文件是否存在
     $year = floor($examinee_info->project_id / 100);
     $path = './project/' . $year . '/' . $examinee_info->project_id . '/individual/personal_result/';
     $path_url = '/project/' . $year . '/' . $examinee_info->project_id . '/individual/personal_result/';
     $name = $examinee_info->number . '_personal_result.xls';
     if (file_exists($path . $name)) {
         $this->dataReturn(array('success' => '点击下载&nbsp;<a href=\'' . $path_url . $name . "' style='color:blue;text-decoration:underline;'>个人测评十项报表</a>"));
         return;
     } else {
         try {
             $checkout_excel = new CheckoutExcel();
             $report_tmp_name = $checkout_excel->excelExport($examinee_info);
             $report_name = $path . $name;
             $file = new FileHandle();
             $file->movefile($report_tmp_name, $report_name);
             //清空临时文件 主要在tmp中
             $file->clearfiles('./tmp/', $examinee_info->id);
             //返回路径
             $this->dataReturn(array('success' => '点击下载&nbsp;<a href=\'' . $path_url . $name . "' style='color:blue;text-decoration:underline;'>个人测评十项报表</a>"));
             return;
         } catch (Exception $e) {
             $this->dataReturn(array('error' => '个人测评十项报表生成失败,原因:' . $e->getMessage()));
             return;
         }
     }
 }