/** * @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; }
public function testAction() { $age = FactorScore::calAge('1980-07-2', '2015-11-06'); echo $age; exit; }
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'); }