public function writeprojectdetailAction() { try { $manager = $this->session->get('Manager'); $project_id = $manager->project_id; #添加项目判断,是否有被试答题,若有答题则不能更新配置的模块 $result = $this->modelsManager->createBuilder()->columns(array('COUNT(Examinee.id) as count'))->from('Examinee')->join('QuestionAns', 'Examinee.id = QuestionAns.examinee_id AND Examinee.project_id = ' . $project_id)->getQuery()->execute(); $result = $result->toArray(); if ($result[0]['count'] > 0) { $this->dataReturn(array('error' => '已有被试答题,项目模块不可再修改!')); return; } if ($manager) { $module_names = array(); $checkeds = $this->request->getpost('checkeds'); $values = $this->request->getpost('values'); $i = 0; foreach ($checkeds as $value) { if ($value == 'true') { $module_names[] = PmDB::getModuleName($values[$i]); } $i++; } #全选情况 $project_detail_info = array(); $index_names = array(); if (count($module_names) == 10) { $index = Index::find(); foreach ($index as $index_record) { $index_names[] = $index_record->name; } $factor = Factor::find(); $factor_names = array(); foreach ($factor as $factor_record) { $factor_names[] = $factor_record->name; } $question = Question::find(); $examination = array(); foreach ($question as $question_record) { $paper_name = Paper::findFirst($question_record->paper_id)->name; $examination[$paper_name][] = $question_record->number; } $project_detail_info['exam_json'] = json_encode($examination, JSON_UNESCAPED_UNICODE); } else { #所有相关指标名数组 $index_names = PmDB::getIndexName($module_names); #所有相关因子名数组 $factor_names = PmDB::getFactorName($index_names); #所有相关试卷下题目的数组 $examination = PmDB::getQuestionName($factor_names); $project_detail_info['exam_json'] = json_encode($examination, JSON_UNESCAPED_UNICODE); } #因子分类 以及寻找子因子 $factors = PmDB::getAllDividedFactors($factor_names); $project_detail_info['factor_names'] = json_encode($factors, JSON_UNESCAPED_UNICODE); $project_detail_info['module_names'] = implode(',', $module_names); $project_detail_info['index_names'] = implode(',', $index_names); $project_detail_info['project_id'] = $project_id; #插入到project_detail 并更新状态 PmDB::insertProjectDetail($project_detail_info); #模块配置的类型设为true #需求量表的上传设为false $this->dataReturn(array('success' => true)); return; } else { $this->dataBack(array('error' => "您的身份验证出错!请重新登录!")); return; } } catch (Exception $e) { $this->dataReturn(array('error' => $e->getMessage())); return; } }
/** * @type 不更改 * @method $rt->id, $rt->description; ok * @param string $paper_name */ public static function getPaperDetail($paper_name) { self::checkConnect(); return Paper::findFirst(array("name = :name:", 'bind' => array('name' => $paper_name), 'hydration' => \Phalcon\Mvc\Model\Resultset\Simple::HYDRATE_ARRAYS, 'cache' => array('key' => 'paper_detail_name_' . $paper_name))); }
/** * 更新paper表数据 * 主要是更新Paper表中的行记录,通过比照name,更新description * @param unknown $data * ture 更新成功 * false|Exception 更新失败 */ public static function updatePaperData() { $data = Paper::getLastedDataFromModel(); $data_type = self::dataFormatCheck($data); if ($data_type != 5) { throw new Exception("input type is not available!"); } $raw_data_count = Paper::count(); if ($raw_data_count != count($data)) { throw new Exception("Please ensure the data[from table and from array] consistency"); } try { $manager = new TxManager(); $transaction = $manager->get(); foreach ($data as $record) { $paper_table_record = Paper::findFirst(array("name = :name:", 'bind' => array('name' => strtoupper(trim($record['name']))))); if (isset($paper_table_record->id)) { if (strcmp($paper_table_record->description, $record['description']) != 0) { $paper = new Paper(); $paper->id = $paper_table_record->id; $paper->description = $record['description']; $paper->name = strtoupper(trim($record['name'])); if ($paper->update() == false) { $transaction->rollback("Cannot update Paper data"); } } } } $transaction->commit(); return true; } catch (TxFailed $e) { throw new Exception("Failed, reason: " . $e->getMessage()); } }
/** * @usage input 因子名数组 * @return 所有分类下的因子数组 */ public static function getAllDividedFactors($factor_names) { $factors = array(); foreach ($factor_names as $factor_name) { $factor = Factor::findFirst(array('name=?1', 'bind' => array(1 => $factor_name))); $paper_name = Paper::findFirst($factor->paper_id)->name; $factors[$paper_name][$factor->id] = $factor_name; $children_type_array = explode(',', $factor->children_type); #因子至多两层 if (in_array(0, $children_type_array)) { $factor = explode(',', $factor->children); foreach ($factor as $value) { $zi_factor = Factor::findFirst(array('name=?1', 'bind' => array(1 => $value))); $factors[$paper_name][$zi_factor->id] = $value; } } } return $factors; }