/**
  * 获取评估规则的 分布比例
  * @param int $rule_id
  * @return boolean
  */
 public function get_rule_distribution_proportion($rule_id)
 {
     $proportion = self::$_data['distribution_proportion'][$rule_id];
     if (!$proportion) {
         $proportion = json_decode(EvaluateRuleModel::get_evaluate_rule($rule_id, 'distribution_proportion'), true);
         if (!$proportion) {
             $proportion = array('高分段' => 27, '中分段' => 73, '低分段' => 100);
         }
         self::$_data['distribution_proportion'][$rule_id] = $proportion;
     }
     return $proportion;
 }
 /**
  * 检查 面试报告生成情况
  *
  * @return void
  */
 public function check_interview_stat()
 {
     /* global */
     //$this->load->model('admin/evaluate_rule_model');
     $subject_names = C('subject');
     //获取待处理的评估规则
     $this->load->model('cron/report/interview_task_report_model', 'task_model');
     $rule_ids = $this->task_model->get_doing_tasks(array(1, 2));
     if (!count($rule_ids)) {
         return false;
     }
     $pdf_path = C('html2pdf_path');
     foreach ($rule_ids as $item) {
         //获取该规则信息
         $rule = EvaluateRuleModel::get_evaluate_rule($item['rule_id']);
         if (!count($rule) || $rule['is_delete']) {
             continue;
         }
         //考试期次
         $exam_id = $rule['exam_pid'];
         $rule_id = $item['rule_id'];
         $finish_part = false;
         //pdf 是否开始处理
         $zip_all_ready = true;
         //zip 是否都已经处理完成
         /* 评分项 期次->评分标准关联->评分标准->学科->评分项*/
         $sql = "select es.options from {pre}evaluation_standard as es left join {pre}evaluation_standard_exam as ese on es.id=ese.standard_id where ese.exam_id={$exam_id};";
         $option_str = $this->db->query($sql)->row_array();
         $options = json_decode($option_str['options']);
         $subjects = array_keys((array) $options);
         if (!count($option_str)) {
             continue;
         }
         if (!count($subjects)) {
             continue;
         }
         //获取该规则关联的考生
         $result = $this->db->query("select exam_ids, uids from {pre}evaluate_student where rule_id={$rule_id}")->row_array();
         if (!count($result)) {
             continue;
         }
         $uids = explode(',', $result['uids']);
         if (!count($uids)) {
             continue;
         }
         foreach ($uids as $uid) {
             foreach ($subjects as $subject) {
                 //检查该考生的 pdf 生成情况
                 $file_name = $subject_names[$subject];
                 $path = "{$pdf_path}/zeming/interview_report/{$rule_id}/{$uid}/{$file_name}.pdf";
                 if (file_exists($path)) {
                     $finish_part = true;
                 }
             }
             //检查该考生的 zip 生成情况
             $zip_path = $this->_get_cache_root_path() . "/zip/interview_report/{$rule_id}/{$uid}.zip";
             if (!file_exists($zip_path)) {
                 $zip_all_ready = false;
             }
         }
         if ($zip_all_ready) {
             //已完成 3
             $this->task_model->set_task_done($rule_id);
         } elseif ($finish_part && !$zip_all_ready) {
             //部分完成 2
             $this->task_model->set_task_part_done($rule_id);
         }
     }
 }
Beispiel #3
0
 /**
  * 邮件通知
  */
 public function batch_mail($rule_id = 0)
 {
     $rule_id = intval($rule_id);
     $rule_id && ($rule = EvaluateRuleModel::get_evaluate_rule($rule_id));
     if (empty($rule)) {
         message('不存在该评估规则');
     }
     $uid = $this->input->post('uid');
     $send_all = intval($this->input->post('send_all'));
     if (!$send_all && (!is_array($uid) || !count($uid))) {
         message('请选择要通知的考生');
     }
     $uids = array();
     if ($send_all) {
         $sql = "select uids from {pre}evaluate_student where rule_id={$rule_id}";
         $result = $this->db->query($sql)->row_array();
         $uids = isset($result['uids']) ? trim($result['uids']) : '';
         $uids = explode(',', $uids);
     } else {
         $uids = $uid;
     }
     //获取考试期次信息
     $rule['exam_name'] = ExamModel::get_exam($rule['exam_pid'], 'exam_name');
     //获取该期次所考到的科目
     $exam_subjects = array();
     $exam_names = array();
     $sql = "select exam_id, subject_id from {pre}exam where exam_pid=" . $rule['exam_pid'];
     $result = $this->db->query($sql)->result_array();
     foreach ($result as $item) {
         $exam_names[$item['exam_id']] = C('subject/' . $item['subject_id']);
     }
     $rule['exams'] = $exam_names;
     //获取未生成zip的考生
     $sql = "select uid from {pre}evaluate_student_stat where rule_id={$rule_id} and zip_ready=0 and uid in(" . implode(',', $uids) . ")";
     $result = $this->db->query($sql)->result_array();
     $no_zip_ready_uids = array();
     foreach ($result as $item) {
         $no_zip_ready_uids[] = $item['uid'];
     }
     $data = array();
     $fails = array();
     $email_tpl = C('email_template/send_zip');
     foreach ($uids as $uid) {
         $uid && ($student = StudentModel::get_student($uid, 'uid, email, last_name, first_name'));
         if (empty($student)) {
             $fails[] = 'uid:' . $uid . '【原因:考生不存在】';
             continue;
         }
         if (in_array($uid, $no_zip_ready_uids)) {
             $fails[] = 'uid:' . $uid . '【原因:未生成zip压缩包】';
             continue;
         }
         $email = $student['email'];
         if (!is_email($email)) {
             $fails[] = 'uid:' . $uid . '->email:' . $email . '【原因:邮件地址格式不正确】';
             continue;
         }
         $email_content = $this->load->view($email_tpl['tpl'], array('rule' => $rule, 'student' => $student), true);
         $data[] = array('type' => 1, 'target_id' => "{$rule_id}-{$uid}", 'email' => $email, 'title' => $email_tpl['subject'], 'content' => $email_content, 'attache' => "report/{$rule_id}/{$uid}.zip");
     }
     $res = $this->cron_task_email_model->insert_batch($data);
     if ($res) {
         if (count($fails)) {
             message('已成功将部分该考生加入通知队列中,等待系统处理中,以下考生出现异常:<br/>' . implode('<hr/>', $fails));
         } else {
             message('已成功将该考生加入通知队列中,等待系统处理中');
         }
     } else {
         message('操作失败,请重试.');
     }
 }
 /**
  * @param   int     $rule_id
  * @param   int     $exam_id
  * @param   int     $stu_id
  * @return  mixed
  */
 public static function studentTranscriptInfo($rule_id, $exam_id, $stu_id)
 {
     $rule_id = intval($rule_id);
     $exam_id = intval($exam_id);
     $stu_id = intval($stu_id);
     if (!$rule_id || !$exam_id || !$stu_id) {
         return array();
     }
     //考试信息
     $exam = self::$_data['exam_info'][$exam_id];
     if (!$exam) {
         $exam = ExamModel::get_exam($exam_id);
         if (!$exam) {
             return array();
         }
         self::$_data['exam_info'][$exam_id] = $exam;
     }
     //学生信息
     $stu_info = StudentModel::get_student($stu_id, 'school_id,last_name,first_name,external_account,exam_ticket');
     if (!$stu_info) {
         return array();
     }
     $db = Fn::db();
     $data = array();
     $subject_id = $exam['subject_id'];
     $exam_pid = $exam['exam_pid'];
     $subject_name = C('subject/' . $subject_id);
     if (!isset(self::$_data['school_rank'][$exam_id][$stu_info['school_id']])) {
         $sql = "SELECT uid, rank\n                    FROM rd_summary_region_student_rank\n                    WHERE exam_id = {$exam_id} AND region_id = ?\n                    AND is_school = 1 AND is_class = 0\n                    ORDER BY rank ASC";
         $grade_rank = $db->fetchPairs($sql, array($stu_info['school_id']));
         self::$_data['school_rank'][$exam_id][$stu_info['school_id']] = $grade_rank;
     } else {
         $grade_rank = self::$_data['school_rank'][$exam_id][$stu_info['school_id']];
     }
     $sql = "SELECT a.etp_id, paper_id, test_score, ques_id FROM rd_exam_test_paper a\n                LEFT JOIN rd_exam_test_paper_question b ON a.etp_id = b.etp_id\n                WHERE uid = ? AND exam_id = ?";
     $bind = array($stu_id, $exam_id);
     $etp = $db->fetchRow($sql, $bind);
     if (!$etp) {
         return array();
     }
     $proportion = self::$_data['distribution_proportion'][$rule_id];
     if (!$proportion) {
         $proportion = json_decode(EvaluateRuleModel::get_evaluate_rule($rule_id, 'distribution_proportion'), true);
         if (!$proportion) {
             $proportion = array('高分段' => 27, '中分段' => 73, '低分段' => 100);
         }
         $proportion = array_values($proportion);
         self::$_data['distribution_proportion'][$rule_id] = $proportion;
     }
     $level_results = 'A';
     $prev_rank = 0;
     $stu_num = count($grade_rank);
     $stu_rank = $grade_rank[$stu_id];
     foreach ($proportion as $k => $rate) {
         $rank = $stu_num * $rate / 100;
         if ($prev_rank < $stu_rank && $stu_rank <= $rank) {
             break;
         }
         $level_results++;
         $prev_rank = $rank;
     }
     $sch_name = self::$_data['school_info'][$stu_info['school_id']];
     if (!$sch_name) {
         $school = SchoolModel::schoolInfo($stu_info['school_id'], 'school_name');
         $sch_name = $school['school_name'];
         self::$_data['school_info'][$stu_info['school_id']] = $sch_name;
     }
     //成绩信息
     $data['results'] = array('exam_name' => $exam['exam_name'], 'stu_fullname' => $stu_info['last_name'] . $stu_info['first_name'], 'stu_schname' => $sch_name, 'subject_name' => $subject_name, 'exam_ticket' => $stu_info['external_account'] ? $stu_info['external_account'] : $stu_info['exam_ticket'], 'test_score' => $etp['test_score'], 'level_results' => $level_results);
     //试题得分
     //计算学校总体试卷试题得分率
     $level_percent = self::$_data['school_question_level_percent'][$etp['paper_id']][$stu_info['school_id']];
     if (!$level_percent) {
         $sql = "SELECT ques_id, ROUND(test_score / total_score * 100) AS percent\n                    FROM rd_summary_region_question\n                    WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n                    AND is_school = 1";
         $stmt = $db->query($sql);
         while ($item = $stmt->fetch(PDO_DB::FETCH_ASSOC)) {
             self::calLevelPercent($item['ques_id'], $item['percent'], $level_percent);
         }
         self::$_data['school_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent;
     }
     //计算本次学生试题得分率
     $sql = "SELECT ques_id, ROUND(SUM(test_score) / SUM(full_score) * 100) AS percent\n                FROM rd_exam_test_result WHERE etp_id = ?\n                GROUP BY ques_id";
     $stu_percent = $db->fetchPairs($sql, array($etp['etp_id']));
     //计算学生考试试题得分率对应等级
     $ques_ids = explode(',', $etp['ques_id']);
     $data['question'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array());
     foreach ($ques_ids as $index => $ques_id) {
         $percent = $stu_percent[$ques_id] > 100 ? 100 : (int) $stu_percent[$ques_id];
         foreach ($level_percent[$ques_id] as $level => $v) {
             if ($v[0] <= $percent && $percent <= $v[1]) {
                 $data['question'][$level][] = $index + 1;
                 break;
             }
         }
     }
     ksort($data['question']);
     //知识点
     $level_percent = self::$_data['school_knowledge_level_percent'][$etp['paper_id']][$stu_info['school_id']];
     if (!$level_percent) {
         $sql = "SELECT knowledge_id, ROUND(test_score / total_score * 100) AS percent\n                    FROM rd_summary_region_knowledge\n                    WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n                    AND is_school = 1 AND is_parent = 0";
         $stmt = $db->query($sql);
         while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) {
             self::calLevelPercent($item['knowledge_id'], $item['percent'], $level_percent);
         }
         self::$_data['school_knowledge_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent;
     }
     //计算本次学生知识点得分率
     $sql = "SELECT knowledge_id, knowledge_name, ROUND(test_score / total_score * 100) AS percent\n                FROM rd_summary_student_knowledge ssk\n                LEFT JOIN rd_knowledge k ON k.id = ssk.knowledge_id\n                WHERE paper_id = ? AND uid = ? AND is_parent = 0";
     $stu_percent = $db->fetchAssoc($sql, array($etp['paper_id'], $stu_id));
     $data['knowledge'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array());
     foreach ($level_percent as $knowledge_id => $levels) {
         $percent = $stu_percent[$knowledge_id]['percent'] > 100 ? 100 : (int) $stu_percent[$knowledge_id]['percent'];
         foreach ($levels as $level => $v) {
             if ($v[0] <= $percent && $percent <= $v[1]) {
                 $data['knowledge'][$level][] = $stu_percent[$knowledge_id]['knowledge_name'];
                 break;
             }
         }
     }
     ksort($data['knowledge']);
     //方法策略
     $sql = "SELECT DISTINCT(subject_id) FROM rd_subject_category_subject";
     $subject_ids = $db->fetchCol($sql);
     if (in_array($subject_id, $subject_ids)) {
         $level_percent = self::$_data['school_method_tactic_level_percent'][$etp['paper_id']][$stu_info['school_id']];
         if (!$level_percent) {
             $sql = "SELECT method_tactic_id, ROUND(test_score / total_score * 100) AS percent\n                        FROM rd_summary_region_method_tactic\n                        WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n                        AND is_school = 1";
             $stmt = $db->query($sql);
             while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) {
                 self::calLevelPercent($item['method_tactic_id'], $item['percent'], $level_percent);
             }
             self::$_data['school_method_tactic_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent;
         }
         //计算本次学生方法策略得分率
         $sql = "SELECT method_tactic_id, name, ROUND(test_score / total_score * 100) AS percent\n                    FROM rd_summary_student_method_tactic ssmt\n                    LEFT JOIN rd_method_tactic mt ON mt.id = ssmt.method_tactic_id\n                    WHERE paper_id = ? AND uid = ?";
         $stu_percent = $db->fetchAssoc($sql, array($etp['paper_id'], $stu_id));
         $data['method_tactic'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array());
         foreach ($level_percent as $method_tactic_id => $levels) {
             $percent = $stu_percent[$method_tactic_id]['percent'] > 100 ? 100 : (int) $stu_percent[$method_tactic_id]['percent'];
             foreach ($levels as $level => $v) {
                 if ($v[0] <= $percent && $percent <= $v[1]) {
                     $data['method_tactic'][$level][] = $stu_percent[$method_tactic_id]['name'];
                     break;
                 }
             }
         }
         ksort($data['method_tactic']);
     } else {
         if ($subject_id == 3) {
             $level_percent = self::$_data['school_group_type_level_percent'][$etp['paper_id']][$stu_info['school_id']];
             if (!$level_percent) {
                 $sql = "SELECT group_type_id, ROUND(test_score / total_score * 100) AS percent\n                        FROM rd_summary_region_group_type\n                        WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n                        AND is_school = 1 AND is_parent = 0";
                 $stmt = $db->query($sql);
                 while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) {
                     self::calLevelPercent($item['group_type_id'], $item['percent'], $level_percent);
                 }
                 self::$_data['school_group_type_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent;
             }
             //计算本次学生信息提取方式得分率
             $sql = "SELECT group_type_id, group_type_name, ROUND(test_score / total_score * 100) AS percent\n                    FROM rd_summary_student_group_type ssgt\n                    LEFT JOIN rd_group_type gt ON gt.id = ssgt.group_type_id\n                    WHERE paper_id = ? AND uid = ? AND is_parent = 0";
             $stu_percent = $db->fetchAssoc($sql, array($etp['paper_id'], $stu_id));
             $data['group_type'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array());
             foreach ($level_percent as $group_type_id => $levels) {
                 $percent = $stu_percent[$group_type_id]['percent'] > 100 ? 100 : (int) $stu_percent[$group_type_id]['percent'];
                 foreach ($levels as $level => $v) {
                     if ($v[0] <= $percent && $percent <= $v[1]) {
                         $data['group_type'][$level][] = $stu_percent[$group_type_id]['group_type_name'];
                         break;
                     }
                 }
             }
             ksort($data['group_type']);
         }
     }
     return $data;
 }
Beispiel #5
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('操作失败,请重试.');
     }
 }