123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class QnA_Vote extends Managed_DataObject
- {
- const UP = 'http://activitystrea.ms/schema/1.0/like';
- const DOWN = 'http://activityschema.org/object/dislike';
- public $__table = 'qna_vote';
- public $id;
- public $question_id;
- public $answer_id;
- public $type;
- public $profile_id;
- public $created;
-
- public static function schemaDef()
- {
- return array(
- 'description' => 'For storing votes on questions and answers',
- 'fields' => array(
- 'id' => array(
- 'type' => 'char',
- 'length' => 36,
- 'not null' => true,
- 'description' => 'UUID of the vote'
- ),
- 'question_id' => array(
- 'type' => 'char',
- 'length' => 36,
- 'not null' => true,
- 'description' => 'UUID of question being voted on'
- ),
- 'answer_id' => array(
- 'type' => 'char',
- 'length' => 36,
- '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(
- 'profile_id_question_Id_index' => array(
- 'profile_id',
- 'question_id'
- ),
- 'profile_id_question_Id_index' => array(
- 'profile_id',
- 'answer_id'
- )
- )
- );
- }
-
- static function save($profile, $question, $answer, $vote)
- {
- $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");
- $v->insert();
- }
- }
|