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->id;
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(' ', $this->user->getSelfTags());
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;
103 $phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null;
106 if (empty($phones)) {
108 'label' => _m('Phone'),
116 for ($i = 0; $i < sizeof($phones); $i++) {
118 'label' => _m('Phone'),
120 'index' => intval($phones[$i]->value_index),
121 'rel' => $phones[$i]->rel,
122 'value' => $phones[$i]->field_value,
133 * Return all the sections of the extended profile
135 * @return array the big list of sections and fields
137 function getSections()
141 'label' => _m('Personal'),
144 'label' => _m('Full name'),
145 'profile' => 'fullname',
149 'label' => _m('Title'),
153 'label' => _m('Manager'),
155 'vcard' => 'x-manager',
158 'label' => _m('Location'),
159 'profile' => 'location'
162 'label' => _m('Bio'),
163 'type' => 'textarea',
167 'label' => _m('Tags'),
174 'label' => _m('Contact'),
176 'phone' => $this->getPhones(),
183 'label' => _m('Websites'),
190 'label' => _m('Personal'),
193 'label' => _m('Birthday'),
198 'label' => _m('Spouse\'s name'),
199 'vcard' => 'x-spouse',
202 'label' => _m('Kids\' names')
206 'experience' => array(
207 'label' => _m('Work experience'),
209 'experience' => array(
210 'type' => 'experience',
211 'label' => _m('Employer'),
215 'education' => array(
216 'label' => _m('Education'),
218 'education' => array(
219 'type' => 'education',
220 'label' => _m('Institution'),