コード例 #1
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return QuestionVotes the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = QuestionVotes::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
コード例 #2
0
                </div>
            </div>

            <?php 
foreach ($answers as $question_answer) {
    ?>
            <div class="panel panel-default qanda-panel" style="padding:25px; padding-left:15px;">
                <div class="panel-body">
                    <div class="media">
                        <div class="pull-left">
                            <div class="vote_control pull-left" style="padding:5px; padding-right:10px; border-right:1px solid #eee; margin-right:10px;">
                                <?php 
    $upBtnClass = "";
    $downBtnClass = "";
    $vote = QuestionVotes::model()->post($question_answer['id'])->user(Yii::app()->user->id)->find();
    if ($vote) {
        if ($vote->vote_type == "up") {
            $upBtnClass = "active btn-info";
            $downBtnClass = "";
        } else {
            if ($vote->vote_type == "down") {
                $downBtnClass = "active btn-info";
                $upBtnClass = "";
            }
        }
    }
    ?>
                                <?php 
    $this->widget('application.modules.questionanswer.widgets.VoteButtonWidget', array('post_id' => $question_answer['id'], 'model' => new QuestionVotes(), 'vote_on' => 'answer', 'vote_type' => 'up', 'class' => $upBtnClass, 'should_open_question' => 1));
    ?>
コード例 #3
0
 /** 
  * Cast a vote
  * @param QuestionVote 
  * @param int question_id (optional)
  */
 public static function castVote($questionVotesModel, $question_id)
 {
     $question = Question::model()->findByPk($question_id);
     $questionVotesModel->created_by = Yii::app()->user->id;
     if ($questionVotesModel->validate()) {
         // Is the author "voting" on the accepted answer?
         if ($question->created_by == $questionVotesModel->created_by && $questionVotesModel->vote_type == "accepted_answer") {
             // If the user has previously selected a best answer, drop the old one
             $previousAccepted = QuestionVotes::model()->findAcceptedAnswer($question->id);
             if ($previousAccepted && $previousAccepted->post_id != $question->id) {
                 $previousAccepted->delete();
             }
         } else {
             // no, just a normal up/down vote then
             // If the user has previously voted on this, drop it
             $previousVote = QuestionVotes::model()->find('post_id=:post_id AND created_by=:user_id', array('post_id' => $questionVotesModel->post_id, 'user_id' => Yii::app()->user->id));
             if ($previousVote) {
                 $previousVote->delete();
             }
         }
         $questionVotesModel->save();
         return true;
     } else {
         return false;
     }
 }
コード例 #4
0
<?php

/* @var $this QuestionController */
/* @var $data Question */
?>
<div class="media" >
    <div class="pull-left">
        <div class="vote_control pull-left" style="padding:5px; padding-right:10px; border-right:1px solid #eee; margin-right:10px;">
            <?php 
$upBtnClass = "";
$downBtnClass = "";
$vote = "";
// Change the button class to 'active' if the user has voted
$vote = QuestionVotes::model()->post($data->id)->user(Yii::app()->user->id)->find();
if ($vote) {
    if ($vote->vote_type == "up") {
        $upBtnClass = "active btn-info";
        $downBtnClass = "";
    } else {
        $downBtnClass = "active btn-info";
        $upBtnClass = "";
    }
}
$this->widget('application.modules.questionanswer.widgets.VoteButtonWidget', array('post_id' => $data->id, 'model' => new QuestionVotes(), 'vote_on' => 'question', 'vote_type' => 'up', 'class' => $upBtnClass, 'should_open_question' => 0));
$this->widget('application.modules.questionanswer.widgets.VoteButtonWidget', array('post_id' => $data->id, 'model' => new QuestionVotes(), 'vote_on' => 'question', 'vote_type' => 'down', 'class' => $downBtnClass, 'should_open_question' => 0));
?>
        </div>
        <!--<a href="" class="pull-left" style="padding-top:5px; padding-right:10px;">
            <img class="media-object img-rounded user-image" alt="40x40" data-src="holder.js/40x40" style="width: 40px; height: 40px;" src="img/default_user.jpg?cacheId=0" width="40" height="40">
        </a>-->
        <?php 
コード例 #5
0
 public function deletequestion($post)
 {
     $id = $post['id'];
     $question = Questions::model()->findByPk($id);
     $question->delete();
     $criteria = new CDbCriteria();
     $criteria->condition = 'question_id = ' . $id;
     Answers::model()->deleteAll($criteria);
     QuestionViews::model()->deleteAll($criteria);
     QuestionVotes::model()->deleteAll($criteria);
     $return['status'] = true;
     $this->renderJSON($return, true);
 }
コード例 #6
0
 public function checkifCanVote()
 {
     $can_vote = 0;
     $q_id = Yii::app()->Ini->v('question_id');
     $question = Questions::model()->findByPk($q_id);
     if (!Yii::app()->user->isGuest) {
         $viewed_by = Yii::app()->user->getId();
         $viewed_user_type = Yii::app()->user->role;
         $vote = QuestionVotes::model()->countByAttributes(array('question_id' => $q_id, 'voted_by' => $viewed_by, 'voted_user_type' => $viewed_user_type));
         if ($vote == 0 && ($question->owner_id != $viewed_by && $question->owner_user_type != $viewed_user_type)) {
             $can_vote = 1;
         }
     }
     $return = array('can_vote' => $can_vote);
     $this->renderJSON($can_vote);
 }
コード例 #7
0
 /** 
  * Controller for viewing a
  * tag and loading up all questions
  * from within that tag
  */
 public function actionTag()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $tag = Tag::model()->findByPk(Yii::app()->request->getParam('id'));
     // Find all questions with that tag
     $criteria = new CDbCriteria();
     $criteria->condition = "tag_id=:tag_id";
     $criteria->params = array(':tag_id' => $tag->id);
     $questions = Question::model()->with('tags')->findAll($criteria);
     // User has just voted on a question
     $questionVotesModel = new QuestionVotes();
     if (isset($_POST['QuestionVotes'])) {
         $questionVotesModel->attributes = $_POST['QuestionVotes'];
         $questionVotesModel->created_by = Yii::app()->user->id;
         if ($questionVotesModel->validate()) {
             // TODO: If the user has previously voted on this, drop it
             $previousVote = QuestionVotes::model()->find('post_id=:post_id AND created_by=:user_id', array('post_id' => $questionVotesModel->post_id, 'user_id' => Yii::app()->user->id));
             if ($previousVote) {
                 $previousVote->delete();
             }
             $questionVotesModel->save();
             $this->redirect($this->createUrl('//questionanswer/main/index'));
         }
     }
     $this->render('tags', array('tag' => $tag, 'questions' => Question::model()->tag_overview($tag->id)));
 }
コード例 #8
0
 public function actionDetails()
 {
     $can_vote = false;
     $q_id = Yii::app()->Ini->v('id');
     $question = Questions::model()->findByPk($q_id);
     if (!Yii::app()->user->isGuest) {
         $viewed_by = Yii::app()->user->getId();
         $viewed_user_type = Yii::app()->user->role;
         $vote = QuestionVotes::model()->countByAttributes(array('question_id' => $q_id, 'voted_by' => $viewed_by, 'voted_user_type' => $viewed_user_type));
         if ($vote == 0 && ($question->owner_id != $viewed_by && $question->owner_user_type != $viewed_user_type)) {
             $can_vote = true;
         }
     } else {
         $viewed_by = 0;
         $viewed_user_type = 'guest';
     }
     $view = new QuestionViews();
     $view->question_id = $q_id;
     $view->viewed_by = $viewed_by;
     $view->viewed_user_type = $viewed_user_type;
     $view->save();
     $pie = new SimplePie();
     $pie->set_feed_url('http://media.handyman.com/feed/');
     $pie->init();
     $pie->handle_content_type();
     $param['feed'] = $pie;
     $this->pageTitle = 'Handyman.com Answers - ' . $question->title;
     $param['question'] = $question;
     $param['sidecats'] = Projecttypes::model()->findAll(array('order' => 'Name ASC'));
     $param['can_vote'] = $can_vote;
     $this->render('details', $param);
 }