Beispiel #1
0
 public static function delModule($project_id)
 {
     try {
         $delete_data = ProjectDetail::findFirst(array('project_id = :project_id:', 'bind' => array('project_id' => $project_id)));
         if (isset($delete_data->project_id)) {
             $manager = new TxManager();
             $transaction = $manager->get();
             $delete_data->setTransaction($transaction);
             if ($delete_data->delete() == false) {
                 $transaction->rollback('数据更新失败-1');
             }
             #说明该项目下需求量表已导入过,则继续更新项目状态
             $project = Project::findFirst(array("id=?1", 'bind' => array(1 => $project_id)));
             $project->setTransaction($transaction);
             $project->state = $project->state - 1 >= 0 ? $project->state - 1 : 0;
             if ($project->save() == false) {
                 $transaction->rollback("数据插入失败-2");
             }
             $transaction->commit();
             return true;
         } else {
             return true;
         }
     } catch (TxFailed $e) {
         throw new Exception($e->getMessage());
     }
 }
 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 getComprehensiveData($project_id)
 {
     $this->project_check($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_name_array = array("心理健康" => '职业心理', "素质结构" => '职业素质', "智体结构" => '智体结构', "能力结构" => '职业能力');
     $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('AVG(IndexAns.score) as score', 'Index.chs_name as chs_name', 'Index.id as id'))->from('Examinee')->join('IndexAns', 'IndexAns.examinee_id = Examinee.id AND Examinee.type = 0 AND Examinee.project_id = ' . $project_id)->join('Index', 'Index.id = IndexAns.index_id')->inwhere('Index.name', $children_array)->groupBy('Index.name')->orderBy('AVG(IndexAns.score) desc')->getQuery()->execute();
         $tmp = array();
         $tmp['children'] = $result_1->toArray();
         $count = count($result_1);
         $sum = 0;
         foreach ($tmp['children'] as &$svalue) {
             $sum += sprintf('%.2f', $svalue['score']);
         }
         if ($count == 0) {
             throw new Exception('系统错误-模块下属指标的数量为0');
         }
         $tmp['value'] = sprintf('%.2f', $sum / $count);
         $tmp['name'] = $module_name_array[$key];
         $tmp['name_in_table'] = $value;
         $module_array_score[] = $tmp;
     }
     return $module_array_score;
 }
 public function getmoduleAction()
 {
     $manager = $this->session->get('Manager');
     if ($manager) {
         $result = array();
         $result['state'] = false;
         $result['ans'] = null;
         $project_detail = ProjectDetail::findFirst(array("project_id=?1", "bind" => array(1 => $manager->project_id)));
         if (!isset($project_detail->project_id)) {
             $this->dataReturn(array('success' => $result));
             return;
         }
         $module_name = array();
         $module_names = $project_detail->module_names;
         $module_name = explode(',', $module_names);
         if (empty($module_name)) {
             $this->dataReturn(array('success' => $result));
             return;
         }
         $ans = array();
         foreach ($module_name as $name) {
             $module = Module::findFirst(array('name=?1', 'bind' => array(1 => $name)));
             $ans[] = $module->chs_name;
         }
         $result['state'] = true;
         $result['ans'] = implode('|', $ans);
         $this->dataReturn(array("success" => $result));
         return;
     } else {
         $this->dataReturn(array('error' => "您的身份验证出错,请重新登录"));
         return;
     }
 }
 public static function getSPMdata($examinee_info)
 {
     $projectdetail = ProjectDetail::findFirst(array('project_id=?1', 'bind' => array(1 => $examinee_info->project_id)));
     $factors = json_decode($projectdetail->factor_names, true);
     if (!isset($factors['SPM'])) {
         return null;
     }
     $ans = array();
     foreach ($factors['SPM'] as $key => $value) {
         $inner_array = array();
         $factor_info = Factor::findFirst($key);
         $inner_array['chs_name'] = $factor_info->chs_name;
         $factor_score_info = FactorAns::findFirst(array('factor_id = ?1 AND examinee_id =?2', 'bind' => array(1 => $key, 2 => $examinee_info->id)));
         $inner_array['std_score'] = intval($factor_score_info->std_score);
         $inner_array['score'] = $factor_score_info->score;
         //$inner_array['name'] = $factor_info->name;
         $ans[$factor_info->name] = $inner_array;
     }
     return $ans;
 }
 /**
  * @type: 多次更改
  * @method $rt->module_names, $rt->index_names, $rt->factor_names, $rt->exam_json; ok
  * @usage 用于缓存通过project_id获取到的ProjectDetail表中的数据
  * @return \Phalcon\Mvc\Model\Resultset\Simple
  * @param int $project_id
  */
 public static function getProjectDetail($project_id)
 {
     self::checkConnect();
     return ProjectDetail::findFirst(array("project_id = :project_id:", 'bind' => array('project_id' => $project_id), 'hydration' => \Phalcon\Mvc\Model\Resultset\Simple::HYDRATE_ARRAYS, 'cache' => array('key' => 'project_detail_id_' . $project_id)));
 }
 public function IsHidden($examinee_id)
 {
     $factor_name = 'epqal';
     $project_id = $this->self_check($examinee_id);
     //判断项目是否选中该因子
     $factor_id = '';
     $factor_info = ProjectDetail::findFirst(array("project_id = :project_id:", 'bind' => array('project_id' => $project_id)));
     $factor_names = json_decode($factor_info->factor_names, true);
     if (isset($factor_names['EPQA'])) {
         if (!in_array($factor_name, $factor_names['EPQA'])) {
             return true;
         } else {
             $new_array = array_flip($factor_names['EPQA']);
             $factor_id = $new_array[$factor_name];
         }
     } else {
         return true;
     }
     //存在的情况下进行项目整体判断
     $result = $this->modelsManager->createBuilder()->columns(array('avg(FactorAns.score) as avg'))->from('Examinee')->join('FactorAns', 'Examinee.id = FactorAns.examinee_id and  Examinee.project_id = ' . $project_id)->join('Factor', "Factor.id = FactorAns.factor_id AND Factor.name = '{$factor_name}'")->getQuery()->execute();
     $average = $result->toArray()[0]['avg'];
     $result = FactorAns::findFirst(array('factor_id = ?1 AND examinee_id = ?2', 'bind' => array(1 => $factor_id, 2 => $examinee_id)));
     $person_score = $result->score;
     if ($person_score <= $average) {
         return true;
     } else {
         return false;
     }
 }