]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ExtendedProfile/classes/Profile_detail.php
Plugins with classes that extend Managed_DataObject get better code reuse
[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 compound key
74      *
75      * This is a utility method to get a single instance with a given set of
76      * key-value pairs. Usually used for the primary key for a compound key; thus
77      * the name.
78      *
79      * @param array $kv array of key-value mappings
80      *
81      * @return Bookmark object found, or null for no hits
82      *
83      */
84     function pkeyGet($kv)
85     {
86         return Memcached_DataObject::pkeyGet('Profile_detail', $kv);
87     }
88
89     static function schemaDef()
90     {
91         return array(
92             // No need for i18n. Table properties.
93             'description'
94                 => 'Additional profile details for the ExtendedProfile plugin',
95             'fields'      => array(
96                 'id'          => array('type' => 'serial', 'not null' => true),
97                 'profile_id'  => array('type' => 'int', 'not null' => true),
98                 'field_name'  => array(
99                     'type'     => 'varchar',
100                     'length'   => 16,
101                     'not null' => true
102                 ),
103                 'value_index' => array('type' => 'int'),
104                 'field_value' => array('type' => 'text'),
105                 'date'        => array('type' => 'datetime'),
106                 'rel'         => array('type' => 'varchar', 'length' => 16),
107                 'rel_profile' => array('type' => 'int'),
108                 'created'     => array(
109                     'type'     => 'datetime',
110                     'not null' => true
111                  ),
112                 'modified'    => array(
113                     'type' => 'timestamp',
114                     'not null' => true
115                 ),
116             ),
117             'primary key' => array('id'),
118             'unique keys' => array(
119                 'profile_detail_profile_id_field_name_value_index'
120                     => array('profile_id', 'field_name', 'value_index'),
121             )
122         );
123     }
124 }