3 * Data class for storing IP addresses of new registrants.
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
37 * Data class for storing IP addresses of new registrants.
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://status.net/
45 class Registration_ip extends Memcached_DataObject
47 public $__table = 'registration_ip'; // table name
48 public $user_id; // int(4) primary_key not_null
49 public $ipaddress; // varchar(15)
50 public $created; // timestamp
53 * Get an instance by key
55 * @param string $k Key to use to lookup (usually 'user_id' for this class)
56 * @param mixed $v Value to lookup
58 * @return User_greeting_count object found, or null for no hits
61 function staticGet($k, $v=null)
63 return Memcached_DataObject::staticGet('Registration_ip', $k, $v);
67 * return table definition for DB_DataObject
69 * @return array array of column definitions
73 return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
74 'ipaddress' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
75 'created' => DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL);
79 * return key definitions for DB_DataObject
81 * DB_DataObject needs to know about keys that the table has; this function
84 * @return array key definitions
88 return array('user_id' => 'K');
92 * return key definitions for Memcached_DataObject
94 * Our caching system uses the same key definitions, but uses a different
97 * @return array key definitions
101 return $this->keys();
105 * Magic formula for non-autoincrementing integer primary keys
107 * If a table has a single integer column as its primary key, DB_DataObject
108 * assumes that the column is auto-incrementing and makes a sequence table
109 * to do this incrementation. Since we don't need this for our class, we
110 * overload this method and return the magic formula that DB_DataObject needs.
112 * @return array magic three-false array that stops auto-incrementing.
115 function sequenceKey()
117 return array(false, false, false);
121 * Get the users who've registered with this ip address.
123 * @param Array $ipaddress IP address to check for
125 * @return Array IDs of users who registered with this address.
128 static function usersByIP($ipaddress)
132 $ri = new Registration_ip();
133 $ri->ipaddress = $ipaddress;
136 while ($ri->fetch()) {
137 $ids[] = $ri->user_id;