public function homeAction() { // action body // echo $_COOKIE["account"]; // print_r( $this->cookie); $imgpath = $_SERVER['DOCUMENT_ROOT'] . "/WebOne/public/image/head/"; $id = $_SESSION["userinfo"][0][id]; // print_r($_SESSION["userinfo"][0]); $userinfo = new userinfoModel(); $db = $userinfo->getAdapter(); $user = $db->query('SELECT * FROM userinfo where userid=?', $id)->fetchAll()[0]; $activitys = new ActivityModel(); $db1 = $activitys->getAdapter(); $hotactivity = $db1->query('select * from activity order by nums desc limit 0,1')->fetchAll()[0]; $questions = new QuestionModel(); $db2 = $questions->getAdapter(); $hotquestion = $db2->query('select * from question order by answernum desc limit 0,1')->fetchAll()[0]; if (file_exists($imgpath . $id . ".jpg")) { $this->view->path = $baseUrl . "/WebOne/public/image/head/" . $id . ".jpg"; } else { $this->view->path = $baseUrl . "/WebOne/public/image/initial.jpg"; } $userid = $hotquestion[userid]; $Usertable = new UserModel(); $db3 = $Usertable->getAdapter(); $name = $db3->query('select name from User where id=?', $userid)->fetchAll()[0][name]; $this->view->user = $user; $this->view->info = $_SESSION["userinfo"]; $this->view->activity = $hotactivity; $this->view->question = $hotquestion; $this->view->name = $name; }
public static function last() { $row = parent::last(QuestionModel::get_table_name()); $qm = new QuestionModel($row["page_id"], $row["q_and_a"], $row["date_created"]); $qm->id = $row["id"]; return $qm; }
public static function delete(array $restOfRoute) { RecruiterController::requireLogin(); $jobId = self::getIdFromRoute($restOfRoute); if (is_null($jobId)) { return; } // Make sure job exists. // Make sure recruiter has permission to edit the job. if (!self::checkJobExists($jobId)) { return; } if (!self::ownsJob($jobId)) { return; } // Delete all applications with jobid. ApplicationModel::deleteByJob($jobId); // Delete from questions' uses this jobid. $application = ApplicationJob::get($jobId); $questions = []; if (!is_null($application)) { $questions = $application->getQuestions(); } foreach ($questions as $questionId) { QuestionModel::removeFromUses($questionId, $jobId); } // Delete this job. JobModel::deleteById($jobId); // Redirect back to home. self::redirect('../home'); }
public function actionDeleteQuestion($id) { $model = QuestionModel::model()->findByPk($id); $userQuestion = UserQuestion::model()->findByAttributes(['question_id' => $id]); if ($model) { $model->delete(); } if ($userQuestion) { $userQuestion->delete(); } }
public function delete($id) { if (!$this->check_power('skill_delete')) { return; } $id = intval($id); $id && ($row = SkillModel::get_skill($id)); if (empty($row)) { message('技能不存在'); return; } if (!QuestionModel::check_subject_power($row['subject_id'], 'w')) { return; } $this->db->delete('skill', array('id' => $id)); admin_log('delete', 'skill', $id); message('技能删除成功', 'admin/skill/index/'); }
/** * 批量取消审核 * * @return void */ public function batch_unshenhe() { $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要取消审核的题目!'); } $success = $fail = 0; foreach ($ids as $id) { $be_tested = QuestionModel::question_has_test_action($id); $question = QuestionModel::get_question($id); if ($be_tested || !$this->has_question_check($question) || $question['is_original'] != 1 || $question['check'] != 1) { $fail++; continue; } $sql = "update {pre}question set `check`=0 where ques_id='{$id}'"; $return = $this->db->query($sql); if ($return === true) { $liyo = 'unexamine'; admin_log($liyo, 'question', $id); $success++; } else { $fail++; } } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/question_audit/index'; message('批量操作完成,成功取消审核:' . $success . ' 个,失败:' . $fail . ' 个。', $back_url); }
<?php /** * @var Answer $model * @var QuestionModel $qM * @var CActiveForm $form */ $model = UserModel::model()->client()->findByPk(Yii::app()->user->id); $this->widget('zii.widgets.CDetailView', array('data' => $qM, 'attributes' => array(array('name' => 'title', 'value' => $qM->title ? $qM->title : null), array('name' => 'text', 'value' => $qM->text ? $qM->text : null), array('name' => 'date_add', 'value' => $qM->date_add ? $qM->date_add : null), array('name' => 'city', 'value' => $qM->city ? $qM->city : null), array('name' => 'id', 'value' => $qM->id ? $qM->id : null), array('name' => 'type', 'value' => QuestionModel::model()->arr_type[$qM->type])))); if ($qM->addQuestions) { $i = 1; foreach ($qM->addQuestions as $k => $addQuestion) { if ($addQuestion->jurist_id !== null) { ?> <h1 style="text-align: center; font-size: 24px">Дополнительные вопрос №<?php echo $i; ?> </h1> <?php $this->widget('zii.widgets.CDetailView', array('data' => $addQuestion, 'attributes' => array(array('name' => 'text', 'type' => 'html', 'value' => $addQuestion->text ? $addQuestion->text : null), array('name' => 'jurist_id', 'value' => $addQuestion->jurist_id ? AddQuestion::fioById($addQuestion->jurist_id) : null)))); $i++; } } } if ($qM->answer) { ?> <h1 style="text-align: center; font-size: 24px">Ответы Юристов</h1> <?php $this->widget('zii.widgets.grid.CGridView', array('dataProvider' => $dataProvider, 'columns' => [['name' => 'id', 'visible' => false], ['name' => 'user.info.avatar', 'type' => 'html', 'value' => function ($data) { if ($data->user && $data->user->info) { return CHtml::image($data->user->info->avatar ? '/uploads/profile/images/' . $data->user->info->avatar : 'https://s0.pravoved.ru/images/design/avatar_large_male_lawyer_default.jpg?s=000d57bb83d9d26ee3a264550dec70d5', '', ['style' => 'height: 150px;']);
/** * @description 更新试卷统计 * @author * @final * @param int $id 试卷id */ public function renew($id = 0) { $id = intval($id); $exam_id = ExamPaperModel::get_paper($id, 'exam_id'); if (empty($exam_id)) { message('试卷不存在'); return; } if (QuestionModel::paper_has_test_action($id)) { message('该试卷已经被考生考过 或者 正在被考中,因此无法操作'); return; } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/paper/index/' . $exam_id; if (ExamPaperModel::renew($id)) { message('更新成功', $back_url); } else { message('更新失败'); } }
/** * Returns comparison information based on criteria arguments. Virtual questions always return an empty array. * * @param array See argument array below * @return array Following this structure: * array($criteria_term => array(array('question' => QuestionModel, * 'messages' => array(string) * ) * ) * ) */ public function compare($args = array()) { // Comparison criteria $args = array_merge(array('model_fail' => true, 'model_pass' => false, 'additional_information' => false), $args); if ($this->question->virtualQuestion) { return array(); } if ($this->compareInstance->depth !== 'response') { throw new Exception('Comparison not possible since compare instance depth not set to response'); } if ($this->depth !== 'response') { throw new Exception('Comparison not possible since depth not set to response'); } $modelPageRows = self::$pageTable->fetchRows('pageID', $this->question->pageID, null, $this->question->instanceID); $modelPageRow = $modelPageRows[0]; $pageGUID = $modelPageRow->pageGUID; $comparePageRows = self::$pageTable->fetchRows('pageGUID', $pageGUID, null, $this->compareInstance->instanceID); $comparePageRow = $comparePageRows[0]; $compareQuestionRows = self::$questionTable->fetchRows('questionGUID', $this->question->questionGUID, null, $comparePageRow->pageID); $compareQuestionRow = $compareQuestionRows[0]; $compareQuestion = new QuestionModel(array('questionID' => $compareQuestionRow->questionID, 'depth' => 'response')); $response = $compareQuestion->getResponse(); $result = array(); foreach ($args as $key => $value) { $result[$key] = array(); } if ($args['model_fail'] || $args['model_pass']) { $messages = array(); $remediationInfo = ''; $pass = null; while ($modelResponse = $this->nextModelResponse()) { switch ($modelResponse->type) { case "no preference": break; case "match": if ($modelResponse->target == $response->responseText) { $messages['pass'][] = "Matches " . $modelResponse->target; $pass = true; } else { $messages['fail'][] = "Does not match " . $modelResponse->target; $pass = false; break; } break; case "selected": if ($modelResponse->promptText() == $response->promptText()) { $messages['pass'][] = "Prompt selected: " . $modelResponse->promptText(); $pass = true; } else { $messages['fail'][] = "Prompt not selected: " . $modelResponse->promptText(); $pass = false; break; } break; case "not selected": if ($modelResponse->promptText() == $response->promptText()) { $messages['fail'][] = "Prompt selected: " . $modelResponse->promptText(); $pass = false; break; } else { $messages['pass'][] = "Prompt not selected: " . $modelResponse->promptText(); $pass = true; } break; case "or selected": if ($modelResponse->promptText() == $response->promptText()) { $messages['pass'][] = "Or prompt selected: " . $modelResponse->promptText(); $pass = true; } else { if ($pass !== TRUE) { $messages['fail'][] = "And prompt not selected: " . $modelResponse->promptText(); $pass = false; } } break; case "remediation info": $remediationInfo = $modelResponse->info; break; case "require attachment": $file = new FileModel($compareQuestion); if ($file->hasAttachment()) { $pass = true; $messages['pass'][] = 'Has attachment'; } else { $pass = false; $messages['fail'][] = 'No attachment'; } break; default: throw new Exception('Unknown model response type'); } } if ($pass === TRUE && $args['model_pass']) { $result['model_pass'][] = array('question' => $compareQuestion, 'messages' => $messages['pass'], 'remediation_info' => $remediationInfo); } if ($pass === FALSE && $args['model_fail']) { $result['model_fail'][] = array('question' => $compareQuestion, 'messages' => $messages['fail'], 'remediation_info' => $remediationInfo); } } if ($args['additional_information'] && (!$args['model_fail'] || count($result['model_fail']) === 0) && strlen($response->additionalInfo) > 0) { if ($args['model_pass'] === TRUE) { $result['model_pass'] = array(); } $result['additional_information'][] = array('question' => $compareQuestion); } return $result; }
private function _delete($id) { $id = intval($id); $item = GroupTypeModel::get_group_type($id); if (empty($item)) { // 知识点不存在 return -1; } $query = $this->db->select('count(*) num')->get_where('group_type', array('pid' => $id)); $row = $query->row_array(); if ($row['num']) { //该信息提取方式还存在下级分类; return -2; } $query = $this->db->select('count(*) num')->get_where('relate_group_type', array('group_type_id' => $id, 'is_child' => 0)); $row = $query->row_array(); if ($row['num']) { //该信息提取方式还存在关联试题; return -3; } if (!QuestionModel::check_subject_power($item['subject_id'], 'w', false)) { //没有权限 return -4; } try { $this->db->delete('group_type', array('id' => $id)); admin_log('delete', 'group_type', $id); } catch (Exception $e) { return FALSE; } return TRUE; }
<div class="row"> <?php echo $form->labelEx($model, 'text'); ?> <?php echo $form->textArea($model, 'text'); ?> <?php echo $form->error($model, 'text'); ?> </div> <div class="row"> <?php echo $form->radioButtonList($model, 'type', QuestionModel::model()->arr_type); ?> </div> <div class="row" id="cost"> <?php echo $form->labelEx($model, 'cost'); ?> <?php echo $form->textField($model, 'cost'); ?> <?php echo $form->error($model, 'cost'); ?> </div>
/** * Saves the page currently being edited */ public function saveAction() { try { $page = new PageModel(array('pageID' => $this->_getParam('id'), 'depth' => 'page')); $lock = $this->lockPage($page, 'edit'); $attachments = array(); $auth = Zend_Auth::getInstance(); $user = DbUserModel::findByUsername($auth->getIdentity()); $responses = array(); foreach ($this->_getAllParams() as $key => $value) { // if the element's name begins 'qXXX' where X is a digit if (preg_match('/^q(\\d+)(.*)$/', $key, $matches)) { $questionID = intval($matches[1]); $remainder = $matches[2]; // if the element name consists of *only* 'qXXX' or qXXX_mXXX for multiple select question types if ($remainder == '' || preg_match('/^_m(\\d+)$/', $remainder)) { $q = new QuestionModel(array('questionID' => $questionID)); $response = $q->getResponse(); if ($response->state == 2) { $this->flash('error', 'You cannot modify a response that has been approved'); $this->_redirector->gotoRouteAndExit(array('action' => 'view', 'id' => $page->pageID)); } if (strlen($value) > 0) { $responses[$questionID]['value'][] = $value; } } elseif ($remainder == "_addl_mod" && intval($this->_getParam("q{$questionID}_addl_mod"))) { $responses[$questionID]['addl'] = $this->_getParam("q{$questionID}_addl"); } elseif ($remainder == "_privateNote_mod" && intval($this->_getParam("q{$questionID}_privateNote_mod"))) { $responses[$questionID]['pNote'] = $this->_getParam("q{$questionID}_privateNote"); } elseif ($remainder == '_attachments') { $question = new QuestionModel(array('questionID' => $questionID)); foreach ($value as $file) { $fileModel = new FileModel($question); $properties = Spyc::YAMLLoad(PROJECT_PATH . '/tmp/.' . $file); $fileModel->storeFilename(PROJECT_PATH . '/tmp/' . $file, $properties); } } elseif (preg_match('/^_file(\\d+)_delete$/', $remainder, $matches) && $value === 'true') { $question = new QuestionModel(array('questionID' => $questionID)); $fileModel = new FileModel($question); $fileModel->delete(intval($matches[1])); } } } foreach ($responses as $questionID => $data) { $q = new QuestionModel(array('questionID' => $questionID)); $response = $q->getResponse(); if (isset($data['value'])) { $response->responseText = join(',', $data['value']); } if (isset($data['addl'])) { $response->additionalInfo = $data['addl']; } if (isset($data['pNote'])) { $response->privateNote = $data['pNote']; } $response->save($user); } /* If there are any file uploads that didn't auto-upload before the user saved */ foreach ($_FILES as $name => $file) { if ($file['size'] > 0) { $question = new QuestionModel(array('questionID' => intVal($name))); $fileModel = new FileModel($question); $properties = array('filename' => $file['name'], 'mime' => $file['type']); $fileModel->storeFilename($file['tmp_name'], $properties); } } $page = new PageModel(array('pageID' => $this->_getParam('id'), 'depth' => 'response')); $page->save(); $instance = new InstanceModel(array('instanceID' => $page->instanceID, 'depth' => 'page')); $instance->save(); } catch (Exception $e) { $this->view->error = $e->getMessage(); } $this->view->setRenderLayout(false); }
/** * Helper function for save() to update the uses of questions and delete * unused questions. */ private static function updateQuestionUses(MongoId $jobId, array $oldQuestions, array $newQuestions) { $commonQuestions = array_intersect($newQuestions, $oldQuestions); $removedQuestions = array_diff($oldQuestions, $commonQuestions); $addedQuestions = array_diff($newQuestions, $commonQuestions); foreach ($removedQuestions as $questionId) { QuestionModel::removeFromUses($questionId, $jobId); } foreach ($addedQuestions as $questionId) { QuestionModel::addToUses($questionId, $jobId); } }
/** * 批量删除试卷中的试题 * * @param int $paper_id 试卷id * @param int $ids 试卷中的试题id * @return void */ public function batch_delete() { if (!$this->check_power('exam_manage')) { return; } $paper_id = (int) $this->input->post('paper_id'); $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要操作的项目!'); return; } $paper = PaperModel::get_paper_by_id($paper_id); if (!$paper) { message('试卷不存在'); return; } $exam_pid = ExamModel::get_exam($paper['exam_id'], 'exam_pid'); $is_mini_test = ExamModel::is_mini_test($exam_pid); //判断该试卷已经被考试过 或 正在被考 $count_fail = 0; $count_success = 0; $tmp_ids = array(); foreach ($ids as $ques_id) { if (!$is_mini_test) { $be_tested = QuestionModel::paper_question_has_been_tested($paper_id, $ques_id); if ($be_tested) { $count_fail++; continue; } } $tmp_ids[] = $ques_id; $count_success++; } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/exam_question/index/' . $paper_id; $this->db->where_in('id', $tmp_ids)->delete('exam_question'); ExamPaperModel::renew($paper_id); if ($is_mini_test && $count_success) { SummaryModel::summary_paper($exam_pid, 0, $paper_id, true); } message("批量操作完成(成功 {$count_success}个,失败 {$count_fail} 个)", $back_url); }
public function EditQuestionAction() { $request = Project::getRequest(); $id = $request->getKeyByNumber(0); $data = array(); if (!$request->getKeyByNumber(1)) { if ($id > 0) { $model = new QuestionModel(); $cat_model = new QuestionCatModel(); $tag_model = new QuestionTagModel(); $data['question'] = $model->load($id); $data['cat_list'] = $cat_model->loadAll(); $tags_model = new QuestionTagModel(); $tags = $tags_model->loadWhere(null, null, $id); foreach ($tags as $tag) { $data['tags'] .= $tag['name'] . ', '; } $data['tags'] = rtrim($data['tags'], ', '); $this->BaseAdminData(); $this->_view->EditQuestion($data); $this->_view->ajax(); } } else { if ($id > 0) { $model = new QuestionModel(); $model->load($id); $model->q_text = $request->question_text; $model->questions_cat_id = (int) $request->cat_id; $id = $model->save(); $tag_model = new QuestionTagModel(); $question_tag_model = new QTagModel(); $tags_ar = array(); $tags_ar = explode(",", $request->tags); foreach ($tags_ar as $tag) { $tag = trim($tag); if (count($tag_model->loadByName($tag)) > 0) { if (count($question_tag_model->loadWhere($id, $tag_model->id)) <= 0) { $question_tag_model->question_id = $id; $question_tag_model->question_tag_id = $tag_model->id; $question_tag_model->save(); $question_tag_model->clear(); } } else { $tag_model->name = $tag; $tag_id = $tag_model->save(); $tag_model->clear(); $question_tag_model->question_id = $id; $question_tag_model->question_tag_id = $tag_id; $question_tag_model->save(); $question_tag_model->clear(); } } } Project::getResponse()->Redirect($request->createUrl('AdminQuestionAnswer', 'QuestionList')); } }
<li class=""> <a style="<?php echo $addQuestion ? 'background-color: rgba(163, 9, 15, 0.79)' : null; ?> " href="<?php echo $url; ?> ">Уточнения</a> </li> </ul> <?php } elseif ($client = UserModel::model()->client()->findByPk($app->user->id)) { if ($client->id != 1) { $addQuestionClient = AddQuestion::model()->findByAttributes(['status' => 0, 'client_id' => $app->user->id]); $question = QuestionModel::model()->findAllByAttributes(['user_id' => $client->id, 'status' => QuestionModel::STATUS_CLOSE]); $urlClient = $app->createUrl('#'); $urlQuestion = $app->createUrl('#'); if ($addQuestionClient) { $urlClient = $app->createUrl('question/answer', ['id' => $addQuestionClient->q_id]); } if ($question) { $urlQuestion = $app->createUrl('question/close'); } ?> <ul class="newMenu unregistered"> <li class="order dropdown"> <span>Заказать услугу</span> <ul class="hidden"> <li class="orderQuestion"><a href="/question/add/">Задать вопрос</a></li> <li class="orderDoc"><a href="/document/add">Заказать документ</a></li>
public function myquestionAction() { $page = $this->getRequest()->getParam('page'); $account = $_COOKIE["account"]; $usertable = new UserModel(); $db1 = $usertable->getAdapter(); $questiontable = new QuestionModel(); $db2 = $questiontable->getAdapter(); //查找当前用户ID $result = $usertable->fetchRow($db1->quoteInto('email = ?', $account))->toArray(); $uid = $result['id']; //查找用户question // $questions = $questiontable-> fetchRow($db2->quoteInto('userid = ?', $uid)) ->toArray(); $num = $db2->query('SELECT COUNT(*) as num FROM question,User WHERE question.userid = User.id and User.id =? order by time desc', $uid)->fetchAll()[0][num]; //$num=count($questions); $pages = ceil($num / 3); if ($page == "") { $page = 0; } //确定页面显示的规范 处理分页的逻辑 if ($page < 3) { if ($pages > 3) { $set = array(1, 2, 3, 4); } else { $set = array(); for ($i = 1; $i <= $pages; $i++) { $set[] = $i; } } } else { if ($page >= 3) { if ($page + 3 <= $pages) { $set = array($page, $page + 1, $page + 2, $page + 3); } else { $set = array(); for ($i = $page; $i <= $pages; $i++) { $set[] = $i; } } } } $where = $db2->quoteInto('userid=?', $uid); $order = 'begin desc'; $count = 3; $offset = $page * 3; $questions = $questiontable->fetchAll($where, $order, $count, $offset)->toArray(); $this->view->results = $questions; $this->view->user = $result; $this->view->page = $page; $this->view->count = $set; }
function viewQuestionPage($user_id) { /* $htmlPage = ' <table class="questions"> <tr> <td style="width: 100%; text-align: left;"><b>Вопросы пользователей</b></td> <td><b>Автор</b></td> <!--<td><b>Ответов</b></td>--> <td><b>Дата создания</b></td> </tr>'; */ $user_id = (int) $user_id; $questionModel = new QuestionModel(); $aQuestions = $questionModel->loadWhere(); $htmlPage = '<ul class="question-preview-list clearfix">'; foreach ($aQuestions as $question) { /* $htmlPage .= ' <tr id="cmod_tab2"> <td style="width: 100%; text-align: left;"><img height="14" width="14" id="ico2" src="'.$this->image_url.'faq.png"/> <a href="'.Project::getRequest()->createUrl('QuestionAnswer', 'ViewQuestion').'/'.$question['id'].'">'.$question['q_text'].'</a></td> <td><a href="'.UserController::getProfileUrl($question['login']).'">'.$question['login'].'</a></td> <!--<td>'.$question['a_count'].'</td>--> <td>'.$question['creation_date'].'</td> </tr> '; */ $htmlPage .= '<li> <dl> <dt><a href="' . UserController::getProfileUrl($question['login']) . '" class="with-icon-s"><i class="icon-s user-icon"></i>' . $question['login'] . '</a> спрашивает</dt> <dd class="question"><a href="' . Project::getRequest()->createUrl('QuestionAnswer', 'ViewQuestion') . '/' . $question['id'] . '">' . $question['q_text'] . '</a></dd> <dd class="reply"><a href="' . Project::getRequest()->createUrl('QuestionAnswer', 'ViewQuestion') . '/' . $question['id'] . '">' . $question['a_count'] . ' ответов</a></dd> </dl> </li>'; } // $htmlPage .= '</table>'; $htmlPage .= '</ul>'; return $htmlPage; }
public function batch_relate() { if (!$this->check_power('interview_question_manage')) { return; } $back_url = empty($_SERVER['HTTP_REFERER']) ? 'admin/interview_question/index' : $_SERVER['HTTP_REFERER']; $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要关联的项目!'); return; } // 检查被关联试题 $relate_ques_id = intval($this->input->post('relate_ques_id')); $relate_ques_id && ($relate_ques = QuestionModel::get_question($relate_ques_id)); if (empty($relate_ques)) { message('被关联试题不存在。'); return; } // 如果被关联试题无分组,则:创建分组,并把该试题加入关联 $group_id = $relate_ques['group_id']; if (empty($group_id)) { $this->db->insert('relate_group', array('group_name' => $relate_ques_id)); $group_id = $this->db->insert_id(); $this->db->update('question', array('group_id' => $group_id), array('ques_id' => $relate_ques_id)); } $success = $fail = 0; foreach ($ids as $id) { $num = $this->_relate($id, $group_id); if ($num > 0) { $success += $num; } else { $fail++; } } message('批量操作完成,成功关联:' . $success . ' 个,失败:' . $fail . ' 个。', $back_url); }
/** * Update any disable rules associated with this response. */ private function updateDisableRules() { if (!isset($this->parent)) { $this->parent = new QuestionModel(array('questionID' => $this->responseRow->questionID, 'depth' => 'question')); } $question = $this->parent; foreach ($question->prompts as $prompt) { foreach ($prompt['rules'] as $rule) { if ($prompt['promptID'] == $this->responseText) { if ($rule->enabled != 'Y') { $rule->enabled = 'Y'; $rule->save(); if (preg_match('/.+Page$/', $rule->type)) { $page = new PageModel(array('pageID' => $rule->targetID, 'depth' => 'question')); $page->save(); } elseif (preg_match('/.+Section$/', $rule->type)) { $section = new SectionModel(array('sectionID' => $rule->targetID, 'depth' => 'question')); $section->save(); } elseif (preg_match('/.+Question$/', $rule->type)) { $question = new QuestionModel(array('questionID' => $rule->targetID, 'depth' => 'question')); $question->save(); } } } else { if ($rule->enabled != 'N') { $rule->enabled = 'N'; $rule->save(); if (preg_match('/.+Page$/', $rule->type)) { $page = new PageModel(array('pageID' => $rule->targetID, 'depth' => 'question')); $page->save(); } elseif (preg_match('/.+Section$/', $rule->type)) { $section = new SectionModel(array('sectionID' => $rule->targetID, 'depth' => 'question')); $section->save(); } elseif (preg_match('/.+Question$/', $rule->type)) { $question = new QuestionModel(array('questionID' => $rule->targetID, 'depth' => 'question')); $question->save(); } } } } } }
/** * 获取试卷信息 * @param int $paper_id * @return array */ private function _paper($paper_id) { if (!$paper_id) { return array(); } $paper = ExamPaperModel::get_paper($paper_id); if (empty($paper)) { return array(); } $exam = ExamModel::get_exam($paper['exam_id'], 'grade_id, class_id, subject_id, qtype_score, total_score'); if (empty($exam)) { return array(); } // 分数计算 $score = array(); // 题目数量 $question_num = explode(',', $paper['qtype_ques_num']); // 题型分数 $qtype_score = explode(',', $exam['qtype_score']); // 总分 排除题组 $total_score = 0; foreach ($qtype_score as $key => $value) { $score[$key + 1]['score'] = $value; $score[$key + 1]['num'] = isset($question_num[$key + 1]) ? $question_num[$key + 1] : 0; $score[$key + 1]['total_score'] = $score[$key + 1]['score'] * $score[$key + 1]['num']; $total_score += $score[$key + 1]['score'] * $score[$key + 1]['num']; } // 题组总分 $total_0 = $exam['total_score'] - $total_score; $data = array(); $data['exam'] = $exam; $data['score'] = $score; $data['total_0'] = $total_0; if ($exam['subject_id'] == 3) { $group = array(1 => array(), 4 => array(), 0 => array(), 5 => array(), 6 => array(), 7 => array(), 2 => array(), 3 => array(), 8 => array(), 9 => array()); } else { $group = array(1 => array(), 2 => array(), 3 => array(), 0 => array()); } /** 题组分值系数总和 */ $sql = "SELECT sum(score_factor) as sum FROM {pre}question q\n LEFT JOIN {pre}exam_question eq ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=q.ques_id\n AND rc.grade_id = {$exam['grade_id']} AND rc.class_id = {$exam['class_id']}\n WHERE eq.paper_id = {$paper_id} and q.type=0"; $query = $this->db->query($sql); $sum_score_factor = $query->row_array(); $sql = "SELECT q.ques_id,q.type,q.title,q.picture,q.answer,q.score_factor,q.children_num,rc.difficulty\n FROM {pre}exam_question eq\n LEFT JOIN {pre}question q ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id = q.ques_id AND rc.grade_id = {$exam['grade_id']}\n AND rc.class_id = {$exam['class_id']}\n WHERE eq.paper_id = {$paper_id} ORDER BY rc.difficulty DESC,q.ques_id ASC"; $query = $this->db->query($sql); foreach ($query->result_array() as $row) { $row['title'] = $this->_format_question_content($row['title'], in_array($row['type'], array(3, 9))); switch ($row['type']) { case 0: $row['children'] = QuestionModel::get_children($row['ques_id']); foreach ($row['children'] as &$child) { $child['title'] = $this->_format_question_content($child['title'], in_array($child['type'], array(3, 9))); } // 分值系数 if ($sum_score_factor > 0) { $row['total_score'] = round($total_0 * $row['score_factor'] / $sum_score_factor['sum'], 2); $row['score'] = round($row['total_score'] / $row['children_num'], 2); } else { $row['total_score'] = 0; $row['score'] = 0; } break; case 1: case 2: case 7: $row['options'] = QuestionModel::get_options($row['ques_id']); break; case 3: case 9: $row['answer'] = explode("\n", $row['answer']); break; case 4: case 5: case 6: case 8: $row['children'] = QuestionModel::get_children($row['ques_id']); break; default: } $group[$row['type']][] = $row; } $paper_info = array(); $types = array_keys($group); foreach ($types as $type) { $paper_info[$type] = isset($group[$type]) ? $group[$type] : array(); } $data['group'] = array_filter($paper_info); return $data; }
/** * Returns a series of attachment links for the given question * * @param QuestionModel question attachments are for * @param string (optional) mode that we are rendering in * @return string */ public function attachments(QuestionModel $question, $mode = 'edit') { $output = ''; foreach ($question->getAttachments() as $id => $properties) { $attachment = array('filename' => $properties['filename'], 'elementName' => "q{$question->questionID}_file{$id}_delete", 'url' => $this->view->url(array('controller' => 'page', 'action' => 'download', 'id' => $question->questionID)) . "?fileID={$id}"); $output .= $this->view->renderPartial('attachment', $attachment, false, false, array('mode' => $mode)); } return $output; }
/** * If $recruiter is set, vanilla will be false. If $recruiter is null, * vanilla will be true. */ private static function create($text, MongoId $recruiter = null) { // Check if question already exists (model function). If so, return // the question. $existingQuestion = QuestionModel::getByExactText($text); if (!is_null($existingQuestion)) { return self::parseRawData($existingQuestion); } // Construct question with parameters. $vanilla = is_null($recruiter); $question = new Question(['text' => $text, 'recruiter' => $recruiter, 'vanilla' => $vanilla]); // Pass (question object or raw data?) to model to store in database with // custom flag. $id = QuestionModel::insert($question->getData()); $question->setId($id); // Return created question. return $question; }
public function DeleteAction() { $request = Project::getRequest(); $user_id = (int) Project::getUser()->getDbUser()->id; $question_model = new QuestionModel(); $question_model->load($request->getKeyByNumber(0)); if ($question_model->user_id == $user_id) { $question_model->delete($request->getKeyByNumber(0)); } Project::getResponse()->redirect($request->createUrl('QuestionAnswer', 'UserQuestions')); }
/** * delete question from an id */ function deleteQuestion() { //"get segment 1 , question segment 2 , (:any) segment 3 $question_id = $this->uri->segment(3); $this->load->model('QuestionModel'); $question = new QuestionModel(); $delete_question_status = $question->deleteQuestion($question_id); echo json_encode(array("delete_question_status" => $delete_question_status)); }
public function actionPayLawyer($lawyerId, $answerId) { $question = QuestionModel::model()->findByPk($answerId); $user = UserModel::model()->findByPk($lawyerId); $cost = $question->cost * 0.7; $user->balance = $user->balance + $cost; $user->save(false); $question->status = QuestionModel::STATUS_CLOSE; $question->save(false); Yii::app()->user->setFlash('success', 'Спасибо вашь вопрос закрыт!'); $this->redirect($this->createUrl('question/index')); }
public function group($group_id = 0) { if (!$this->check_power('question_manage')) { return; } $group_id = intval($group_id); if ($group_id) { $query = $this->db->get_where('relate_group', array('group_id' => $group_id)); $group = $query->row_array(); } if (empty($group)) { $site_url = site_url('/admin/question/index'); header("location: {$site_url}"); // message('关联分组不存在。','/admin/question/index'); return; } $cpusers = CpUserModel::get_cpuser_list(); // 加载分类数据 $class_list = ClassModel::get_class_list(); $subjects = CpUserModel::get_allowed_subjects(); $grades = C('grades'); $qtypes = C('qtype'); $periods = C('grade_period'); $langs = C('interview_lang'); $types = C('interview_type'); $list_ques = $list_interview = array(); $query = $this->db->get_where('question', array('group_id' => $group_id, 'parent_id' => 0, 'is_delete' => 0)); foreach ($query->result_array() as $row) { $row_cids = explode(',', trim($row['class_id'], ',')); $row_cname = array(); foreach ($row_cids as $cid) { $row_cname[] = isset($class_list[$cid]['class_name']) ? $class_list[$cid]['class_name'] : ''; } $row['class_name'] = implode(',', $row_cname); $row['start_grade'] = isset($grades[$row['start_grade']]) ? $grades[$row['start_grade']] : ''; $row['qtype'] = isset($qtypes[$row['type']]) ? $qtypes[$row['type']] : ''; $row['end_grade'] = isset($grades[$row['end_grade']]) ? $grades[$row['end_grade']] : ''; $row['subject_name'] = isset($subjects[$row['subject_id']]) ? $subjects[$row['subject_id']] : ''; $row['addtime'] = date('Y-m-d H:i', $row['addtime']); $row['cpuser'] = isset($cpusers[$row['admin_id']]['realname']) ? $cpusers[$row['admin_id']]['realname'] : ''; $row['has_edit_power'] = QuestionModel::check_question_power($row['ques_id'], 'w', false); //判断该试题已经被考试过 或 正在被考 $row['be_tested'] = QuestionModel::question_has_test_action($row['ques_id']); $list_ques[] = $row; } $query2 = $this->db->get_where('interview_question', array('group_id' => $group_id, 'is_delete' => 0)); foreach ($query2->result_array() as $row) { // 类型 $row_cids = explode(',', trim($row['class_id'], ',')); $row_cname = array(); foreach ($row_cids as $cid) { $row_cname[] = isset($class_list[$cid]['class_name']) ? $class_list[$cid]['class_name'] : ''; } // 年段 $row_pids = explode(',', trim($row['grade_period'], ',')); $row_pname = array(); foreach ($row_pids as $pid) { $row_pname[] = isset($periods[$pid]) ? $periods[$pid] : ''; } $row['class_name'] = implode(',', $row_cname); $row['period_name'] = implode(',', $row_pname); $row['language'] = isset($langs[$row['lang']]) ? $langs[$row['lang']] : ''; $row['type_name'] = isset($types[$row['interview_type']]['type_name']) ? $types[$row['interview_type']]['type_name'] : ''; $row['addtime'] = date('Y-m-d H:i', $row['addtime']); $row['cpuser'] = isset($cpusers[$row['admin_id']]['realname']) ? $cpusers[$row['admin_id']]['realname'] : ''; $list_interview[] = $row; } $priv = array('delete_question' => $this->check_power('question_delete', FALSE), 'delete_interview_question' => $this->check_power('invterview_question_delete', FALSE)); $data['group_id'] = $group_id; $data['list_ques'] = $list_ques; $data['list_interview'] = $list_interview; $data['priv'] = $priv; $data['has_edit_power'] = QuestionModel::check_question_power($group['group_name'], 'w', false); $data['has_interview_question_manage'] = $this->check_power('interview_question_manage', false); // 模版 $this->load->view('relate_group/group', $data); }
public function setexamrelatequestion($erq_examid, $erq_zmoss_examid) { $erq_examid = intval($erq_examid); $erq_zmoss_examid = intval($erq_zmoss_examid); $paper_id = intval(Fn::getParam('er_paperid')); $exam = ExamModel::get_exam($erq_examid); if (!$exam['exam_pid']) { message('请指定需要设置试题对应的考试学科!'); } $examrelate = ZmossModel::examRelateInfo($erq_examid, $erq_zmoss_examid); if (!$examrelate) { message('此考试学科没有对应关系,无法设置试题关系!'); } $zmossquestion = ZmossModel::examQuestionList($examrelate['er_zmoss_examid']); if (!$zmossquestion) { message('此考试学科对应阅卷系统的考试没有试题,无法设置试题关系!'); } $paperlist = ExamPaperModel::examSubjectPaperList($erq_examid); if (!$paperlist) { message('此考试学科没有设置考试试卷,无法设置试题关系!'); } if ($paper_id) { $paper = $paperlist[$paper_id]; } if (!$paper) { $paper = current($paperlist); } /* $paperquestion = ExamPaperModel::examPaperQuestion( $paper['paper_id'], 'q.ques_id, q.parent_id, q.type, IFNULL(pq.type, q.type) AS p_type', 'AND q.is_parent = 0', 'ORDER BY p_type ASC, q.parent_id ASC, q.ques_id ASC'); */ $question = json_decode($paper['question_sort'], true); $paperquestion = array(); foreach ($question as $k => $ques_id) { $info = QuestionModel::get_question($ques_id); $list = QuestionModel::get_children($ques_id); if ($list) { foreach ($list as $key => $val) { $paperquestion[$val['ques_id']] = array('ques_id' => $val['ques_id'], 'type' => $info['type'], 'parent_id' => $ques_id); } } else { $paperquestion[$ques_id] = array('ques_id' => $ques_id, 'type' => $info['type']); } } $examrelatequestion = ZmossModel::examRelateQuestionInfo($erq_examid, $erq_zmoss_examid, $paper['paper_id']); $erq_relate_data = array(); if ($examrelatequestion) { $erq_relate_data = json_decode($examrelatequestion['erq_relate_data'], true); } $data['examrelatequestion'] = $erq_relate_data; $data['examrelate'] = $examrelate; $data['paperquestion'] = $paperquestion; $data['zmossquestion'] = $zmossquestion; $data['qtype'] = C('qtype'); $data['paperlist'] = $paperlist; $this->load->view('zmoss/setexamrelatequestion', $data); }
public function validate_related() { $related = $this->input->post('related'); $question = QuestionModel::get_question($related); $result = $question && $question['is_original'] == '2' ? 'true' : 'false'; die($result); }
/** * 学生答题详情 * * @author TCG * @param int $uid 用户ID * @param int $etp_id 考场-试卷-学生关联表 * @return void */ public function detail($uid = 0, $etp_id = 0) { $sql = "select subject_id,exam_id from {pre}exam_test_paper where etp_id='{$uid}' "; $res = $this->db->query($sql)->row_array(); $subject_id = $res['subject_id']; $exam_id = $res['exam_id']; $exam = $this->db->select('exam_id, subject_id, grade_id, class_id, total_score, qtype_score')->get_where('exam', array('exam_id' => $exam_id), 1)->row_array(); $sql = "SELECT q.type,etr.ques_id,etr.answer,etr.ques_subindex,etr.full_score,etr.test_score,etr.sub_ques_id \n from {pre}exam_test_result etr\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=etr.ques_id AND rc.grade_id='{$exam['grade_id']}' AND rc.class_id='{$exam['class_id']}'\n LEFT JOIn {pre}question q ON etr.ques_id = q.ques_id \n where etp_id = ? and uid = ? order by rc.difficulty DESC,etr.ques_id ASC, q.sort ASC, etr.sub_ques_id"; $query = $this->db->query($sql, array($uid, $etp_id)); $sql = "SELECT paper_id FROM {pre}exam_test_paper WHERE etp_id='{$uid}' "; $res = $this->db->query($sql)->row_array(); $paper_id = $res['paper_id']; $paper = PaperModel::get_paper_by_id($paper_id); $questions_arr = json_decode($paper['question_sort'], true); $questions_score = json_decode($paper['question_score'], true); if ($query->num_rows() > 0) { $sort = array(); /* 重新排序 */ if (is_array($questions_arr)) { foreach ($questions_arr as $v) { foreach ($query->result_array() as $value) { if ($v == $value['ques_id']) { $sort[] = $value; } } } } else { $sort = $query->result_array(); } $result = array(); $result1 = array(); foreach ($sort as $key => $row) { if ($row['sub_ques_id'] > 0) { $result[$row['ques_id']][$row['sub_ques_id']]['answer'] = $row['answer']; $result[$row['ques_id']][$row['sub_ques_id']]['full_score'] = $row['full_score']; $result[$row['ques_id']][$row['sub_ques_id']]['test_score'] = $row['test_score']; } else { $result[$row['ques_id']]['answer'] = $row['answer']; $result[$row['ques_id']]['full_score'] = $row['full_score']; $result[$row['ques_id']]['test_score'] = $row['test_score']; } } // 试题类型 foreach ($result as $ques_id => $value) { $question['type'] = QuestionModel::get_question($ques_id, 'type'); $result[$ques_id]['type'] = $question['type']; if (in_array($question['type'], array(1, 2, 3, 7, 9, 11, 10, 14))) { if (in_array($question['type'], array(1, 2, 7, 14))) { $answer = explode(',', $value['answer']); $tmp_answer = array(); foreach ($answer as $k => $v) { if (!$v) { continue; } $option = QuestionModel::get_option($v); if ($option) { $tmp_answer[$k] = '<span>' . $option['option_name'] . '</span>'; if ($option['picture']) { $tmp_answer[$k] .= '<br/><img src="' . __IMG_ROOT_URL__ . $option['picture'] . '" />'; } } } $result[$ques_id]['answer'] = $tmp_answer; } else { if (in_array($question['type'], array(3, 9))) { $result[$ques_id]['answer'] = explode("\n", $value['answer']); } } } else { foreach ($value as $sub_ques_id => $item) { $sub_question['type'] = QuestionModel::get_question($sub_ques_id, 'type'); if (in_array($sub_question['type'], array(1, 2))) { $answer = explode(',', $item['answer']); $tmp_answer = array(); foreach ($answer as $k => $v) { if (!$v) { continue; } $option = QuestionModel::get_option($v); if ($option) { $tmp_answer[$k] = '<span>' . $option['option_name'] . '</span>'; if ($option['picture']) { $tmp_answer[$k] .= '<br/><img src="' . __IMG_ROOT_URL__ . $option['picture'] . '" />'; } } } $result[$ques_id][$sub_ques_id]['answer'] = $tmp_answer; } else { if ($sub_question['type'] == 3) { $result[$ques_id][$sub_ques_id]['answer'] = explode("\n", $item['answer']); } } } } $groups[$question['type']]['list'][$ques_id] = $result[$ques_id]; } $data['result'] = $groups; } else { die('暂无考生考试信息!'); } $data['group_index'] = array('一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四'); $this->load->view('exam_student_result/detail', $data); }