示例#1
0
 /**
  * 处理指标得分的核心
  * @param int $examinee_id
  */
 public static function handleIndexs($examinee_id)
 {
     #判定项目存在
     if (empty(self::$project_id)) {
         $index_state = self::getProjectId($examinee_id);
         #false 表示这一层已经完成
         if (!$index_state) {
             return false;
         }
     }
     #获取必须存到数据库的相关因子
     self::getFactors($examinee_id);
     #获取需要计算的指标
     if (empty(self::$indexs_list)) {
         self::getIndexs($examinee_id);
     }
     $index_ans = array();
     #此处为依次进行
     foreach (self::$indexs_list as $key => $value) {
         $score = 0;
         $index_detail = MemoryCache::getIndexDetail($value);
         if ($value != 'zb_ldnl' && $value != 'zb_gzzf') {
             #注意此处解析直接需要知道得到相应的因子得分,如果需要的因子得分而没有得到计算,那么可能报错
             $code = preg_replace('/[a-zA-Z][a-zA-Z0-9]*/', 'self::$factors_list[\'$0\']', $index_detail->action);
             $matches = array();
             preg_match_all('/self\\:\\:\\$factors\\_list\\[\'[a-zA-Z][a-zA-Z0-9]*\'\\]/', $code, $matches);
             foreach ($matches[0] as $key => $svalue) {
                 if (!isset($svalue)) {
                     eval("{$svalue} = 0;");
                 }
             }
             $code = "\$score = sprintf(\"%.2f\",{$code});";
             eval($code);
             $index_ans[$value] = $score;
         } else {
             if ($value == 'zb_ldnl') {
                 $code = preg_replace('/zb_[a-zA-Z0-9]*/', '\\$index_ans[\'$0\']', $index_detail->action);
                 $matches = array();
                 preg_match_all('/\\$index\\_ans\\[\'[a-zA-Z][a-zA-Z0-9]*\'\\]/', $code, $matches);
                 foreach ($matches[0] as $key => $svalue) {
                     if (!isset($svalue)) {
                         eval("{$svalue} = 0;");
                     }
                 }
                 $code = "\$score = sprintf(\"%.2f\",{$code});";
                 eval($code);
                 $index_ans[$value] = $score;
             } else {
                 if (!isset($index_ans['zb_rjgxtjsp'])) {
                     $index_ans['zb_rjgxtjsp'] = 0;
                 }
                 $code = $index_detail->action;
                 $code = str_replace('zb_rjgxtjsp', 'rjgxtjsptmp', $code);
                 self::$factors_list['rjgxtjsptmp'] = $index_ans['zb_rjgxtjsp'];
                 $code = preg_replace('/[a-zA-Z][a-zA-Z0-9]*/', 'self::$factors_list[\'$0\']', $code);
                 $matches = array();
                 preg_match_all('/self\\:\\:\\$factors\\_list\\[\'[a-zA-Z][a-zA-Z0-9]*\'\\]/', $code, $matches);
                 foreach ($matches[0] as $key => $svalue) {
                     if (!isset($svalue)) {
                         eval("{$svalue} = 0;");
                     }
                 }
                 $code = "\$score = sprintf(\"%.2f\",{$code});";
                 eval($code);
                 $index_ans[$value] = $score;
                 if (isset(self::$factors_list['rjgxtjsptmp'])) {
                     unset(self::$factors_list['rjgxtjsptmp']);
                 }
             }
         }
     }
     try {
         $manager = new TxManager();
         $transaction = $manager->get();
         foreach (self::$indexs_list as $key => $value) {
             $index = new IndexAns();
             $index->setTransaction($transaction);
             $index->examinee_id = $examinee_id;
             $index->index_id = $key;
             $index->score = $index_ans[$value];
             $isWrited = IndexAns::findFirst(array("examinee_id = :examinee_id: AND index_id = :index_id:", 'bind' => array('examinee_id' => $examinee_id, 'index_id' => $key)));
             if (isset($isWrited->score)) {
                 continue;
             }
             if ($index->save() == false) {
                 $transaction->rollback("Cannot insert IndexAns data");
             }
         }
         $transaction->commit();
         return true;
     } catch (TxFailed $e) {
         throw new Exception("Failed, reason: " . $e->getMessage());
     }
 }