Пример #1
0
 /**
  * 生成面试报告
  *
  * @author TCG 2015-08-22
  * @return void
  */
 public function interview_general($rule_id = 0)
 {
     if (!$this->check_power('evaluate_rule_manage')) {
         return;
     }
     $rule_id = intval($rule_id);
     $rule_id && ($rule = EvaluateRuleModel::get_evaluate_rule($rule_id));
     if (empty($rule)) {
         message('不存在该评估规则');
     }
     $this->load->model('cron/report/interview_task_report_model', 'task_report_model');
     $task = $this->task_report_model->get_task($rule_id);
     if (isset($task['status']) && ($task['status'] == '0' || $task['status'] == '1')) {
         message('该规则报告正在处理中,请耐心等待.');
     }
     $template_id = $this->input->post('template_id');
     if (empty($template_id)) {
         message('请选择面试报告模板');
     }
     $templates = array();
     if (is_array($template_id)) {
         foreach ($template_id as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             $template_info = EvaluateTemplateModel::get_evaluate_template_info($value, false);
             if (!$template_info) {
                 message('模板不存在!');
             }
             $templates[$key] = $value;
             /* @todo 验证模板类型 */
         }
     } else {
         message('模板参数错误,请从新选择模板!');
     }
     //添加一条计划任务
     $res = $this->task_report_model->insert($rule_id, json_encode($templates, JSON_FORCE_OBJECT));
     if ($res) {
         $rule_admin = array('rule_id' => $rule_id, 'admin_id' => $this->session->userdata('admin_id'));
         $this->db->replace('evaluate_rule_admin', $rule_admin);
         admin_log('generate', 'evaluate_rule', $rule_id);
         message('已成功将该规则添加到生成报告队列中,报告将在第二天生成,请耐心等待.', '/admin/evaluate_rule/index');
     } else {
         message('操作失败,请重试.');
     }
 }
 /**
  * 生成面试模板->html
  *
  * @return void
  */
 public function general_interview_to_html()
 {
     /* global */
     //$this->load->model('admin/interview_question_model');
     //$this->load->model('admin/interview_result_model');
     $this->load->model('cron/report/interview_task_report_model', 'task_model');
     //$this->load->model('admin/evaluate_template_model', 'et_model');
     //$this->load->model('admin/evaluation_option_model');
     /* config */
     $subject_names = C('subject');
     /**************************** 1.获取数据 **************************/
     /* 任务->评估规则(->模板信息)->考试期次(->评估规则)->考生->面试结果 */
     /* 获取待处理的评估规则 */
     $rule_ids = $this->task_model->get_doing_tasks();
     if (!count($rule_ids)) {
         return false;
     }
     foreach ($rule_ids as $item) {
         $rule_id = $item['rule_id'];
         $ctime = $item['ctime'];
         $convert2pdf_data = array();
         /* 评估规则 */
         $rule = EvaluateRuleModel::get_evaluate_rule($rule_id);
         if (!count($rule) || $rule['is_delete']) {
             continue;
         }
         /* 考试期次 */
         $exam_id = $rule['exam_pid'];
         $sql = "select exam_name from {pre}exam where exam_id={$exam_id}";
         $exam_info = $this->db->query($sql)->row_array();
         if (empty($exam_info)) {
             continue;
         }
         /* 评分标准 */
         $sql = "select * from \n\t\t\t\t{pre}evaluation_standard as es \n\t\t\t\tleft join {pre}evaluation_standard_exam as ese on es.id=ese.standard_id \n\t\t\t\twhere ese.exam_id={$exam_id};";
         $standard = $this->db->query($sql)->row_array();
         if (!count($standard)) {
             continue;
         }
         $options = json_decode($standard['options'], true);
         $weights = json_decode($standard['weight'], true);
         $level = json_decode($standard['level'], true);
         /* 将该规则的计划任务设置为 处理中 */
         $item['status'] == '0' && $this->task_model->set_task_doing($rule_id);
         /* 模板信息 */
         $template_module = array();
         /* 是否生成总结报告 */
         $is_summary = false;
         if ($item['template_id']) {
             $template_data = json_decode($item['template_id'], true);
             foreach ($template_data as $key => $value) {
                 if (in_array($key, array(0, '0'), true)) {
                     $is_summary = true;
                 }
                 $template_module[$key] = EvaluateTemplateModel::get_evaluate_template_info($value);
             }
         } else {
             $message = "[" . date('Y-m-d H:i:s') . "]" . " 规则(" . $rule_id . ")模板信息不存在!";
             log_message('error', $message);
             continue;
         }
         /* 所有考生(考生信息) */
         $students = array();
         $sql = "select distinct r.student_id,s.uid,s.first_name,s.last_name,sh.school_name from \n\t\t\t\t{pre}interview_result as r left join {pre}student as s on r.student_id=s.uid \n\t\t\t\tleft join {pre}school as sh on s.school_id=sh.school_id \n\t\t\t\twhere exam_id={$exam_id}";
         $students = $this->db->query($sql)->result_array();
         if (count($students) <= 0) {
             continue;
         }
         /* 所有总结报告 */
         $summary_array = array();
         /* 实际权重得分排名 */
         $actual_resutl_ranking = array();
         /* 循环学生生成报告 */
         foreach ($students as $student) {
             /* 如果系统中没有当前考生信息,跳过报告生成 */
             if (empty($student['student_id'])) {
                 continue;
             }
             /* 总结 (0 为总结报告) 以模板为准,如果模板中含有总结模板,则生成总结报告*/
             if ($is_summary) {
                 /* global */
                 $data = array();
                 $actual_score = 0;
                 /* 1.各科面试得分状况 uid */
                 $total = array();
                 foreach ($options as $subject_id => $option) {
                     /* a.各个学科评分项总分 stanard -> option */
                     $option_str = implode(',', $option);
                     $option_sql = "select sum(score) as sum from {pre}evaluation_option where id in ({$option_str})";
                     $option_result = $this->db->query($option_sql)->row_array();
                     $total[$subject_id]['option_score'] = $option_result['sum'];
                     /* b.权重 standard */
                     $total[$subject_id]['weight'] = $weights[$subject_id];
                     /* c.实际得分 uid,exam_id ->interview_result*/
                     $score_sql = "select sum(scroe) as sum from {pre}interview_result \n\t\t\t\t\t\t\twhere exam_id={$exam_id} and student_id={$student['uid']} and subject_id={$subject_id}";
                     $score_result = $this->db->query($score_sql)->row_array();
                     $total[$subject_id]['score'] = $score_result['sum'];
                     /* d.实际权重得分 保留小数点后两位 */
                     $total[$subject_id]['actual'] = round($total[$subject_id]['score'] * $total[$subject_id]['weight'] / 100, 2);
                     /* 实际总得分 */
                     $actual_score += $total[$subject_id]['actual'];
                 }
                 $data['total'] = $total;
                 /* 2.获奖情况 */
                 /* uid -> ruidabei_result */
                 $ruidabei_sql = "select awards,score,subject,ranks,grade from {pre}ruidabei_result \n\t\t\t\t\t\twhere exam_id={$exam_id} and student_id={$student['uid']}";
                 $ruidabei_result = $this->db->query($ruidabei_sql)->result_array();
                 $data['ruidabei_result'] = $ruidabei_result;
                 /* 3.学习与竞赛成绩 */
                 /* 排名 uid-> student_ranking */
                 $ranking_sql = "select grade_id,ranking,totalnum from {pre}student_ranking where uid={$student['uid']}";
                 $ranking_result = $this->db->query($ranking_sql)->result_array();
                 $data['ranking_result'] = $ranking_result;
                 /* 获奖 uid->awards */
                 $awards_sql = "select typeid,subject,awards,grade,other_name,other_desc from {pre}student_awards\n\t\t\t\t\t\twhere uid={$student['uid']}";
                 $awards_result = $this->db->query($awards_sql)->result_array();
                 $data['awards_result'] = $awards_result;
                 /* 考生信息 */
                 /* a.姓名 */
                 $data['student_id'] = $student['uid'];
                 $data['school_name'] = $student['school_name'];
                 $data['student_name'] = $student['last_name'] . $student['first_name'];
                 $data['actual_score'] = $actual_score;
                 $data['examName'] = $exam_info['exam_name'];
                 $summary_array[] = $data;
                 $actual_result_ranking[$student['uid']] = $actual_score;
             }
             /* 单学科 以评分标准中设置的学科为准,如果只有此学科模板,评分标准中没有选中此学科,则不生成报告*/
             foreach ($options as $key => $value) {
                 $option_ids = $value;
                 $subject_id = $key;
                 /* 科目 */
                 if (!isset($template_module[$subject_id])) {
                     continue;
                 }
                 $option_arr = array();
                 foreach ($option_ids as $k => $v) {
                     $option_arr[$k + 1] = EvaluationOptionModel::get_one($v, 'id,title,score');
                 }
                 /* 平均分 */
                 $sql = "select option_index,avg(scroe) as avg from {pre}interview_result \n\t\t\t\t\t\twhere exam_id={$exam_id} and subject_id={$subject_id} group by option_index;";
                 $score_avg = $this->db->query($sql)->result_array();
                 /* 评分项索引 */
                 $option_index = array();
                 $avg = array();
                 $avg_index = array();
                 $total = array();
                 foreach ($score_avg as $k => $v) {
                     $option_index[] = $option_arr[$v['option_index']]['title'];
                     $avg[] = intval($v['avg']);
                     $avg_index[$v['option_index']] = intval($v['avg']);
                     $total[] = intval($option_arr[$v['option_index']]['score']);
                 }
                 $student_id = $student['student_id'];
                 /* 每项评价分 */
                 $query = "select id,option_index,scroe from {pre}interview_result where \n\t\t\t\t\tstudent_id={$student_id} and exam_id={$exam_id} and subject_id={$subject_id} order by option_index";
                 $grade = $this->db->query($query)->result_array();
                 if (!count($grade)) {
                     continue;
                 }
                 /**************************** 2.生成模板 ****************************/
                 $data = array();
                 $data['studentName'] = $student['last_name'] . $student['first_name'];
                 $data['ctime'] = $ctime;
                 $data['examName'] = $exam_info['exam_name'];
                 $data['grade'] = $grade;
                 $data['score_avg'] = $score_avg;
                 $data['option_index'] = $option_index;
                 $data['avg'] = $avg;
                 $data['avg_index'] = $avg_index;
                 $data['total'] = $total;
                 $data['options'] = $option_arr;
                 $data['template_module'] = $template_module[$subject_id];
                 /* 得分分数据处理 */
                 $scroes = array();
                 foreach ($grade as $k => $v) {
                     $scroes[] = intval($v['scroe']);
                 }
                 $data['scroes'] = $scroes;
                 $data['subject_name'] = $subject_names[$subject_id];
                 $output = $this->load->view('report/interview_module/layout', $data, true);
                 /**************************** 3.写入html文件 ****************************/
                 $html_file_name = $subject_id;
                 $uid = $student['uid'];
                 $res = $this->_put_interview_html_content($rule_id, $html_file_name, $uid, $output);
                 /**************************** 4.写入生成pdf任务 ****************************/
                 if ($res) {
                     $pdf_file_name = $subject_names[$subject_id] . "面试";
                     $now = time();
                     $unique = urlencode(base64_encode("{$rule_id}-{$uid}-{$html_file_name}"));
                     $source_url = C('public_host_name') . "/interview_report/{$unique}.html";
                     $source_path = "zeming/interview_report/{$rule_id}/{$uid}/{$pdf_file_name}.pdf";
                     $target_id = "{$rule_id}_{$uid}_{$html_file_name}";
                     $convert2pdf_data[$target_id] = array('type' => '1', 'source_url' => $source_url, 'source_path' => $source_path, 'ctime' => $now, 'mtime' => $now, 'target_id' => $target_id);
                     //事先创建好保存zip目录
                     $this->_mk_interview_zip_dir($rule_id);
                 }
             }
         }
         /* 计算排名 (忽略分数相同的情况,如果分数相同,将按照添加到考试期次中的顺序排序)*/
         $actual_ranking_result = usort($summary_array, function ($a, $b) {
             if ($a['actual_score'] == $b['actual_score']) {
                 return 0;
             }
             return $a['actual_score'] > $b['actual_score'] ? -1 : 1;
         });
         $count_student = count($summary_array);
         $level_index = array_values($level);
         $level_name = array_keys($level);
         $summary_array = array_values($summary_array);
         if ($count_student > 0) {
             foreach ($summary_array as $summary_index => $summary) {
                 /* 分级 */
                 $increment = 0;
                 foreach ($level_index as $key => $level_percent) {
                     $level_min = ceil($count_student * $increment / 100);
                     $level_max = ceil($count_student * ($level_percent + $increment) / 100);
                     $increment += $level_percent;
                     if ($summary_index >= $level_min && $summary_index < $level_max) {
                         $summary['level_name'] = $level_name[$key];
                     }
                 }
                 /* 生成模板 */
                 $output = $this->load->view('report/interview_summary_module/layout', $summary, true);
                 /* 写入html */
                 $html_file_name = '0';
                 $uid = $summary['student_id'];
                 $res = $this->_put_interview_html_content($rule_id, $html_file_name, $uid, $output);
                 /* 写入pdf任务 */
                 if ($res) {
                     $pdf_file_name = "面试总结";
                     $now = time();
                     $unique = urlencode(base64_encode("{$rule_id}-{$uid}-{$html_file_name}"));
                     $source_url = C('public_host_name') . "/interview_report/{$unique}.html";
                     $source_path = "zeming/interview_report/{$rule_id}/{$uid}/{$pdf_file_name}.pdf";
                     $target_id = "{$rule_id}_{$uid}_{$html_file_name}";
                     $convert2pdf_data[$target_id] = array('type' => '1', 'source_url' => $source_url, 'source_path' => $source_path, 'ctime' => $now, 'mtime' => $now, 'target_id' => $target_id);
                     //事先创建好保存zip目录
                     $this->_mk_interview_zip_dir($rule_id);
                 }
             }
         }
         /* ====================================================== */
         /* 保存 待生成pdf 数据 */
         if (count($convert2pdf_data)) {
             $this->_save_convert2pdf_data($convert2pdf_data);
         }
     }
 }
Пример #3
0
 /**
  * 删除模板
  */
 public function delete($template_id = 0)
 {
     if (!$template_id) {
         $template_id = implode(',', $this->input->post('ids'));
     }
     $template_type = (int) $this->session->userdata('template_type');
     if (!$template_id) {
         message('请选择需要删除的模板');
     }
     $back_url = "/admin/evaluate_template/index/" . $template_type;
     if (EvaluateTemplateModel::remove_evaluate_template($template_id)) {
         admin_log('delete', 'evaluate_template', $template_id);
         message('删除模板成功', $back_url);
     } else {
         message('删除模板失败', $back_url);
     }
 }