]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ExtendedProfile/classes/Profile_detail.php
94e52c396c6a2506c3d97a8228b0747074062703
[quix0rs-gnu-social.git] / plugins / ExtendedProfile / classes / 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 /**
25  * DataObject class to store extended profile fields. Allows for storing
26  * multiple values per a "field_name" (field_name property is not unique).
27  *
28  * Example:
29  *
30  *     Jed's Phone Numbers
31  *     home  : 510-384-1992
32  *     mobile: 510-719-1139
33  *     work  : 415-231-1121
34  *
35  * We can store these phone numbers in a "field" represented by three
36  * Profile_detail objects, each named 'phone_number' like this:
37  *
38  *     $phone1 = new Profile_detail();
39  *     $phone1->field_name  = 'phone_number';
40  *     $phone1->rel         = 'home';
41  *     $phone1->field_value = '510-384-1992';
42  *     $phone1->value_index = 1;
43  *
44  *     $phone1 = new Profile_detail();
45  *     $phone1->field_name  = 'phone_number';
46  *     $phone1->rel         = 'mobile';
47  *     $phone1->field_value = '510-719-1139';
48  *     $phone1->value_index = 2;
49  *
50  *     $phone1 = new Profile_detail();
51  *     $phone1->field_name  = 'phone_number';
52  *     $phone1->rel         = 'work';
53  *     $phone1->field_value = '415-231-1121';
54  *     $phone1->value_index = 3;
55  *
56  */
57 class Profile_detail extends Managed_DataObject
58 {
59     public $__table = 'profile_detail';
60
61     public $id;
62     public $profile_id;  // profile this is for
63     public $rel;         // detail for some field types; eg "home", "mobile", "work" for phones or "aim", "irc", "xmpp" for IM
64     public $field_name;  // name
65     public $field_value; // primary text value
66     public $value_index; // relative ordering of multiple values in the same field
67     public $date;        // related date
68     public $ref_profile; // for people types, allows pointing to a known profile in the system
69     public $created;
70     public $modified;
71
72     /**
73      * Get an instance by key
74      *
75      * This is a utility method to get a single instance with a given key value.
76      *
77      * @param string $k Key to use to lookup
78      * @param mixed  $v Value to lookup
79      *
80      * @return User_greeting_count object found, or null for no hits
81      *
82      */
83     function staticGet($k, $v=null)
84     {
85         return Memcached_DataObject::staticGet('Profile_detail', $k, $v);
86     }
87
88     /**
89      * Get an instance by compound key
90      *
91      * This is a utility method to get a single instance with a given set of
92      * key-value pairs. Usually used for the primary key for a compound key; thus
93      * the name.
94      *
95      * @param array $kv array of key-value mappings
96      *
97      * @return Bookmark object found, or null for no hits
98      *
99      */
100     function pkeyGet($kv)
101     {
102         return Memcached_DataObject::pkeyGet('Profile_detail', $kv);
103     }
104
105     static function schemaDef()
106     {
107         return array(
108             // No need for i18n. Table properties.
109             'description'
110                 => 'Additional profile details for the ExtendedProfile plugin',
111             'fields'      => array(
112                 'id'          => array('type' => 'serial', 'not null' => true),
113                 'profile_id'  => array('type' => 'int', 'not null' => true),
114                 'field_name'  => array(
115                     'type'     => 'varchar',
116                     'length'   => 16,
117                     'not null' => true
118                 ),
119                 'value_index' => array('type' => 'int'),
120                 'field_value' => array('type' => 'text'),
121                 'date'        => array('type' => 'datetime'),
122                 'rel'         => array('type' => 'varchar', 'length' => 16),
123                 'rel_profile' => array('type' => 'int'),
124                 'created'     => array(
125                     'type'     => 'datetime',
126                     'not null' => true
127                  ),
128                 'modified'    => array(
129                     'type' => 'timestamp',
130                     'not null' => true
131                 ),
132             ),
133             'primary key' => array('id'),
134             'unique keys' => array(
135                 'profile_detail_profile_id_field_name_value_index'
136                     => array('profile_id', 'field_name', 'value_index'),
137             )
138         );
139     }
140 }