3 * Data class to save users votes for
9 * @author Zach Copley <zach@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2011, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * For storing votes on question and answers
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
45 class QnA_Vote extends Managed_DataObject
47 const UP = 'http://activitystrea.ms/schema/1.0/like';
48 const DOWN = 'http://activityschema.org/object/dislike'; // Gar!
50 public $__table = 'qna_vote'; // table name
51 public $id; // char(36) primary key not null -> UUID
52 public $question_id; // char(36) -> question.id UUID
53 public $answer_id; // char(36) -> question.id UUID
54 public $type; // tinyint -> vote: up (1) or down (-1)
55 public $profile_id; // int -> question.id
56 public $created; // datetime
59 * The One True Thingy that must be defined and declared.
61 public static function schemaDef()
64 'description' => 'For storing votes on questions and answers',
70 'description' => 'UUID of the vote'
72 'question_id' => array(
76 'description' => 'UUID of question being voted on'
82 'description' => 'UUID of answer being voted on'
84 'vote' => array('type' => 'int', 'size' => 'tiny'),
85 'profile_id' => array('type' => 'int'),
86 'created' => array('type' => 'datetime', 'not null' => true),
88 'primary key' => array('id'),
90 'profile_id_question_Id_index' => array(
94 'profile_id_question_Id_index' => array(
103 * Save a vote on a question or answer
105 * @param Profile $profile
106 * @param QnA_Question the question being voted on
107 * @param QnA_Answer the answer being voted on
113 static function save($profile, $question, $answer, $vote)
116 $v->id = UUID::gen();
117 $v->profile_id = $profile->id;
118 $v->question_id = $question->id;
119 $v->answer_id = $answer->id;
121 $v->created = common_sql_now();
123 common_log(LOG_DEBUG, "Saving vote: $v->id $v->vote");