]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ExtendedProfile/Profile_detail.php
delete the Bookmark if Notice::saveNew() fails
[quix0rs-gnu-social.git] / plugins / ExtendedProfile / Profile_detail.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET')) {
21     exit(1);
22 }
23
24 class Profile_detail extends Memcached_DataObject
25 {
26     public $__table = 'submirror';
27
28     public $id;
29
30     public $profile_id;
31     public $field;
32     public $field_index; // relative ordering of multiple values in the same field
33
34     public $value; // primary text value
35     public $rel; // detail for some field types; eg "home", "mobile", "work" for phones or "aim", "irc", "xmpp" for IM
36     public $ref_profile; // for people types, allows pointing to a known profile in the system
37
38     public $created;
39     public $modified;
40
41     public /*static*/ function staticGet($k, $v=null)
42     {
43         return parent::staticGet(__CLASS__, $k, $v);
44     }
45
46     /**
47      * return table definition for DB_DataObject
48      *
49      * DB_DataObject needs to know something about the table to manipulate
50      * instances. This method provides all the DB_DataObject needs to know.
51      *
52      * @return array array of column definitions
53      */
54
55     function table()
56     {
57         return array('id' =>  DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
58
59                      'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
60                      'field' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
61                      'field_index' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
62
63                      'value' => DB_DATAOBJECT_STR,
64                      'rel' => DB_DATAOBJECT_STR,
65                      'ref_profile' => DB_DATAOBJECT_ID,
66
67                      'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
68                      'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
69     }
70
71     static function schemaDef()
72     {
73         // @fixme need a reverse key on (subscribed, subscriber) as well
74         return array(new ColumnDef('id', 'integer',
75                                    null, false, 'PRI'),
76
77                      // @fixme need a unique index on these three
78                      new ColumnDef('profile_id', 'integer',
79                                    null, false),
80                      new ColumnDef('field', 'varchar',
81                                    16, false),
82                      new ColumnDef('field_index', 'integer',
83                                    null, false),
84
85                      new ColumnDef('value', 'text',
86                                    null, true),
87                      new ColumnDef('rel', 'varchar',
88                                    16, true),
89                      new ColumnDef('ref_profile', 'integer',
90                                    null, true),
91
92                      new ColumnDef('created', 'datetime',
93                                    null, false),
94                      new ColumnDef('modified', 'datetime',
95                                    null, false));
96     }
97
98     /**
99      * Temporary hack to set up the compound index, since we can't do
100      * it yet through regular Schema interface. (Coming for 1.0...)
101      *
102      * @param Schema $schema
103      * @return void
104      */
105     static function fixIndexes($schema)
106     {
107         try {
108             // @fixme this won't be a unique index... SIGH
109             $schema->createIndex('profile_detail', array('profile_id', 'field', 'field_index'));
110         } catch (Exception $e) {
111             common_log(LOG_ERR, __METHOD__ . ': ' . $e->getMessage());
112         }
113     }
114
115     /**
116      * return key definitions for DB_DataObject
117      *
118      * DB_DataObject needs to know about keys that the table has; this function
119      * defines them.
120      *
121      * @return array key definitions
122      */
123
124     function keys()
125     {
126         return array_keys($this->keyTypes());
127     }
128
129     /**
130      * return key definitions for Memcached_DataObject
131      *
132      * Our caching system uses the same key definitions, but uses a different
133      * method to get them.
134      *
135      * @return array key definitions
136      */
137
138     function keyTypes()
139     {
140         // @fixme keys
141         // need a sane key for reverse lookup too
142         return array('id' => 'K');
143     }
144
145     function sequenceKey()
146     {
147         return array('id', true);
148     }
149
150 }