]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/FollowEveryone/User_followeveryone_prefs.php
Localisation updates from http://translatewiki.net.
[quix0rs-gnu-social.git] / plugins / FollowEveryone / User_followeveryone_prefs.php
1 <?php
2 /**
3  * Data class for counting greetings
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@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) 2009, 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 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 /**
37  * Data class for counting greetings
38  *
39  * We use the DB_DataObject framework for data classes in StatusNet. Each
40  * table maps to a particular data class, making it easier to manipulate
41  * data.
42  *
43  * Data classes should extend Memcached_DataObject, the (slightly misnamed)
44  * extension of DB_DataObject that provides caching, internationalization,
45  * and other bits of good functionality to StatusNet-specific data classes.
46  *
47  * @category Action
48  * @package  StatusNet
49  * @author   Evan Prodromou <evan@status.net>
50  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
51  * @link     http://status.net/
52  *
53  * @see      DB_DataObject
54  */
55 class User_followeveryone_prefs extends Memcached_DataObject
56 {
57     public $__table = 'user_followeveryone_prefs'; // table name
58     public $user_id;                               // int(4)  primary_key not_null
59     public $followeveryone;                        // tinyint(1)
60
61     /**
62      * Get an instance by key
63      *
64      * This is a utility method to get a single instance with a given key value.
65      *
66      * @param string $k Key to use to lookup (usually 'user_id' for this class)
67      * @param mixed  $v Value to lookup
68      *
69      * @return User_followeveryone_prefs object found, or null for no hits
70      */
71     function staticGet($k, $v=null)
72     {
73         return Memcached_DataObject::staticGet('User_followeveryone_prefs', $k, $v);
74     }
75
76     /**
77      * return table definition for DB_DataObject
78      *
79      * DB_DataObject needs to know something about the table to manipulate
80      * instances. This method provides all the DB_DataObject needs to know.
81      *
82      * @return array array of column definitions
83      */
84     function table()
85     {
86         return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
87                      'followeveryone' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL);
88     }
89
90     /**
91      * return key definitions for DB_DataObject
92      *
93      * DB_DataObject needs to know about keys that the table has, since it
94      * won't appear in StatusNet's own keys list. In most cases, this will
95      * simply reference your keyTypes() function.
96      *
97      * @return array list of key field names
98      */
99     function keys()
100     {
101         return array_keys($this->keyTypes());
102     }
103
104     /**
105      * return key definitions for Memcached_DataObject
106      *
107      * Our caching system uses the same key definitions, but uses a different
108      * method to get them. This key information is used to store and clear
109      * cached data, so be sure to list any key that will be used for static
110      * lookups.
111      *
112      * @return array associative array of key definitions, field name to type:
113      *         'K' for primary key: for compound keys, add an entry for each component;
114      *         'U' for unique keys: compound keys are not well supported here.
115      */
116     function keyTypes()
117     {
118         return array('user_id' => 'K');
119     }
120
121     /**
122      * Magic formula for non-autoincrementing integer primary keys
123      *
124      * If a table has a single integer column as its primary key, DB_DataObject
125      * assumes that the column is auto-incrementing and makes a sequence table
126      * to do this incrementation. Since we don't need this for our class, we
127      * overload this method and return the magic formula that DB_DataObject needs.
128      *
129      * @return array magic three-false array that stops auto-incrementing.
130      */
131     function sequenceKey()
132     {
133         return array(false, false, false);
134     }
135
136     static function followEveryone($user_id)
137     {
138         $ufep = self::staticGet('user_id', $user_id);
139
140         if (empty($ufep)) {
141             return true;
142         } else {
143             return (bool)$ufep->followeveryone;
144         }
145     }
146
147     static function savePref($user_id, $followEveryone)
148     {
149         $ufep = self::staticGet('user_id', $user_id);
150
151         if (empty($ufep)) {
152             $ufep = new User_followeveryone_prefs();
153             $ufep->user_id = $user_id;
154             $ufep->followeveryone = $followEveryone;
155             $ufep->insert();
156         } else {
157             $orig = clone($ufep);
158             $ufep->followeveryone = $followEveryone;
159             $ufep->update();
160         }
161
162         return true;
163     }
164 }