当前位置: 首页>>代码示例>>PHP>>正文


PHP Answer::model方法代码示例

本文整理汇总了PHP中Answer::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Answer::model方法的具体用法?PHP Answer::model怎么用?PHP Answer::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Answer的用法示例。


在下文中一共展示了Answer::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new QuestionVotes();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['QuestionVotes'])) {
         $model->attributes = $_POST['QuestionVotes'];
         // TODO: I'd like to figure out a way to instantiate the model
         //			dynamically. I think they might do that with
         //			the 'activity' module. For now this will do.
         switch ($model->vote_on) {
             case "question":
                 $question_id = $model->post_id;
                 break;
             case "answer":
                 $obj = Answer::model()->findByPk($model->post_id);
                 $question_id = $obj->question_id;
                 break;
         }
         if (QuestionVotes::model()->castVote($model, $question_id)) {
             if ($_POST['QuestionVotes']['should_open_question'] == true) {
                 $this->redirect(array('//questionanswer/question/view', 'id' => $question_id));
             } else {
                 $this->redirect(array('//questionanswer/question/index'));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:33,代码来源:VoteController.php

示例2: actionView

 /** 
  * Controller action for viewing a questions.
  * Also provides functionality for creating an answer,
  * adding a comment and voting.
  */
 public function actionView()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $question = Question::model()->findByPk(Yii::app()->request->getParam('id'));
     if (isset($_POST['Answer'])) {
         $answerModel = new Answer();
         $answerModel->attributes = $_POST['Answer'];
         $answerModel->created_by = Yii::app()->user->id;
         $answerModel->post_type = "answer";
         $answerModel->question_id = $question->id;
         if ($answerModel->validate()) {
             $answerModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     if (isset($_POST['Comment'])) {
         $commentModel = new Comment();
         $commentModel->attributes = $_POST['Comment'];
         $commentModel->created_by = Yii::app()->user->id;
         $commentModel->post_type = "comment";
         $commentModel->question_id = $question->id;
         if ($commentModel->validate()) {
             $commentModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $question->id)));
         }
     }
     // User has just voted on a question
     if (isset($_POST['QuestionVotes'])) {
         $questionVotesModel = new QuestionVotes();
         $questionVotesModel->attributes = $_POST['QuestionVotes'];
         QuestionVotes::model()->castVote($questionVotesModel, $question->id);
     }
     $this->render('view', array('author' => $question->user->id, 'question' => $question, 'answers' => Answer::model()->overview($question->id), 'related' => Question::model()->related($question->id)));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:40,代码来源:MainController.php

示例3: getBestAnswer

 public function getBestAnswer()
 {
     //$sql = "select a.* from answer a left join answer_vote v on a.id=v.answerid where a.userId= 1 and v.value>0 group by a.id order by count(*) desc,a.addTime desc limit 1";
     $sql = "select a.* from ew_answer a left join  ew_entity e on a.voteableEntityId=e.id left join ew_vote v on e.id=v.voteableEntityId where a.userId= " . $this->id . " and v.value>0 order by a.addTime desc limit 1";
     $answer = Answer::model()->findBySql($sql);
     return $answer;
 }
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:7,代码来源:UserInfo.php

示例4: actionCheckAnswer

 public function actionCheckAnswer()
 {
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $ac_models = new AnswerComments();
         $ac_models->message = $_POST['CommentForm']['message'];
         $ac_models->answer_id = $_POST['CommentForm']['comment_id'];
         $ac_models->uid = Yii::app()->user->id;
         $ac_models->time = time();
         if (!$ac_models->save()) {
             throw new Exception('评论失败');
         }
         //在question中的 comment_count字段+1
         if (!Answer::model()->updateByPk($ac_models->answer_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());
     }
 }
开发者ID:jvlstudio,项目名称:ask,代码行数:25,代码来源:CommentController.php

示例5: actionBatchDelete

 public function actionBatchDelete()
 {
     if (Yii::app()->user->checkAccess('deleteFeedback') == false) {
         throw new CHttpException(403);
     }
     $idList = Yii::app()->request->getPost('id', array());
     if (count($idList) > 0) {
         $criteria = new CDbCriteria();
         $criteria->addInCondition('id', $idList);
         $feedbacks = Feedback::model()->findAll($criteria);
         $flag = 0;
         foreach ($feedbacks as $feedback) {
             if ($feedback->delete()) {
                 $answer = Answer::model()->deleteAll('feedback_id=:feedbackID', array(':feedbackID' => $feedback->primaryKey));
                 $flag++;
             }
         }
         if ($flag > 0) {
             $this->setFlashMessage('问题咨询 已成功删除');
         } else {
             $this->setFlashMessage('问题咨询 删除失败', 'warn');
         }
     } else {
         $this->setFlashMessage('没有记录被选中', 'warn');
     }
     $this->redirect(array('index'));
 }
开发者ID:kinghinds,项目名称:kingtest2,代码行数:27,代码来源:FeedbackController.php

示例6: getStatusText

 public function getStatusText()
 {
     $id = $this->id;
     $answer = Answer::model()->find('feedback_id=:feedbackID', array(':feedbackID' => $id));
     if ($this->is_reply == 0) {
         return '<font color="blue">未回复</font>&nbsp;&nbsp;<a href="index.php?r=answer/reply&feedbackid=' . $id . '">回复</a>';
     } else {
         if ($this->is_reply == 1) {
             return '<font color="green">已回复</font>&nbsp;&nbsp;<a href="index.php?r=answer/view&id=' . $answer->primaryKey . '">查看回复</a>';
         }
     }
 }
开发者ID:kinghinds,项目名称:kingtest2,代码行数:12,代码来源:Feedback.php

示例7: getUserAnswerCount

 /**
  * 计算用户在本小组内回答问题的次数
  * Enter description here ...
  * @param unknown_type $userId
  */
 public function getUserAnswerCount($userId)
 {
     $group = $this->getOwner();
     $answerCount = 0;
     foreach ($group->testQuestions as $question) {
         $answer = Answer::model()->findByAttributes(array('userId' => $userId, 'questionid' => $question->id));
         if ($answer) {
             $answerCount++;
         }
     }
     return $answerCount;
 }
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:17,代码来源:GroupHelperBehavior.php

示例8: actionOwnerAns

 public function actionOwnerAns($uid)
 {
     if (Yii::app()->user->isGuest) {
         Yii::app()->user->loginRequired();
     } else {
         $cri = new CDbCriteria();
         $cri->with = array('question');
         $cri->addCondition('t.userId=' . $uid);
         $cri->order = 'time DESC';
         $viewModel = Answer::model()->findAll($cri);
         $myLike = LikeAns::model()->findAll('userId=:uid', array(':uid' => Yii::app()->user->id));
         $this->render('ownerAns', array('viewModel' => $viewModel, 'uid' => $uid, 'myLike' => $myLike));
     }
 }
开发者ID:hanyilu,项目名称:iQuestion,代码行数:14,代码来源:UserController.php

示例9: onSearchRebuild

 /**
  * On rebuild of the search index, rebuild all user records
  *
  * @param type $event
  */
 public static function onSearchRebuild($event)
 {
     foreach (Question::model()->findAll() as $obj) {
         HSearch::getInstance()->addModel($obj);
         print "q";
     }
     foreach (Tag::model()->findAll() as $obj) {
         HSearch::getInstance()->addModel($obj);
         print "t";
     }
     foreach (Answer::model()->findAll() as $obj) {
         HSearch::getInstance()->addModel($obj);
         print "a";
     }
     foreach (Comment::model()->findAll() as $obj) {
         HSearch::getInstance()->addModel($obj);
         print "c";
     }
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:24,代码来源:QuestionAnswerEvents.php

示例10: actionAnswer

 /**
  * 为帖子投票
  * Enter description here ...
  * @param unknown_type $postid
  * @param unknown_type $value
  */
 public function actionAnswer($answerid, $value = 0)
 {
     //$vote = new PostVote;
     $vote = AnswerVote::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'answerid' => $answerid));
     $answer = Answer::model()->with('question')->findByPk($answerid);
     if ($vote && $vote->value == $value) {
         //再点击赞同(反对),即取消第一次投的赞同(反对)
         $result = $vote->delete();
     } else {
         //赞同(反对)被第一次点击
         $vote or $vote = new AnswerVote();
         $vote->answerid = $answerid;
         $vote->value = $value;
         $vote->userId = Yii::app()->user->id;
         $vote->addTime = time();
         $result = $vote->save();
         //发送系统通知给回答主人
         if ($answer->userId != $vote->userId) {
             $notice = new Notice();
             $notice->type = 'vote_answer';
             $notice->setData(array('voteId' => $vote->getPrimaryKey()));
             $notice->userId = $answer->userId;
             $notice->save();
         }
     }
     if ($result) {
         //		$question = Question::model()->findByPk($answer->question)
         //修改答案投票次数统计
         $answer->voteupNum = $answer->voteupCount;
         $answer->count_votedown = $answer->votedownCount;
         $answer->save();
         //修改问题投票次数统计
         $answer->question->updateVoteCount();
         //修改用户被赞数量
         $user = UserInfo::model()->findByPk($answer->userId);
         $user->answerVoteupNum = $user->getAnswerVoteupCount();
         $user->save();
         $score = $answer->voteupCount - $answer->votedownCount;
         $this->renderPartial('result', array('score' => $score, 'voteupers' => $answer->voteupers));
     }
 }
开发者ID:stan5621,项目名称:jp_edu_online,代码行数:47,代码来源:VoteController.php

示例11: actionGetAll

 public function actionGetAll()
 {
     $session_id = Yii::app()->request->getPost("session_id", NULL);
     $session = Session::model()->find('session_id=:session_id', array(':session_id' => $session_id));
     $session_listenings = SessionListening::model()->findAll('session_id=:session_id', array(':session_id' => $session_id));
     $all = array();
     $all["session_id"] = $session->session_id;
     $all["session_name"] = $session->session_name;
     $all["session_order"] = $session->session_order;
     $all["mod_id"] = $session->mod_id;
     $all["listenings"] = array();
     foreach ($session_listenings as $key => $session_listening) {
         $temp_listening_id = $session_listening->listening_id;
         $listening = Listening::model()->find('listening_id=:listening_id', array(':listening_id' => $temp_listening_id));
         $all["listenings"][$key] = array('listening_id' => $listening->listening_id, 'listening_name' => $listening->listening_name, 'listening_repeat_number' => $listening->listening_repeat_number, 'listening_learning_guide_availability' => $listening->listening_learning_guide_availability);
         $criteria = new CDbCriteria();
         $criteria->addCondition("listening_id=:listening_id");
         $criteria->order = 'RAND()';
         $criteria->params = array(':listening_id' => $listening->listening_id);
         $questions = Question::model()->findAll($criteria);
         //$questions=Question::model()->findAll('listening_id=:listening_id',array('listening_id'=>$listening->listening_id));
         foreach ($questions as $key2 => $question) {
             $all["listenings"][$key]['questions'][$key2] = array('question_id' => $question->question_id, 'question_body' => $question->question_body, 'question_correct_answer_id' => $question->question_correct_answer_id);
             $criteria = new CDbCriteria();
             $criteria->addCondition("question_id=:question_id");
             $criteria->order = 'RAND()';
             $criteria->params = array(':question_id' => $question->question_id);
             $answers = Answer::model()->findAll($criteria);
             //$answers=Answer::model()->findAll('question_id=:question_id',array(':question_id'=>$question->question_id));
             foreach ($answers as $key3 => $answer) {
                 $all["listenings"][$key]['questions'][$key2]['answers'][$key3] = array('answer_id' => $answer->answer_id, 'answer_body' => $answer->answer_body);
             }
         }
     }
     $this->renderJSON($all);
 }
开发者ID:taskinegemen,项目名称:akdeniz_uni,代码行数:36,代码来源:ApiController.php

示例12: foreach

                        if(isset($dualscaleheaderb) && $dualscaleheaderb != "")
                        {
                            $labeltitle2 = $dualscaleheaderb;
                        }
                        else
                        {
                            //get label text

                            $labeltitle2 = '';
                        }

                        echo " />&nbsp;<strong>"
                        ._showSpeaker($niceqtext." [".str_replace("'", "`", $row[1])."] - ".gT("Label").": ".$labeltitle2)
                        ."</strong><br />\n";
                        $fresult = Answer::model()->getQuestionsForStatistics('*', "qid='$flt[0]' AND language = '$language' AND scale_id = 1", 'sortorder, code');

                        //this is for debugging only
                        //echo $fquery;

                        echo "\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}#{1}[]' multiple='multiple' class='form-control'>\n";

                        //list answers
                        foreach($fresult as $frow)
                        {
                            echo "\t<option value='{$frow['code']}'";

                            //pre-check
                            if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($frow['code'], $_POST[$myfield2])) {echo " selected";}

                            echo ">({$frow['code']}) ".flattenText($frow['answer'],true)."</option>\n";
开发者ID:jgianpiere,项目名称:lime-survey,代码行数:30,代码来源:statistics_view.php

示例13: afterSave

 /**
  * 修改被点赞的人员
  */
 public function afterSave()
 {
     parent::afterSave();
     $to_user = "";
     if ($this->model == "answer") {
         $to_user = Answer::model()->findByPk($this->pk_id)->create_user;
     } else {
         if ($this->model == "article") {
             $to_user = Article::model()->findByPk($this->pk_id)->create_user;
         } else {
             if ($this->model == "question") {
                 $to_user = Question::model()->findByPk($this->pk_id)->create_user;
             }
         }
     }
     if ($to_user != "") {
         Vote::model()->updateByPk($this->id, array("to_user" => $to_user));
     }
 }
开发者ID:ruzuojun,项目名称:shiqu,代码行数:22,代码来源:Vote.php

示例14: do_array

function do_array($ia)
{
    global $thissurvey;
    $aLastMoveResult = LimeExpressionManager::GetLastMoveResult();
    $aMandatoryViolationSubQ = $aLastMoveResult['mandViolation'] && $ia[6] == 'Y' ? explode("|", $aLastMoveResult['unansweredSQs']) : array();
    $repeatheadings = Yii::app()->getConfig("repeatheadings");
    $minrepeatheadings = Yii::app()->getConfig("minrepeatheadings");
    $extraclass = "";
    $caption = "";
    // Just leave empty, are replaced after
    $checkconditionFunction = "checkconditions";
    $qquery = "SELECT other FROM {{questions}} WHERE qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "'";
    $other = Yii::app()->db->createCommand($qquery)->queryScalar();
    //Checked
    $aQuestionAttributes = getQuestionAttributeValues($ia[0]);
    if (trim($aQuestionAttributes['answer_width']) != '') {
        $answerwidth = $aQuestionAttributes['answer_width'];
    } else {
        $answerwidth = 20;
    }
    $columnswidth = 100 - $answerwidth;
    if ($aQuestionAttributes['use_dropdown'] == 1) {
        $useDropdownLayout = true;
        $extraclass .= " dropdown-list";
        $caption = gT("An array with sub-question on each line. You have to select your answer.");
    } else {
        $useDropdownLayout = false;
        $caption = gT("An array with sub-question on each line. The answers are contained in the table header. ");
    }
    if (ctype_digit(trim($aQuestionAttributes['repeat_headings'])) && trim($aQuestionAttributes['repeat_headings'] != "")) {
        $repeatheadings = intval($aQuestionAttributes['repeat_headings']);
        $minrepeatheadings = 0;
    }
    $lresult = Answer::model()->findAll(array('order' => 'sortorder, code', 'condition' => 'qid=:qid AND language=:language AND scale_id=0', 'params' => array(':qid' => $ia[0], ':language' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'])));
    $labelans = array();
    $labelcode = array();
    foreach ($lresult as $lrow) {
        $labelans[] = $lrow->answer;
        $labelcode[] = $lrow->code;
    }
    if ($useDropdownLayout === false && count($lresult) > 0) {
        $sQuery = "SELECT count(qid) FROM {{questions}} WHERE parent_qid={$ia[0]} AND question like '%|%' ";
        $iCount = Yii::app()->db->createCommand($sQuery)->queryScalar();
        if ($iCount > 0) {
            $right_exists = true;
            $answerwidth = $answerwidth / 2;
        } else {
            $right_exists = false;
        }
        // $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column
        if ($aQuestionAttributes['random_order'] == 1) {
            $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY " . dbRandom();
        } else {
            $ansquery = "SELECT * FROM {{questions}} WHERE parent_qid={$ia[0]} AND language='" . $_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang'] . "' ORDER BY question_order";
        }
        $ansresult = dbExecuteAssoc($ansquery);
        //Checked
        $aQuestions = $ansresult->readAll();
        $anscount = count($aQuestions);
        $fn = 1;
        $numrows = count($labelans);
        if ($right_exists) {
            ++$numrows;
            $caption .= gT("After answers, a cell give some information. ");
        }
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
            ++$numrows;
            $caption .= gT("The last cell are for no answer. ");
        }
        $cellwidth = round($columnswidth / $numrows, 1);
        $answer_start = "\n<table class=\"question subquestions-list questions-list {$extraclass}\" summary=\"{$caption}\">\n";
        $answer_head_line = "\t<td>&nbsp;</td>\n";
        foreach ($labelans as $ld) {
            $answer_head_line .= "\t<th>" . $ld . "</th>\n";
        }
        if ($right_exists) {
            $answer_head_line .= "\t<td>&nbsp;</td>\n";
        }
        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {
            $answer_head_line .= "\t<th>" . gT('No answer') . "</th>\n";
        }
        $answer_head = "\t<thead><tr class=\"dontread\">\n" . $answer_head_line . "</tr></thead>\n\t\n";
        $answer = '<tbody>';
        $trbc = '';
        $inputnames = array();
        foreach ($aQuestions as $ansrow) {
            if (isset($repeatheadings) && $repeatheadings > 0 && $fn - 1 > 0 && ($fn - 1) % $repeatheadings == 0) {
                if ($anscount - $fn + 1 >= $minrepeatheadings) {
                    $answer .= "</tbody>\n<tbody>";
                    // Close actual body and open another one
                    $answer .= "<tr class=\"dontread repeat headings\">{$answer_head_line}</tr>";
                }
            }
            $myfname = $ia[1] . $ansrow['title'];
            $answertext = $ansrow['question'];
            $answertextsave = $answertext;
            if (strpos($answertext, '|')) {
                $answertext = substr($answertext, 0, strpos($answertext, '|'));
            }
            if (strpos($answertext, '|')) {
//.........这里部分代码省略.........
开发者ID:segfault,项目名称:LimeSurvey,代码行数:101,代码来源:qanda_helper.php

示例15: actioncancelnotanonymous

 public function actioncancelnotanonymous()
 {
     $answer_id = $_POST["answer_id"];
     $answerModel = Answer::model()->findByPk($answer_id);
     $return = array();
     $return['message'] = "false";
     if ($answerModel == NULL) {
         $tip = '没有此答案!';
     } else {
         if (Yii::app()->user->isGuest) {
             $tip = '回答问题前,请先登录!';
         } else {
             if ($answerModel->create_user != Yii::app()->user->id) {
                 $tip = '你没有修改权限!';
             } else {
                 $answerModel->is_anonymous = 0;
                 $return['message'] = $answerModel->save() ? "ok" : "false";
                 $tip = $return['message'] == "ok" ? '修改成功!' : '修改失败!';
             }
         }
     }
     $return['tip'] = $tip;
     echo json_encode($return);
 }
开发者ID:ruzuojun,项目名称:shiqu,代码行数:24,代码来源:DefaultController.php


注:本文中的Answer::model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。