public function getindividualComprehensive($examinee_id)
 {
     $project_id = Examinee::findFirst($examinee_id)->project_id;
     $project_detail = ProjectDetail::findFirst(array("project_id = :project_id:", 'bind' => array('project_id' => $project_id)));
     if (empty($project_detail) || empty($project_detail->module_names)) {
         throw new Exception('项目配置信息有误');
     }
     $exist_module_array = explode(',', $project_detail->module_names);
     $module_array = array("心理健康" => 'mk_xljk', "素质结构" => 'mk_szjg', "智体结构" => 'mk_ztjg', "能力结构" => 'mk_nljg');
     $module_array_score = array();
     foreach ($module_array as $key => $value) {
         if (!in_array($value, $exist_module_array)) {
             continue;
         }
         $module_record = Module::findFirst(array("name = ?1", 'bind' => array(1 => $value)));
         $children = $module_record->children;
         $children_array = explode(',', $children);
         $result_1 = $this->modelsManager->createBuilder()->columns(array('Index.chs_name as chs_name', 'Index.name as name', 'IndexAns.score as score', 'Index.children as children'))->from('Index')->inwhere('Index.name', $children_array)->join('IndexAns', 'IndexAns.index_id = Index.id AND IndexAns.examinee_id = ' . $examinee_id)->orderBy('IndexAns.score desc')->getQuery()->execute()->toArray();
         //进行规范排序
         $module_array_score[$key] = array();
         foreach ($result_1 as &$result_1_record) {
             $skey = array_search($result_1_record['name'], $children_array);
             $module_array_score[$key][$skey] = $result_1_record;
         }
         //对指标层进行遍历查找中间层,以及children
         foreach ($module_array_score[$key] as &$index_info) {
             $middle = array();
             $middle = MiddleLayer::find(array('father_chs_name=?1', 'bind' => array(1 => $index_info['chs_name'])))->toArray();
             $children = array();
             $index_info['count'] = count(explode(',', $index_info['children']));
             $children = $this->getChildrenOfIndexDesc($index_info['name'], $index_info['children'], $examinee_id);
             $tmp = array();
             $children = $this->foo($children, $tmp);
             $tmp_detail = array();
             foreach ($middle as $middle_info) {
                 $outter_tmp = array();
                 $middle_children = explode(',', $middle_info['children']);
                 $outter_tmp_score = 0;
                 foreach ($middle_children as $children_name) {
                     $skey = array_search($children_name, $children);
                     $inner_tmp = array();
                     $inner_tmp['name'] = $children_name;
                     $inner_tmp['score'] = $children[$skey + 1];
                     $outter_tmp_score += $inner_tmp['score'];
                     $tmp_detail[] = $inner_tmp;
                 }
                 $outter_tmp['name'] = null;
                 $outter_tmp['score'] = $outter_tmp_score;
                 $tmp_detail[] = $outter_tmp;
             }
             $index_info['detail'] = $tmp_detail;
         }
     }
     return $module_array_score;
 }
 public function getEightAddFive($examinee_info)
 {
     $result = $this->modelsManager->createBuilder()->columns(array('IndexAns.index_id as id', 'IndexAns.score as score'))->from('IndexAns')->where('IndexAns.examinee_id = ' . $examinee_info->id)->orderBy('IndexAns.score desc')->getQuery()->execute()->toArray();
     $index_count = count($result);
     $rtn_array = array();
     if ($index_count < 8) {
         $rtn_array['strong'] = array_slice($result, 0, $index_count);
         $rtn_array['weak'] = array();
     } else {
         if ($index_count < 13) {
             $rtn_array['strong'] = array_slice($result, 0, 8);
             $rtn_array['weak'] = array_reverse(array_slice($result, 8, $index_count - 8));
         } else {
             $rtn_array['strong'] = array_slice($result, 0, 8);
             $rtn_array['weak'] = array_reverse(array_slice($result, $index_count - 6, 5));
         }
     }
     $strong_exist_array = array();
     foreach ($rtn_array['strong'] as &$strong_value) {
         $index = Index::findFirst(array('id=?1', 'bind' => array(1 => $strong_value['id'])));
         $strong_value['chs_name'] = $index->chs_name;
         $middle = array();
         $middle = MiddleLayer::find(array('father_chs_name=?1', 'bind' => array(1 => $strong_value['chs_name'])))->toArray();
         $children = array();
         $children = $this->getChildrenOfIndexDesc($index->name, $index->children, $examinee_info->id);
         foreach ($children as &$children_info) {
             if (!isset($children_info['raw_score'])) {
                 $children_info['raw_score'] = null;
             }
         }
         $strong_value['count'] = count($children);
         $tmp = array();
         $children = $this->foo($children, $tmp);
         // 			echo '<pre>';
         // 			print_r($children);
         // 			exit();
         $strong_value['children'] = array();
         $number_count = 0;
         foreach ($middle as $middle_info) {
             $outter_tmp = array();
             $middle_children = explode(',', $middle_info['children']);
             $outter_tmp_score = 0;
             foreach ($middle_children as $children_name) {
                 $inner_tmp = array();
                 $key = array_search($children_name, $children);
                 $number = (intval($key) + 4) / 4;
                 if ($number > 3) {
                     $number = null;
                 }
                 $inner_tmp['name'] = $children_name;
                 $inner_tmp['raw_score'] = $children[$key + 3];
                 $inner_tmp['ans_score'] = $children[$key + 1];
                 $outter_tmp_score += $inner_tmp['ans_score'];
                 $inner_tmp['number'] = $number;
                 $strong_value['children'][] = $inner_tmp;
             }
             $outter_tmp['name'] = null;
             $outter_tmp['raw_score'] = null;
             $outter_tmp['ans_score'] = $outter_tmp_score;
             $outter_tmp['number'] = null;
             $strong_value['children'][] = $outter_tmp;
         }
     }
     //进行逆向重排列
     $week_exist_array = array();
     foreach ($rtn_array['weak'] as &$strong_value) {
         $index = Index::findFirst(array('id=?1', 'bind' => array(1 => $strong_value['id'])));
         $strong_value['chs_name'] = $index->chs_name;
         $middle = array();
         $middle = MiddleLayer::find(array('father_chs_name=?1', 'bind' => array(1 => $strong_value['chs_name'])))->toArray();
         $children = array();
         $children = $this->getChildrenOfIndexDesc($index->name, $index->children, $examinee_info->id);
         $children = array_reverse($children);
         foreach ($children as &$children_info) {
             if (!isset($children_info['raw_score'])) {
                 $children_info['raw_score'] = null;
             }
         }
         $strong_value['count'] = count($children);
         $tmp = array();
         $children = $this->foo($children, $tmp);
         $strong_value['children'] = array();
         $number_count = 0;
         foreach ($middle as $middle_info) {
             $outter_tmp = array();
             $middle_children = explode(',', $middle_info['children']);
             $outter_tmp_score = 0;
             foreach ($middle_children as $children_name) {
                 $inner_tmp = array();
                 $key = array_search($children_name, $children);
                 $number = (intval($key) + 4) / 4;
                 if ($number > 3) {
                     $number = null;
                 }
                 $inner_tmp['name'] = $children_name;
                 $inner_tmp['raw_score'] = $children[$key + 3];
                 $inner_tmp['ans_score'] = $children[$key + 1];
                 $outter_tmp_score += $inner_tmp['ans_score'];
                 $inner_tmp['number'] = $number;
                 $strong_value['children'][] = $inner_tmp;
             }
             $outter_tmp['name'] = null;
             $outter_tmp['raw_score'] = null;
             $outter_tmp['ans_score'] = $outter_tmp_score;
             $outter_tmp['number'] = null;
             $strong_value['children'][] = $outter_tmp;
         }
     }
     return $rtn_array;
 }
Beispiel #3
0
 public static function insertMiddle($data)
 {
     try {
         $manager = new TxManager();
         $transaction = $manager->get();
         foreach ($data as $key => $value) {
             $middle = new MiddleLayer();
             $middle->setTransaction($transaction);
             foreach ($value as $skey => $svalue) {
                 $middle->{$skey} = $svalue;
             }
             if ($middle->save() == false) {
                 $transaction->rollback('数据更新失败-3');
             }
         }
         $transaction->commit();
         return true;
     } catch (TxFailed $e) {
         throw new Exception($e->getMessage());
     }
 }