2011-02-03 00:23:24 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Class to represent extended profile data
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
class ExtendedProfile
|
|
|
|
{
|
2011-03-10 03:27:21 +00:00
|
|
|
protected $fields;
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
|
|
|
*/
|
2011-02-03 01:29:34 +00:00
|
|
|
function __construct(Profile $profile)
|
|
|
|
{
|
2011-03-09 03:20:43 +00:00
|
|
|
$this->profile = $profile;
|
|
|
|
$this->user = $profile->getUser();
|
2011-02-03 01:29:34 +00:00
|
|
|
$this->sections = $this->getSections();
|
2011-03-09 03:20:43 +00:00
|
|
|
$this->fields = $this->loadFields();
|
2011-03-10 22:14:21 +00:00
|
|
|
//common_debug(var_export($this->fields, true));
|
2011-02-03 01:29:34 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Load extended profile fields
|
|
|
|
*
|
|
|
|
* @return array $fields the list of fields
|
|
|
|
*/
|
2011-02-03 01:29:34 +00:00
|
|
|
function loadFields()
|
|
|
|
{
|
|
|
|
$detail = new Profile_detail();
|
|
|
|
$detail->profile_id = $this->profile->id;
|
|
|
|
$detail->find();
|
2011-03-08 05:34:57 +00:00
|
|
|
|
|
|
|
$fields = array();
|
|
|
|
|
|
|
|
while ($detail->fetch()) {
|
2011-03-10 02:00:24 +00:00
|
|
|
$fields[$detail->field_name][] = clone($detail);
|
2011-02-03 01:29:34 +00:00
|
|
|
}
|
2011-03-09 03:20:43 +00:00
|
|
|
|
2011-02-03 01:29:34 +00:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Get a the self-tags associated with this profile
|
|
|
|
*
|
|
|
|
* @return string the concatenated string of tags
|
|
|
|
*/
|
|
|
|
function getTags()
|
|
|
|
{
|
|
|
|
return implode(' ', $this->user->getSelfTags());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a simple string value. Checks for fields that should
|
|
|
|
* be stored in the regular profile and returns values from it
|
|
|
|
* if appropriate.
|
|
|
|
*
|
|
|
|
* @param string $name name of the detail field to get the
|
|
|
|
* value from
|
|
|
|
*
|
|
|
|
* @return string the value
|
|
|
|
*/
|
|
|
|
function getTextValue($name)
|
|
|
|
{
|
2011-03-10 03:27:21 +00:00
|
|
|
$key = strtolower($name);
|
2011-03-09 03:20:43 +00:00
|
|
|
$profileFields = array('fullname', 'location', 'bio');
|
|
|
|
|
2011-03-10 03:27:21 +00:00
|
|
|
if (in_array($key, $profileFields)) {
|
2011-03-09 03:20:43 +00:00
|
|
|
return $this->profile->$name;
|
2011-03-10 03:27:21 +00:00
|
|
|
} else if (array_key_exists($key, $this->fields)) {
|
|
|
|
return $this->fields[$key][0]->field_value;
|
2011-03-09 03:20:43 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-10 22:14:21 +00:00
|
|
|
|
|
|
|
function getPhones()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'label' => _m('Phone'),
|
|
|
|
'type' => 'phone',
|
|
|
|
'multi' => true,
|
|
|
|
'index' => 8123,
|
|
|
|
'rel' => 'home',
|
|
|
|
'value' => '510-528-0079',
|
|
|
|
'vcard' => 'tel'
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-03-09 03:20:43 +00:00
|
|
|
/**
|
|
|
|
* Return all the sections of the extended profile
|
|
|
|
*
|
|
|
|
* @return array the big list of sections and fields
|
|
|
|
*/
|
2011-02-03 00:23:24 +00:00
|
|
|
function getSections()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'basic' => array(
|
|
|
|
'label' => _m('Personal'),
|
|
|
|
'fields' => array(
|
|
|
|
'fullname' => array(
|
|
|
|
'label' => _m('Full name'),
|
|
|
|
'profile' => 'fullname',
|
|
|
|
'vcard' => 'fn',
|
|
|
|
),
|
|
|
|
'title' => array(
|
|
|
|
'label' => _m('Title'),
|
|
|
|
'vcard' => 'title',
|
|
|
|
),
|
|
|
|
'manager' => array(
|
|
|
|
'label' => _m('Manager'),
|
|
|
|
'type' => 'person',
|
|
|
|
'vcard' => 'x-manager',
|
|
|
|
),
|
|
|
|
'location' => array(
|
|
|
|
'label' => _m('Location'),
|
|
|
|
'profile' => 'location'
|
|
|
|
),
|
|
|
|
'bio' => array(
|
|
|
|
'label' => _m('Bio'),
|
|
|
|
'type' => 'textarea',
|
|
|
|
'profile' => 'bio',
|
|
|
|
),
|
|
|
|
'tags' => array(
|
|
|
|
'label' => _m('Tags'),
|
|
|
|
'type' => 'tags',
|
|
|
|
'profile' => 'tags',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'contact' => array(
|
|
|
|
'label' => _m('Contact'),
|
|
|
|
'fields' => array(
|
2011-03-10 22:14:21 +00:00
|
|
|
'phone' => $this->getPhones(),
|
2011-02-03 00:23:24 +00:00
|
|
|
'im' => array(
|
|
|
|
'label' => _m('IM'),
|
|
|
|
'type' => 'im',
|
|
|
|
'multi' => true,
|
|
|
|
),
|
|
|
|
'website' => array(
|
|
|
|
'label' => _m('Websites'),
|
|
|
|
'type' => 'website',
|
|
|
|
'multi' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'personal' => array(
|
|
|
|
'label' => _m('Personal'),
|
|
|
|
'fields' => array(
|
|
|
|
'birthday' => array(
|
|
|
|
'label' => _m('Birthday'),
|
|
|
|
'type' => 'date',
|
|
|
|
'vcard' => 'bday',
|
|
|
|
),
|
|
|
|
'spouse' => array(
|
|
|
|
'label' => _m('Spouse\'s name'),
|
|
|
|
'vcard' => 'x-spouse',
|
|
|
|
),
|
|
|
|
'kids' => array(
|
|
|
|
'label' => _m('Kids\' names')
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'experience' => array(
|
|
|
|
'label' => _m('Work experience'),
|
|
|
|
'fields' => array(
|
|
|
|
'experience' => array(
|
|
|
|
'type' => 'experience',
|
|
|
|
'label' => _m('Employer'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'education' => array(
|
|
|
|
'label' => _m('Education'),
|
|
|
|
'fields' => array(
|
|
|
|
'education' => array(
|
|
|
|
'type' => 'education',
|
|
|
|
'label' => _m('Institution'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|