1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace app\model;
- use think\Model;
- class ExamEmpResult extends Model
- {
- //relaitonship
- public function paper()
- {
- return $this->belongsTo('ExamPaper', 'paper_id')->bind([
- 'name', 'starttime', 'endtime', 'duringtime', 'total_score', 'base_score','checkway'
- ]);
- }
- public function employee()
- {
- return $this->belongsTo(Employee::class, 'employee_id')->bind(['emp_name' => 'name']);
- }
- public function employees()
- {
- return $this->belongsTo(Employee::class, 'aprove_employee_id')->bind(['p_name' => 'name']);
- }
- //funcitons
- public static function autoPaperAnswerCheck($emp_answer = '', $keywordsstr = '', $fullscore = 0)
- {
- $keywordsarr = array_filter(explode('|', $keywordsstr));
- $keynum = count($keywordsarr);
- $eachkeyscore = 0;
- if (!empty($fullscore) && !empty($keynum)) {
- $eachkeyscore = $fullscore / $keynum;
- }
- $gotkeys = [];
- foreach ($keywordsarr as $keyw) {
- $posnum = strpos($emp_answer, $keyw);
- if ($posnum === false) continue;
- $gotkeys[] = $keyw;
- $markentity = '<span class="keyw" style="color:red;">' . $keyw . '</span>';
- $emp_answer = str_replace($keyw, $markentity, $emp_answer);
- }
- $got_key_num = count(array_unique($gotkeys));
- $got_score = floor($got_key_num * $eachkeyscore);
- $data = [
- 'got_score' => $got_score,
- 'emp_answer' => $emp_answer,
- 'gotkeys' => $gotkeys
- ];
- return $data;
- }
- public function paperid()
- {
- return $this->belongsTo(ExamPaper::class, 'paper_id')->bind(['total_score' => 'total_score']);
- }
- public function emp()
- {
- return $this->belongsTo(Employee::class, 'employee_id');
- }
- public function paperInfo()
- {
- return $this->belongsTo('ExamPaper', 'paper_id'); //
- }
- public function paperShowRealName()
- {
- return $this->belongsTo(ExamPaper::class, 'paper_id')->bind(['show_real_name']);
- }
- }
|