| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  |  * Data class to save users votes for | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  |  * @category  QnA | 
					
						
							|  |  |  |  * @package   GNUsocial | 
					
						
							|  |  |  |  * @author    Zach Copley <zach@status.net> | 
					
						
							|  |  |  |  * @copyright 2011 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  | defined('GNUSOCIAL') || die(); | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * For storing votes on question and answers | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  |  * @copyright 2011 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  |  * @see       DB_DataObject | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | class QnA_Vote extends Managed_DataObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const UP   = 'http://activitystrea.ms/schema/1.0/like'; | 
					
						
							|  |  |  |     const DOWN = 'http://activityschema.org/object/dislike'; // Gar!
 | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-21 15:50:36 -07:00
										 |  |  |     public $__table = 'qna_vote'; // table name
 | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |     public $id;          // char(36) primary key not null -> UUID
 | 
					
						
							|  |  |  |     public $question_id; // char(36) -> question.id UUID
 | 
					
						
							|  |  |  |     public $answer_id;   // char(36) -> question.id UUID
 | 
					
						
							| 
									
										
										
										
											2011-03-21 15:50:36 -07:00
										 |  |  |     public $type;        // tinyint -> vote: up (1) or down (-1)
 | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |     public $profile_id;  // int -> question.id
 | 
					
						
							|  |  |  |     public $created;     // datetime
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * The One True Thingy that must be defined and declared. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function schemaDef() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return array( | 
					
						
							|  |  |  |             'description' => 'For storing votes on questions and answers', | 
					
						
							|  |  |  |             'fields' => array( | 
					
						
							|  |  |  |                 'id' => array( | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  |                     'type'        => 'char', | 
					
						
							|  |  |  |                     'length'      => 36, | 
					
						
							|  |  |  |                     'not null'    => true, | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |                     'description' => 'UUID of the vote' | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 'question_id' => array( | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  |                     'type'        => 'char', | 
					
						
							|  |  |  |                     'length'      => 36, | 
					
						
							|  |  |  |                     'not null'    => true, | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |                     'description' => 'UUID of question being voted on' | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 'answer_id' => array( | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  |                     'type'        => 'char', | 
					
						
							|  |  |  |                     'length'      => 36, | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |                     'not null'    => true, | 
					
						
							|  |  |  |                     'description' => 'UUID of answer being voted on' | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 'vote'       => array('type' => 'int', 'size' => 'tiny'), | 
					
						
							|  |  |  |                 'profile_id' => array('type' => 'int'), | 
					
						
							|  |  |  |                 'created'    => array('type' => 'datetime', 'not null' => true), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             'primary key' => array('id'), | 
					
						
							|  |  |  |             'indexes' => array( | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  |                 'qna_vote_profile_id_question_id_idx' => array( | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  |                     'profile_id', | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |                     'question_id' | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  |                 'qna_vote_profile_id_question_id_idx' => array( | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  |                     'profile_id', | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |                     'answer_id' | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Save a vote on a question or answer | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Profile  $profile | 
					
						
							|  |  |  |      * @param QnA_Question the question being voted on | 
					
						
							|  |  |  |      * @param QnA_Answer   the answer being voted on | 
					
						
							|  |  |  |      * @param vote | 
					
						
							|  |  |  |      * @param array | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return Void | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-09-11 12:07:54 +03:00
										 |  |  |     public static function save($profile, $question, $answer, $vote) | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |     { | 
					
						
							|  |  |  |         $v = new QnA_Vote(); | 
					
						
							|  |  |  |         $v->id          = UUID::gen(); | 
					
						
							|  |  |  |         $v->profile_id  = $profile->id; | 
					
						
							|  |  |  |         $v->question_id = $question->id; | 
					
						
							|  |  |  |         $v->answer_id   = $answer->id; | 
					
						
							|  |  |  |         $v->vote        = $vote; | 
					
						
							|  |  |  |         $v->created     = common_sql_now(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         common_log(LOG_DEBUG, "Saving vote: $v->id $v->vote"); | 
					
						
							| 
									
										
										
										
											2011-04-19 21:54:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-20 19:24:35 -07:00
										 |  |  |         $v->insert(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |