]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ExtendedProfile/extendedprofile.php
94a5ef482680ddf359000b2d4a0941799c7e0f2d
[quix0rs-gnu-social.git] / plugins / ExtendedProfile / extendedprofile.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  * Class to represent extended profile data
26  */
27 class ExtendedProfile
28 {
29     protected $fields;
30
31     /**
32      * Constructor
33      *
34      * @param Profile $profile
35      */
36     function __construct(Profile $profile)
37     {
38         $this->profile  = $profile;
39         $this->user     = $profile->getUser();
40         $this->fields   = $this->loadFields();
41         $this->sections = $this->getSections();
42         //common_debug(var_export($this->sections, true));
43
44         //common_debug(var_export($this->fields, true));
45     }
46
47     /**
48      * Load extended profile fields
49      *
50      * @return array $fields the list of fields
51      */
52     function loadFields()
53     {
54         $detail = new Profile_detail();
55         $detail->profile_id = $this->profile->id;
56         $detail->find();
57
58         $fields = array();
59
60         while ($detail->fetch()) {
61             $fields[$detail->field_name][] = clone($detail);
62         }
63
64         return $fields;
65     }
66
67     /**
68      * Get a the self-tags associated with this profile
69      *
70      * @return string the concatenated string of tags
71      */
72     function getTags()
73     {
74         return implode(' ', $this->user->getSelfTags());
75     }
76
77     /**
78      * Return a simple string value. Checks for fields that should
79      * be stored in the regular profile and returns values from it
80      * if appropriate.
81      *
82      * @param string $name name of the detail field to get the
83      *                     value from
84      *
85      * @return string the value
86      */
87     function getTextValue($name)
88     {
89         $key           = strtolower($name);
90         $profileFields = array('fullname', 'location', 'bio');
91
92         if (in_array($key, $profileFields)) {
93             return $this->profile->$name;
94         } else if (array_key_exists($key, $this->fields)) {
95             return $this->fields[$key][0]->field_value;
96         } else {
97             return null;
98         }
99     }
100
101     function getPhones()
102     {
103         $phones  = $this->fields['phone'];
104         $pArrays = array();
105
106         if (empty($phones)) {
107             $pArrays[] = array(
108                 'label' => _m('Phone'),
109                 'index' => 0,
110                 'type'  => 'phone',
111                 'vcard' => 'tel',
112                 'multi' => true
113             );
114         } else {
115             for ($i = 0; $i < sizeof($phones); $i++) {
116                 $pa = array(
117                     'label' => _m('Phone'),
118                     'type'  => 'phone',
119                     'index' => intva($phones[$i]->value_index),
120                     'rel'   => $phones[$i]->rel,
121                     'value' => $phones[$i]->field_value,
122                     'vcard' => 'tel'
123                 );
124                 // Last phone record should allow adding more
125                 if ($i == sizeof($phones) - 1) {
126                     $pa['multi'] = true;
127                 }
128                $pArrays[] = $pa;
129             }
130         }
131         return $pArrays;
132     }
133
134     /**
135      *  Return all the sections of the extended profile
136      *
137      * @return array the big list of sections and fields
138      */
139     function getSections()
140     {
141         return array(
142             'basic' => array(
143                 'label' => _m('Personal'),
144                 'fields' => array(
145                     'fullname' => array(
146                         'label' => _m('Full name'),
147                         'profile' => 'fullname',
148                         'vcard' => 'fn',
149                     ),
150                     'title' => array(
151                         'label' => _m('Title'),
152                         'vcard' => 'title',
153                     ),
154                     'manager' => array(
155                         'label' => _m('Manager'),
156                         'type' => 'person',
157                         'vcard' => 'x-manager',
158                     ),
159                     'location' => array(
160                         'label' => _m('Location'),
161                         'profile' => 'location'
162                     ),
163                     'bio' => array(
164                         'label' => _m('Bio'),
165                         'type' => 'textarea',
166                         'profile' => 'bio',
167                     ),
168                     'tags' => array(
169                         'label' => _m('Tags'),
170                         'type' => 'tags',
171                         'profile' => 'tags',
172                     ),
173                 ),
174             ),
175             'contact' => array(
176                 'label' => _m('Contact'),
177                 'fields' => array(
178                     'phone' => $this->getPhones(),
179                     'im' => array(
180                         'label' => _m('IM'),
181                         'type' => 'im',
182                         'multi' => true,
183                     ),
184                     'website' => array(
185                         'label' => _m('Websites'),
186                         'type' => 'website',
187                         'multi' => true,
188                     ),
189                 ),
190             ),
191             'personal' => array(
192                 'label' => _m('Personal'),
193                 'fields' => array(
194                     'birthday' => array(
195                         'label' => _m('Birthday'),
196                         'type' => 'date',
197                         'vcard' => 'bday',
198                     ),
199                     'spouse' => array(
200                         'label' => _m('Spouse\'s name'),
201                         'vcard' => 'x-spouse',
202                     ),
203                     'kids' => array(
204                         'label' => _m('Kids\' names')
205                     ),
206                 ),
207             ),
208             'experience' => array(
209                 'label' => _m('Work experience'),
210                 'fields' => array(
211                     'experience' => array(
212                         'type' => 'experience',
213                         'label' => _m('Employer'),
214                     ),
215                 ),
216             ),
217             'education' => array(
218                 'label' => _m('Education'),
219                 'fields' => array(
220                     'education' => array(
221                         'type' => 'education',
222                         'label' => _m('Institution'),
223                     ),
224                 ),
225             ),
226         );
227     }
228 }