本文整理汇总了PHP中Question::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::model方法的具体用法?PHP Question::model怎么用?PHP Question::model使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Question
的用法示例。
在下文中一共展示了Question::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
public function loadModel($id)
{
if (($model = Question::model()->findByPk($id)) === null) {
throw new CHttpException(404, Yii::t('FaqModule.faq', 'Page was not found!'));
}
return $model;
}
示例2: actionBatch
/**
* 批量操作
*
*/
public function actionBatch()
{
if ($this->method() == 'GET') {
$command = trim($this->_request->getParam('command'));
$ids = intval($this->_request->getParam('id'));
} elseif ($this->method() == 'POST') {
$command = $this->_request->getPost('command');
$ids = $this->_request->getPost('id');
} else {
throw new CHttpException(404, Yii::t('admin', 'Only POST Or GET'));
}
empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
switch ($command) {
case 'delete':
foreach ((array) $ids as $id) {
$questionModel = Question::model()->findByPk($id);
if ($questionModel) {
$questionModel->delete();
}
}
break;
default:
throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
break;
}
$this->message('success', Yii::t('admin', 'Batch Operate Success'));
}
示例3: search
private function search($search)
{
$criteria = new CDbCriteria();
$criteria->addSearchCondition('content', $search);
$questions = Question::model()->with('user', 'tags')->findAll($criteria);
return $questions;
}
示例4: actionCheckQuestion
public function actionCheckQuestion()
{
$transaction = Yii::app()->db->beginTransaction();
try {
$qc_models = new QuestionComments();
$qc_models->message = $_POST['CommentForm']['message'];
$qc_models->question_id = $_POST['CommentForm']['comment_id'];
//查看该问题是否已经被锁定
if ($this->is_lock($qc_models->question_id)) {
throw new Exception("该问题已经被锁定!");
}
$qc_models->uid = Yii::app()->user->id;
$qc_models->time = time();
if (!$qc_models->save()) {
throw new Exception('评论失败');
}
//在question中的 comment_count字段+1
if (!Question::model()->updateByPk($qc_models->question_id, array('comment_count' => new CDbExpression('comment_count+1')))) {
throw new ErrorException('评论失败');
}
$transaction->commit();
$this->redirect(Yii::app()->request->urlReferrer);
//$this->success('评论成功');
} catch (Exception $e) {
$transaction->rollBack();
//exit($e->getMessage());
$this->error($e->getMessage());
}
}
示例5: loadModel
public function loadModel($id)
{
if (($model = Question::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例6: actionCheckAnswer
/**
* 验证回答
*/
public function actionCheckAnswer()
{
//登入判断
$this->checkAuth();
$model = new AnswerForm();
if (isset($_POST['ajax']) && $_POST['ajax'] === 'answer-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
//var_dump($_POST['AnswerForm']);
//启用事物处理 因为需要插入 Answer表及Question字段中的answer_count 字段
$transaction = Yii::app()->db->beginTransaction();
try {
$answer_model = new Answer();
$answer_model->answer_content = $_POST['AnswerForm']['answer_content'];
$answer_model->question_id = $_POST['AnswerForm']['question_id'];
$answer_model->uid = Yii::app()->user->id;
$answer_model->add_time = time();
$answer_model->ip = Yii::app()->request->userHostAddress;
if (!$answer_model->save()) {
throw new ErrorException('回答失败1');
}
//更改question表中的answer_count 信息
if (!Question::model()->updateByPk($answer_model->question_id, array('answer_count' => new CDbExpression('answer_count+1')))) {
throw new ErrorException('回答失败2');
}
$transaction->commit();
$this->redirect(Yii::app()->request->urlReferrer);
//$this->success('回答成功');
} catch (Exception $e) {
$transaction->rollBack();
//exit($e->getMessage());
$this->error($e->getMessage());
}
}
示例7: run
public function run()
{
App()->loadHelper('surveytranslator');
$aData['issuperadmin'] = false;
if (Permission::model()->hasGlobalPermission('superadmin', 'read')) {
$aData['issuperadmin'] = true;
}
// We get the last survey visited by user
$setting_entry = 'last_survey_' . Yii::app()->user->getId();
$lastsurvey = getGlobalSetting($setting_entry);
$survey = Survey::model()->findByPk($lastsurvey);
if ($lastsurvey != null && $survey) {
$aData['showLastSurvey'] = true;
$iSurveyID = $lastsurvey;
$surveyinfo = $survey->surveyinfo;
$aData['surveyTitle'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")";
$aData['surveyUrl'] = $this->getController()->createUrl("admin/survey/sa/view/surveyid/{$iSurveyID}");
} else {
$aData['showLastSurvey'] = false;
}
// We get the last question visited by user
$setting_entry = 'last_question_' . Yii::app()->user->getId();
$lastquestion = getGlobalSetting($setting_entry);
// the question group of this question
$setting_entry = 'last_question_gid_' . Yii::app()->user->getId();
$lastquestiongroup = getGlobalSetting($setting_entry);
// the sid of this question : last_question_sid_1
$setting_entry = 'last_question_sid_' . Yii::app()->user->getId();
$lastquestionsid = getGlobalSetting($setting_entry);
$survey = Survey::model()->findByPk($lastquestionsid);
if ($lastquestion && $lastquestiongroup && $survey) {
$baselang = $survey->language;
$aData['showLastQuestion'] = true;
$qid = $lastquestion;
$gid = $lastquestiongroup;
$sid = $lastquestionsid;
$qrrow = Question::model()->findByAttributes(array('qid' => $qid, 'gid' => $gid, 'sid' => $sid, 'language' => $baselang));
if ($qrrow) {
$aData['last_question_name'] = $qrrow['title'];
if ($qrrow['question']) {
$aData['last_question_name'] .= ' : ' . $qrrow['question'];
}
$aData['last_question_link'] = $this->getController()->createUrl("admin/questions/sa/view/surveyid/{$sid}/gid/{$gid}/qid/{$qid}");
} else {
$aData['showLastQuestion'] = false;
}
} else {
$aData['showLastQuestion'] = false;
}
$aData['countSurveyList'] = count(getSurveyList(true));
// We get the home page display setting
$aData['bShowSurveyList'] = getGlobalSetting('show_survey_list') == "show";
$aData['bShowSurveyListSearch'] = getGlobalSetting('show_survey_list_search') == "show";
$aData['bShowLogo'] = getGlobalSetting('show_logo') == "show";
$aData['oSurveySearch'] = new Survey('search');
$aData['bShowLastSurveyAndQuestion'] = getGlobalSetting('show_last_survey_and_question') == "show";
$aData['iBoxesByRow'] = (int) getGlobalSetting('boxes_by_row');
$aData['sBoxesOffSet'] = (string) getGlobalSetting('boxes_offset');
$this->_renderWrappedTemplate('super', 'welcome', $aData);
}
示例8: loadQuestion
protected function loadQuestion($questId)
{
if ($this->_question === null) {
$this->_question = Question::model()->findByPk($questId);
if ($this->_question === null) {
throw new CHttpException(404, 'The requested Question does not exists');
}
}
return $this->_question;
}
示例9: loadModel
/**
* 判断数据是否存在
*
* return \$this->model
*/
public function loadModel()
{
if ($this->model === null) {
if (isset($_GET['id'])) {
$this->model = Question::model()->with('user')->findbyPk($_GET['id']);
}
if ($this->model === null) {
throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
}
}
return $this->model;
}
示例10: actionQuestion
public function actionQuestion($questionid)
{
$question = Question::model()->findByPk($questionid);
$question->viewNum = $question->viewNum + 1;
if ($question->save()) {
$questionView = new QuestionView();
$questionView->userId = Yii::app()->user->isGuest ? 0 : Yii::app()->user->id;
$questionView->ip = Yii::app()->request->getUserHostAddress();
$questionView->questionid = $questionid;
$questionView->save();
}
}
示例11: getFiles
/**
* Delete all files related to this repsonse.
*/
public function getFiles()
{
$questions = Question::model()->findAllByAttributes(array('sid' => $this->dynamicId, 'type' => '|'));
$files = array();
foreach ($questions as $question) {
$field = "{$question->sid}X{$question->gid}X{$question->qid}";
$data = json_decode(stripslashes($this->getAttribute($field)), true);
if (is_array($data)) {
$files = array_merge($files, $data);
}
}
return $files;
}
示例12: fixNumbering
/**
* fixes the numbering of questions
* This can happen if question 1 have subquestion code 1 and have question 11 in same survey and group (then same SGQA)
* @param int $fixnumbering
* @todo can call this function (no $_GET, but getParam) AND do it with Yii
*/
function fixNumbering($iQuestionID, $iSurveyID)
{
Yii::app()->loadHelper("database");
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
//Fix a question id - requires renumbering a question
$iQuestionID = (int) $iQuestionID;
$iMaxQID = Question::model()->getMaxId('qid', true);
// Always refresh as we insert new qid's
$iNewQID = $iMaxQID + 1;
// Not sure we can do this in MSSQL ?
$sQuery = "UPDATE {{questions}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
// Update subquestions
$sQuery = "UPDATE {{questions}} SET parent_qid={$iNewQID} WHERE parent_qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update conditions.. firstly conditions FOR this question
$sQuery = "UPDATE {{conditions}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update default values
$sQuery = "UPDATE {{defaultvalues}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
$sQuery = "UPDATE {{defaultvalues}} SET sqid={$iNewQID} WHERE sqid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update quotas
$sQuery = "UPDATE {{quota_members}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Update url params
$sQuery = "UPDATE {{survey_url_parameters}} SET targetqid={$iNewQID} WHERE targetqid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
$sQuery = "UPDATE {{survey_url_parameters}} SET targetsqid={$iNewQID} WHERE targetsqid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Now conditions based upon this question
$sQuery = "SELECT cqid, cfieldname FROM {{conditions}} WHERE cqid={$iQuestionID}";
$sResult = Yii::app()->db->createCommand($sQuery)->query();
foreach ($sResult->readAll() as $row) {
$aSwitcher[] = array("cqid" => $row['cqid'], "cfieldname" => $row['cfieldname']);
}
if (isset($aSwitcher)) {
foreach ($aSwitcher as $aSwitch) {
$sQuery = "UPDATE {{conditions}}\n SET cqid={$iNewQID},\n cfieldname='" . str_replace("X" . $iQuestionID, "X" . $iNewQID, $aSwitch['cfieldname']) . "'\n WHERE cqid={$iQuestionID}";
$sResult = db_execute_assosc($sQuery);
}
}
//Now question_attributes
$sQuery = "UPDATE {{question_attributes}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
//Now answers
$sQuery = "UPDATE {{answers}} SET qid={$iNewQID} WHERE qid={$iQuestionID}";
Yii::app()->db->createCommand($sQuery)->query();
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID);
}
示例13: actionOwnerQue
public function actionOwnerQue($uid)
{
Yii::app()->user->setReturnUrl(Yii::app()->request->url);
if (Yii::app()->user->isGuest) {
Yii::app()->user->loginRequired();
} else {
$cri = new CDbCriteria();
$cri->addCondition('userId=' . $uid);
$cri->order = 'createTime DESC';
$viewModel = Question::model()->findAll($cri);
$myLike = LikeQue::model()->findAll('userId=:uid', array(':uid' => Yii::app()->user->id));
$this->render('ownerQue', array('viewModel' => $viewModel, 'uid' => $uid, 'myLike' => $myLike));
}
}
示例14: actionDelete
/**
* 删除信息
* 多表删除 事物处理
* 删除 question 中信息
* 删除 answer 表中信息
* 删除 question
* 更新topic中次数
*/
public function actionDelete($id)
{
$transaction = Yii::app()->db->beginTransaction();
try {
//删除question 表信息
if (!Question::model()->deleteByPk($id)) {
throw new Exception("删除question表失败");
}
//删除 topic_question 表 首先把 topic id 查找出来
//获取topic id
$topic_ids = TopicQuestion::model()->findAll(array('select' => 'topic_id', 'condition' => 'question_id=:question_id', 'params' => array(':question_id' => $id)));
//更新 topic次数
foreach ($topic_ids as $model) {
//更新topic 次数
if (!Topic::model()->updateByPk($model->topic_id, array('discuss_count' => new CDbExpression('discuss_count-1')))) {
throw new ErrorException('更新失败');
}
}
//删除topic_question 表中信息
if (false === TopicQuestion::model()->deleteAll('question_id=:question_id', array('question_id' => $id))) {
throw new ErrorException('删除topic_question中信息失败');
}
//删除question_comment 中信息
if (false === QuestionComments::model()->deleteAll('question_id=:question_id', array('question_id' => $id))) {
throw new ErrorException('删除question_comment中信息失败');
}
//获取answer_comment 中id
$answer_comment_models = Answer::model()->findAll(array('select' => 'id', 'condition' => 'question_id=:question_id', 'params' => array(':question_id' => $id)));
//删除answer_comment 中信息
foreach ($answer_comment_models as $answer_comment_model) {
if (false === AnswerComments::model()->deleteAll('answer_id=:answer_id', array(':answer_id' => $answer_comment_model->id))) {
throw new ErrorException('删除answer_comment中信息失败');
}
}
//删除answer 表中信息
if (false === Answer::model()->deleteAll('question_id=:question_id', array('question_id' => $id))) {
throw new ErrorException('删除answer中信息失败');
}
//删除question_focus 中信息
if (false === QuestionFocus::model()->deleteAll('question_id=:question_id', array('question_id' => $id))) {
throw new ErrorException('删除question_focus 中信息失败');
}
$transaction->commit();
$this->success('删除成功');
} catch (Exception $e) {
$transaction->rollBack();
exit($e->getMessage());
$this->error($e->getMessage());
}
}
示例15: canPublish
public function canPublish()
{
$level = $this->getLevel();
if ($level >= 10) {
return true;
}
$criteria = new CDbCriteria();
$criteria->addCondition('userId=' . $this->id);
$criteria->addCondition('TO_DAYS(createTime)=TO_DAYS(NOW())');
$count = Question::model()->count($criteria);
if ($count < $level) {
return true;
}
return false;
}