コード例 #1
0
 /**
  * A question has been voted on 
  * This method will determine what type
  * of vote has been cast and what karma to give.
  * 
  * Key Votes:
  * - up vote on question
  * - up vote on answer
  * - marked as best answer
  *
  * @param type $event
  */
 public static function onQuestionVoteAfterSave($event)
 {
     switch ($event->sender->vote_type) {
         case "up":
             // Only vote on questions and answers
             switch ($event->sender->vote_on) {
                 case "question":
                     Karma::model()->addKarma('question_up_vote', $event->sender->created_by);
                     break;
                 case "answer":
                     Karma::model()->addKarma('answer_up_vote', $event->sender->created_by);
                     break;
             }
             break;
         case "accepted_answer":
             Karma::model()->addKarma('accepted_answer', $event->sender->created_by);
             break;
     }
 }
コード例 #2
0
 /**
  * Deletes a karma record
  */
 public function actionDelete()
 {
     $id = (int) Yii::app()->request->getQuery('id');
     $doit = (int) Yii::app()->request->getQuery('doit');
     $karma = Karma::model()->resetScope()->findByPk($id);
     if ($karma == null) {
         throw new CHttpException(404, "Karma record not found");
     }
     if ($doit == 2) {
         $this->forcePostRequest();
         $karma->delete();
         $this->redirect($this->createUrl('index'));
     }
     $this->render('delete', array('model' => $karma));
 }
コード例 #3
0
 /** 
  * Private method that handles assinging
  * karma to a user
  * @param string $karma_name
  * @param int $user_id
  * @return bool
  */
 public function addKarma($karma_name, $user_id)
 {
     // First find the karma record
     $karma = Karma::model()->findByAttributes(array('name' => $karma_name));
     if ($karma) {
         KarmaUser::model()->attachKarma($user_id, $karma->id);
         return true;
     } else {
         return false;
     }
 }