]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Poll/Poll_response.php
fix off-by-one error in poll results display
[quix0rs-gnu-social.git] / plugins / Poll / Poll_response.php
1 <?php
2 /**
3  * Data class to record responses to polls
4  *
5  * PHP version 5
6  *
7  * @category PollPlugin
8  * @package  StatusNet
9  * @author   Brion Vibber <brion@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 the poll options and such
36  *
37  * @category PollPlugin
38  * @package  StatusNet
39  * @author   Brion Vibber <brion@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
46 class Poll_response extends Managed_DataObject
47 {
48     public $__table = 'poll_response'; // table name
49     public $poll_id;     // char(36) primary key not null -> UUID
50     public $profile_id;  // int -> profile.id
51     public $selection;   // int -> choice #
52     public $created;     // datetime
53
54     /**
55      * Get an instance by key
56      *
57      * This is a utility method to get a single instance with a given key value.
58      *
59      * @param string $k Key to use to lookup (usually 'user_id' for this class)
60      * @param mixed  $v Value to lookup
61      *
62      * @return User_greeting_count object found, or null for no hits
63      *
64      */
65
66     function staticGet($k, $v=null)
67     {
68         return Memcached_DataObject::staticGet('Poll_response', $k, $v);
69     }
70
71     /**
72      * Get an instance by compound key
73      *
74      * This is a utility method to get a single instance with a given set of
75      * key-value pairs. Usually used for the primary key for a compound key; thus
76      * the name.
77      *
78      * @param array $kv array of key-value mappings
79      *
80      * @return Bookmark object found, or null for no hits
81      *
82      */
83
84     function pkeyGet($kv)
85     {
86         return Memcached_DataObject::pkeyGet('Poll_response', $kv);
87     }
88
89     /**
90      * The One True Thingy that must be defined and declared.
91      */
92     public static function schemaDef()
93     {
94         return array(
95             'description' => 'Record of responses to polls',
96             'fields' => array(
97                 'poll_id' => array('type' => 'char', 'length' => 36, 'not null' => true, 'description' => 'UUID'),
98                 'profile_id' => array('type' => 'int'),
99                 'selection' => array('type' => 'int'),
100                 'created' => array('type' => 'datetime', 'not null' => true),
101             ),
102             'unique keys' => array(
103                 'poll_response_poll_id_profile_id_key' => array('poll_id', 'profile_id'),
104             ),
105             'indexes' => array(
106                 'poll_response_profile_id_poll_id_index' => array('profile_id', 'poll_id'),
107             )
108         );
109     }
110 }