3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('STATUSNET')) {
25 * Class to represent extended profile data
34 * @param Profile $profile
36 function __construct(Profile $profile)
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));
44 //common_debug(var_export($this->fields, true));
48 * Load extended profile fields
50 * @return array $fields the list of fields
54 $detail = new Profile_detail();
55 $detail->profile_id = $this->profile->getID();
60 while ($detail->fetch()) {
61 $fields[$detail->field_name][] = clone($detail);
68 * Get a the self-tags associated with this profile
70 * @return string the concatenated string of tags
74 return implode(' ', Profile_tag::getSelfTagsArray($this->profile));
78 * Return a simple string value. Checks for fields that should
79 * be stored in the regular profile and returns values from it
82 * @param string $name name of the detail field to get the
85 * @return string the value
87 function getTextValue($name)
89 $key = strtolower($name);
90 $profileFields = array('fullname', 'location', 'bio');
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;
101 function getDateValue($name) {
102 $key = strtolower($name);
103 if (array_key_exists($key, $this->fields)) {
104 return $this->fields[$key][0]->date;
110 // XXX: getPhones, getIms, and getWebsites pretty much do the same thing,
114 $phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null;
117 if (empty($phones)) {
119 // TRANS: Field label for extended profile properties.
120 'label' => _m('Phone'),
128 for ($i = 0; $i < sizeof($phones); $i++) {
130 // TRANS: Field label for extended profile properties.
131 'label' => _m('Phone'),
133 'index' => intval($phones[$i]->value_index),
134 'rel' => $phones[$i]->rel,
135 'value' => $phones[$i]->field_value,
147 $ims = (isset($this->fields['im'])) ? $this->fields['im'] : null;
152 // TRANS: Field label for extended profile properties (Instant Messaging).
157 for ($i = 0; $i < sizeof($ims); $i++) {
159 // TRANS: Field label for extended profile properties (Instant Messaging).
162 'index' => intval($ims[$i]->value_index),
163 'rel' => $ims[$i]->rel,
164 'value' => $ims[$i]->field_value,
173 function getWebsites()
175 $sites = (isset($this->fields['website'])) ? $this->fields['website'] : null;
180 // TRANS: Field label for extended profile properties.
181 'label' => _m('Website'),
185 for ($i = 0; $i < sizeof($sites); $i++) {
187 // TRANS: Field label for extended profile properties.
188 'label' => _m('Website'),
190 'index' => intval($sites[$i]->value_index),
191 'rel' => $sites[$i]->rel,
192 'value' => $sites[$i]->field_value,
201 function getExperiences()
203 $companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
204 $start = (isset($this->fields['start'])) ? $this->fields['start'] : null;
205 $end = (isset($this->fields['end'])) ? $this->fields['end'] : null;
209 if (empty($companies)) {
211 // TRANS: Field label for extended profile properties.
212 'label' => _m('Employer'),
213 'type' => 'experience',
221 for ($i = 0; $i < sizeof($companies); $i++) {
223 // TRANS: Field label for extended profile properties.
224 'label' => _m('Employer'),
225 'type' => 'experience',
226 'company' => $companies[$i]->field_value,
227 'index' => intval($companies[$i]->value_index),
228 'current' => $end[$i]->rel,
229 'start' => $start[$i]->date,
230 'end' => $end[$i]->date
238 function getEducation()
240 $schools = (isset($this->fields['school'])) ? $this->fields['school'] : null;
241 $degrees = (isset($this->fields['degree'])) ? $this->fields['degree'] : null;
242 $descs = (isset($this->fields['degree_descr'])) ? $this->fields['degree_descr'] : null;
243 $start = (isset($this->fields['school_start'])) ? $this->fields['school_start'] : null;
244 $end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null;
247 if (empty($schools)) {
249 'type' => 'education',
250 // TRANS: Field label for extended profile properties.
251 'label' => _m('Institution'),
254 'description' => null,
260 for ($i = 0; $i < sizeof($schools); $i++) {
262 'type' => 'education',
263 // TRANS: Field label for extended profile properties.
264 'label' => _m('Institution'),
265 'school' => $schools[$i]->field_value,
266 'degree' => isset($degrees[$i]->field_value) ? $degrees[$i]->field_value : null,
267 'description' => isset($descs[$i]->field_value) ? $descs[$i]->field_value : null,
268 'index' => intval($schools[$i]->value_index),
269 'start' => $start[$i]->date,
270 'end' => $end[$i]->date
280 * Return all the sections of the extended profile
282 * @return array the big list of sections and fields
284 function getSections()
288 // TRANS: Field label for extended profile properties.
289 'label' => _m('Personal'),
292 // TRANS: Field label for extended profile properties.
293 'label' => _m('Full name'),
294 'profile' => 'fullname',
298 // TRANS: Field label for extended profile properties.
299 'label' => _m('Title'),
303 // TRANS: Field label for extended profile properties.
304 'label' => _m('Manager'),
306 'vcard' => 'x-manager',
309 // TRANS: Field label for extended profile properties.
310 'label' => _m('Location'),
311 'profile' => 'location'
314 // TRANS: Field label for extended profile properties.
315 'label' => _m('Bio'),
316 'type' => 'textarea',
320 // TRANS: Field label for extended profile properties.
321 'label' => _m('Tags'),
328 // TRANS: Field label for extended profile properties.
329 'label' => _m('Contact'),
331 'phone' => $this->getPhones(),
332 'im' => $this->getIms(),
333 'website' => $this->getWebsites()
337 // TRANS: Field label for extended profile properties.
338 'label' => _m('Personal'),
341 // TRANS: Field label for extended profile properties.
342 'label' => _m('Birthday'),
347 // TRANS: Field label for extended profile properties.
348 'label' => _m('Spouse\'s name'),
349 'vcard' => 'x-spouse',
352 // TRANS: Field label for extended profile properties.
353 'label' => _m('Kids\' names')
357 'experience' => array(
358 // TRANS: Field label for extended profile properties.
359 'label' => _m('Work experience'),
361 'experience' => $this->getExperiences()
364 'education' => array(
365 // TRANS: Field label for extended profile properties.
366 'label' => _m('Education'),
368 'education' => $this->getEducation()