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 testAction() { $age = FactorScore::calAge('1980-07-2', '2015-11-06'); echo $age; exit; }
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' => '点击下载 <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' => '点击下载 <a href=\'' . $path_url . $name . "' style='color:blue;text-decoration:underline;'>个人测评十项报表</a>")); return; } catch (Exception $e) { $this->dataReturn(array('error' => '个人测评十项报表生成失败,原因:' . $e->getMessage())); return; } } }
/** * @usage 个体胜任力报告生成 * @param */ public function individualCompetencyReport($examinee_id) { //check examinee_id - - - get basic info $data = new CompetencyData(); $examinee_data = $data->getExamineeData($examinee_id); $examinee = Examinee::findFirst($examinee_id); $project_id = $examinee->project_id; $project_data = $data->getProjectAvgIndex($project_id, $examinee_data); \PhpOffice\PhpWord\Autoloader::register(); $this->wordHandle = new \PhpOffice\PhpWord\PhpWord(); //set default style $this->wordHandle->setDefaultFontName("Microsoft YaHei"); $titleFontStyle = array('color' => 'blue', 'size' => 12, 'bold' => true); $fontStyle2 = array('color' => 'blue'); //set table style $labelFontStyle = array('bold' => true, 'size' => 12); $labelParagraphStyle = array('alignment' => 'center'); $valueFontStyle = array('size' => 12); $valuePragraphStyle = array('alignment' => 'center'); $styleTable = array('borderSize' => 6, 'borderColor' => 'black', 'cellMargin' => 80); $section = $this->wordHandle->createSection(); $table = $section->addTable($styleTable); $table->addRow(); $cell1_19 = $table->addCell(1000); $cell1_19->getStyle()->setGridSpan(9); $cell1_19->addText("胜任力模型+述职、民主生活会、民主集中制、四个全面", array('color' => 'red', 'bold' => true, 'size' => 16), array('alignment' => 'center')); $table->addRow(); $table->addCell(1000)->addText("姓名", $labelFontStyle, $labelParagraphStyle); $table->addCell(1000)->addText($examinee->name, $valueFontStyle, $valuePragraphStyle); $table->addCell(1000)->addText("性别", $labelFontStyle, $labelParagraphStyle); $table->addCell(1000)->addText($examinee->sex == 1 ? '男' : '女', $valueFontStyle, $valuePragraphStyle); $table->addCell(1000)->addText("年龄", $labelFontStyle, $labelParagraphStyle); //个体年龄取整 $age = floor(FactorScore::calAge($examinee->birthday, $examinee->last_login)); $table->addCell(1000)->addText($age, $valueFontStyle, $valuePragraphStyle); $table->addCell(1000)->addText("职位", $labelFontStyle, $labelParagraphStyle); $cell2_89 = $table->addCell(1000); $cell2_89->getStyle()->setGridSpan(2); $cell2_89->addText($examinee->duty, $valueFontStyle, $valuePragraphStyle); $table->addRow(); $cell3_19 = $table->addCell(1000); $cell3_19->getStyle()->setGridSpan(9); $cell3_19->addText('胜任素质评分', $titleFontStyle, $labelParagraphStyle); $table->addRow(); foreach ($examinee_data['advantage']['value'] as $key => $value) { $table->addCell(1000)->addText($value['chs_name'], $labelFontStyle, $labelParagraphStyle); } foreach ($examinee_data['disadvantage']['value'] as $key => $value) { $table->addCell(1000)->addText($value['chs_name'], $labelFontStyle, $labelParagraphStyle); } $table->addCell(1000)->addText('总分', $labelFontStyle, $labelParagraphStyle); $table->addRow(); foreach ($examinee_data['advantage']['value'] as $key => $value) { $table->addCell(1000)->addText($value['score'], $valueFontStyle, $valuePragraphStyle); } foreach ($examinee_data['disadvantage']['value'] as $key => $value) { $table->addCell(1000)->addText($value['score'], $valueFontStyle, $valuePragraphStyle); } $table->addCell(1000)->addText($examinee_data['value'], $valueFontStyle, $valuePragraphStyle); $table->addRow(); $cell6_19 = $table->addCell(1000); $cell6_19->getStyle()->setGridSpan(9); $cell6_19->addText("胜任力模型+述职", $titleFontStyle, $labelParagraphStyle); $table->addRow(); $cell7_19 = $table->addCell(1000); $cell7_19->getStyle()->setGridSpan(9); //add chart $chart = new WordChart(); $fileName = $chart->radarGraph_3($examinee_data, $project_data, $project_id); if (file_exists($fileName)) { $cell7_19->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.31), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(6.46), 'wrappingStyle' => 'square')); } $cell7_19->addText("主要优势有五点:", $titleFontStyle); $array1 = array('一', '二', '三', '四', '五'); $i = 0; foreach ($examinee_data['advantage']['value'] as $key => $value) { $cell7_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell7_19->addText("有待改进有三点:", $titleFontStyle); $array2 = array('一', '二', '三'); $i = 0; foreach ($examinee_data['disadvantage']['value'] as $key => $value) { $cell7_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell7_19->addText("述职报告结果:", $titleFontStyle); $cell7_19->addTextBreak(); $table->addRow(); $cell8_19 = $table->addCell(1000); $cell8_19->getStyle()->setGridSpan(9); $cell8_19->addText("胜任力模型+民主生活会", $titleFontStyle, $labelParagraphStyle); $table->addRow(); $cell9_19 = $table->addCell(1000); $cell9_19->getStyle()->setGridSpan(9); if (file_exists($fileName)) { $cell9_19->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.31), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(6.46), 'wrappingStyle' => 'square')); } $cell9_19->addText("主要优势有五点:", $titleFontStyle); $array1 = array('一', '二', '三', '四', '五'); $i = 0; foreach ($examinee_data['advantage']['value'] as $key => $value) { $cell9_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell9_19->addText("有待改进有三点:", $titleFontStyle); $array2 = array('一', '二', '三'); $i = 0; foreach ($examinee_data['disadvantage']['value'] as $key => $value) { $cell9_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell9_19->addText("民主生活会指标描述:", $titleFontStyle); $cell9_19->addTextBreak(); $table->addRow(); $cell10_19 = $table->addCell(1000); $cell10_19->getStyle()->setGridSpan(9); $cell10_19->addText("胜任力模型+民主集中制", $titleFontStyle, $labelParagraphStyle); $table->addRow(); $cell11_19 = $table->addCell(1000); $cell11_19->getStyle()->setGridSpan(9); if (file_exists($fileName)) { $cell11_19->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.31), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(6.46), 'wrappingStyle' => 'square')); } $cell11_19->addText("主要优势有五点:", $titleFontStyle); $array1 = array('一', '二', '三', '四', '五'); $i = 0; foreach ($examinee_data['advantage']['value'] as $key => $value) { $cell11_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell11_19->addText("有待改进有三点:", $titleFontStyle); $array2 = array('一', '二', '三'); $i = 0; foreach ($examinee_data['disadvantage']['value'] as $key => $value) { $cell11_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell11_19->addText("民主集中制指标描述:", $titleFontStyle); $cell11_19->addTextBreak(); $table->addRow(); $cell12_19 = $table->addCell(1000); $cell12_19->getStyle()->setGridSpan(9); $cell12_19->addText("胜任力模型+四个全面", $titleFontStyle, $labelParagraphStyle); $table->addRow(); $cell13_19 = $table->addCell(1000); $cell13_19->getStyle()->setGridSpan(9); if (file_exists($fileName)) { $cell13_19->addImage($fileName, array('width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(9.31), 'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(6.46), 'wrappingStyle' => 'square')); } $cell13_19->addText("主要优势有五点:", $titleFontStyle); $array1 = array('一', '二', '三', '四', '五'); $i = 0; foreach ($examinee_data['advantage']['value'] as $key => $value) { $cell13_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell13_19->addText("有待改进有三点:", $titleFontStyle); $array2 = array('一', '二', '三'); $i = 0; foreach ($examinee_data['disadvantage']['value'] as $key => $value) { $cell13_19->addText($array1[$i++] . "是" . $value['comment'], array('size' => 12)); } $cell13_19->addText("四个全面指标描述:", $titleFontStyle); $cell13_19->addTextBreak(); //命名 //临时文件命名规范 $project_id_$date_rand(100,900) $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($this->wordHandle, 'Word2007'); $date = date('H_i_s'); $stamp = rand(100, 900); $fileName = './tmp/' . $examinee_id . '_' . $date . '_' . $stamp . '.docx'; $objWriter->save($fileName); return $fileName; }
/** * @usage 返回被试应该写入的所有因子得分 * @param int $examinee_id */ protected static function getFactorsAll($examinee_id) { if (empty(self::$examinee_info)) { self::getExamineeInfo($examinee_id); } $project_info = MemoryCache::getProjectDetail(self::$examinee_info['project_id']); self::$factors_list_all = json_decode($project_info->factor_names, true); }
public function checkoutSpm($examinee, $objActSheet) { $objActSheet->getDefaultRowDimension()->setRowHeight(21); $objActSheet->getDefaultColumnDimension()->setWidth(12); $objActSheet->mergeCells('A1:F1'); $objActSheet->setCellValue('A1', 'SPM瑞文标准推理测验结果'); $objActSheet->getStyle('A1')->getFont()->setBold(true); $this->position($objActSheet, 'A1'); $objActSheet->setCellValue('A2', '分类号'); $this->position($objActSheet, 'A2'); $objActSheet->mergeCells('B2:F2'); $objActSheet->setCellValue('A3', '编号'); $this->position($objActSheet, 'A3'); $objActSheet->setCellValue('B3', $examinee->number); $this->position($objActSheet, 'B3'); $objActSheet->setCellValue('C3', '姓名'); $this->position($objActSheet, 'C3'); $objActSheet->setCellValue('D3', $examinee->name); $this->position($objActSheet, 'D3'); $objActSheet->setCellValue('E3', '性别'); $this->position($objActSheet, 'E3'); $objActSheet->setCellValue('F3', $examinee->sex == "1" ? "男" : "女"); $this->position($objActSheet, 'F3'); $objActSheet->setCellValue('A4', '年龄'); $this->position($objActSheet, 'A4'); $age = floor(FactorScore::calAge($examinee->birthday, $examinee->last_login)); $objActSheet->setCellValue('B4', $age); $this->position($objActSheet, 'B4'); $objActSheet->setCellValue('C4', '测试日期'); $this->position($objActSheet, 'C4'); $date = explode(' ', $examinee->last_login)[0]; $objActSheet->setCellValue('D4', $date); $this->position($objActSheet, 'D4'); $styleArray = array('borders' => array('outline' => array('style' => PHPExcel_Style_Border::BORDER_THIN))); $objActSheet->getStyle('A2:F4')->applyFromArray($styleArray); $objActSheet->getStyle('A6:F9')->applyFromArray($styleArray); $objActSheet->mergeCells('A5:F5'); $objActSheet->setCellValue('A6', '总分'); $this->position($objActSheet, 'A6'); $objActSheet->setCellValue('C6', '百分等级'); $this->position($objActSheet, 'C6'); $objActSheet->setCellValue('E6', '智力等级'); $this->position($objActSheet, 'E6'); $objActSheet->setCellValue('A7', '评定结果'); $this->position($objActSheet, 'A7'); $objActSheet->mergeCells('B7:F7'); $objActSheet->setCellValue('A8', '部分'); $this->position($objActSheet, 'A8'); $objActSheet->setCellValue('B8', 'A类'); $this->position($objActSheet, 'B8'); $objActSheet->setCellValue('C8', 'B类'); $this->position($objActSheet, 'C8'); $objActSheet->setCellValue('D8', 'C类'); $this->position($objActSheet, 'D8'); $objActSheet->setCellValue('E8', 'D类'); $this->position($objActSheet, 'E8'); $objActSheet->setCellValue('F8', 'E类'); $this->position($objActSheet, 'F8'); $objActSheet->setCellValue('A9', '得分'); $this->position($objActSheet, 'A9'); $spmArray = array('spma', 'spmb', 'spmc', 'spmd', 'spme'); $spmPos = array('B', 'C', 'D', 'E', 'F'); $data = CheckoutData::getSPMdata($examinee); if (empty($data)) { return; } $dengji = array(1 => '一级、高水平智力。', 2 => '二级、智力水平良好。', 3 => '三级、中等水平智力。', 4 => '四级、智力水平中下。', 5 => '五级、智力缺陷。'); if (isset($data['spm'])) { $str = $data['spm']['std_score']; $zhili = substr($str, 0, 1); $objActSheet->setCellValue('F6', $zhili); $this->position($objActSheet, 'F6'); $baifen = substr($str, 1); $objActSheet->setCellValue('D6', $baifen); $this->position($objActSheet, 'D6'); if (isset($dengji[$zhili])) { $objActSheet->setCellValue('B7', $dengji[$zhili]); $this->position($objActSheet, 'B7', 'left'); } } $sum = 0; foreach ($spmArray as $key => $value) { if (isset($data[$value])) { $objActSheet->setCellValue($spmPos[$key] . '9', $data[$value]['std_score']); $this->position($objActSheet, $spmPos[$key] . '9'); $sum += $data[$value]['std_score']; } } $objActSheet->setCellValue('B6', $sum); $this->position($objActSheet, 'B6'); }