]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/QnA/classes/QnA_Vote.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / QnA / classes / QnA_Vote.php
1 <?php
2 /**
3  * Data class to save users votes for
4  *
5  * PHP version 5
6  *
7  * @category QnA
8  * @package  StatusNet
9  * @author   Zach Copley <zach@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2011, StatusNet, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * For storing votes on question and answers
36  *
37  * @category QnA
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  *
43  * @see      DB_DataObject
44  */
45 class QnA_Vote extends Managed_DataObject
46 {
47     const UP   = 'http://activitystrea.ms/schema/1.0/like';
48     const DOWN = 'http://activityschema.org/object/dislike'; // Gar!
49
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
57
58     /**
59      * The One True Thingy that must be defined and declared.
60      */
61     public static function schemaDef()
62     {
63         return array(
64             'description' => 'For storing votes on questions and answers',
65             'fields' => array(
66                 'id' => array(
67                     'type'        => 'char',
68                     'length'      => 36,
69                     'not null'    => true,
70                     'description' => 'UUID of the vote'
71                 ),
72                 'question_id' => array(
73                     'type'        => 'char',
74                     'length'      => 36,
75                     'not null'    => true,
76                     'description' => 'UUID of question being voted on'
77                 ),
78                 'answer_id' => array(
79                     'type'        => 'char',
80                     'length'      => 36,
81                     'not null'    => true,
82                     'description' => 'UUID of answer being voted on'
83                 ),
84                 'vote'       => array('type' => 'int', 'size' => 'tiny'),
85                 'profile_id' => array('type' => 'int'),
86                 'created'    => array('type' => 'datetime', 'not null' => true),
87             ),
88             'primary key' => array('id'),
89             'indexes' => array(
90                 'profile_id_question_Id_index' => array(
91                     'profile_id',
92                     'question_id'
93                 ),
94                 'profile_id_question_Id_index' => array(
95                     'profile_id',
96                     'answer_id'
97                 )
98             )
99         );
100     }
101
102     /**
103      * Save a vote on a question or answer
104      *
105      * @param Profile  $profile
106      * @param QnA_Question the question being voted on
107      * @param QnA_Answer   the answer being voted on
108      * @param vote
109      * @param array
110      *
111      * @return Void
112      */
113     static function save($profile, $question, $answer, $vote)
114     {
115         $v = new QnA_Vote();
116         $v->id          = UUID::gen();
117         $v->profile_id  = $profile->id;
118         $v->question_id = $question->id;
119         $v->answer_id   = $answer->id;
120         $v->vote        = $vote;
121         $v->created     = common_sql_now();
122
123         common_log(LOG_DEBUG, "Saving vote: $v->id $v->vote");
124
125         $v->insert();
126     }
127 }