2011-02-03 09:23:24 +09: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 12:20:43 +09:00
|
|
|
/**
|
|
|
|
* Class to represent extended profile data
|
|
|
|
*/
|
2011-02-03 09:23:24 +09:00
|
|
|
class ExtendedProfile
|
|
|
|
{
|
2011-03-10 12:27:21 +09:00
|
|
|
protected $fields;
|
|
|
|
|
2011-03-09 12:20:43 +09:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
|
|
|
*/
|
2011-02-03 10:29:34 +09:00
|
|
|
function __construct(Profile $profile)
|
|
|
|
{
|
2011-03-09 12:20:43 +09:00
|
|
|
$this->profile = $profile;
|
|
|
|
$this->user = $profile->getUser();
|
|
|
|
$this->fields = $this->loadFields();
|
2011-03-11 09:57:41 +09:00
|
|
|
$this->sections = $this->getSections();
|
|
|
|
//common_debug(var_export($this->sections, true));
|
|
|
|
|
2011-03-11 07:14:21 +09:00
|
|
|
//common_debug(var_export($this->fields, true));
|
2011-02-03 10:29:34 +09:00
|
|
|
}
|
|
|
|
|
2011-03-09 12:20:43 +09:00
|
|
|
/**
|
|
|
|
* Load extended profile fields
|
|
|
|
*
|
|
|
|
* @return array $fields the list of fields
|
|
|
|
*/
|
2011-02-03 10:29:34 +09:00
|
|
|
function loadFields()
|
|
|
|
{
|
|
|
|
$detail = new Profile_detail();
|
|
|
|
$detail->profile_id = $this->profile->id;
|
|
|
|
$detail->find();
|
2011-03-08 14:34:57 +09:00
|
|
|
|
|
|
|
$fields = array();
|
|
|
|
|
|
|
|
while ($detail->fetch()) {
|
2011-03-10 11:00:24 +09:00
|
|
|
$fields[$detail->field_name][] = clone($detail);
|
2011-02-03 10:29:34 +09:00
|
|
|
}
|
2011-03-09 12:20:43 +09:00
|
|
|
|
2011-02-03 10:29:34 +09:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2011-03-09 12:20:43 +09: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 12:27:21 +09:00
|
|
|
$key = strtolower($name);
|
2011-03-09 12:20:43 +09:00
|
|
|
$profileFields = array('fullname', 'location', 'bio');
|
|
|
|
|
2011-03-10 12:27:21 +09:00
|
|
|
if (in_array($key, $profileFields)) {
|
2011-03-09 12:20:43 +09:00
|
|
|
return $this->profile->$name;
|
2011-03-10 12:27:21 +09:00
|
|
|
} else if (array_key_exists($key, $this->fields)) {
|
|
|
|
return $this->fields[$key][0]->field_value;
|
2011-03-09 12:20:43 +09:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 17:09:38 +09:00
|
|
|
function getDateValue($name) {
|
|
|
|
$key = strtolower($name);
|
|
|
|
if (array_key_exists($key, $this->fields)) {
|
|
|
|
return $this->fields[$key][0]->date;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 02:10:18 +09:00
|
|
|
// XXX: getPhones, getIms, and getWebsites pretty much do the same thing,
|
|
|
|
// so refactor.
|
2011-03-11 07:14:21 +09:00
|
|
|
function getPhones()
|
|
|
|
{
|
2011-03-14 17:49:46 +09:00
|
|
|
$phones = (isset($this->fields['phone'])) ? $this->fields['phone'] : null;
|
2011-03-11 09:57:41 +09:00
|
|
|
$pArrays = array();
|
|
|
|
|
|
|
|
if (empty($phones)) {
|
|
|
|
$pArrays[] = array(
|
2011-03-11 07:14:21 +09:00
|
|
|
'label' => _m('Phone'),
|
2011-03-14 08:32:13 +09:00
|
|
|
'index' => 0,
|
2011-03-11 07:14:21 +09:00
|
|
|
'type' => 'phone',
|
2011-03-11 09:57:41 +09:00
|
|
|
'vcard' => 'tel',
|
2011-03-14 17:49:46 +09:00
|
|
|
'rel' => 'office',
|
|
|
|
'value' => null
|
2011-03-11 09:57:41 +09:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
for ($i = 0; $i < sizeof($phones); $i++) {
|
|
|
|
$pa = array(
|
|
|
|
'label' => _m('Phone'),
|
|
|
|
'type' => 'phone',
|
2011-03-14 17:49:46 +09:00
|
|
|
'index' => intval($phones[$i]->value_index),
|
2011-03-11 09:57:41 +09:00
|
|
|
'rel' => $phones[$i]->rel,
|
|
|
|
'value' => $phones[$i]->field_value,
|
|
|
|
'vcard' => 'tel'
|
|
|
|
);
|
2011-03-14 17:49:46 +09:00
|
|
|
|
2011-03-11 09:57:41 +09:00
|
|
|
$pArrays[] = $pa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $pArrays;
|
2011-03-11 07:14:21 +09:00
|
|
|
}
|
|
|
|
|
2011-03-15 14:38:34 +09:00
|
|
|
function getIms()
|
|
|
|
{
|
|
|
|
$ims = (isset($this->fields['im'])) ? $this->fields['im'] : null;
|
|
|
|
$iArrays = array();
|
|
|
|
|
|
|
|
if (empty($ims)) {
|
|
|
|
$iArrays[] = array(
|
|
|
|
'label' => _m('IM'),
|
|
|
|
'type' => 'im'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
for ($i = 0; $i < sizeof($ims); $i++) {
|
|
|
|
$ia = array(
|
|
|
|
'label' => _m('IM'),
|
|
|
|
'type' => 'im',
|
|
|
|
'index' => intval($ims[$i]->value_index),
|
|
|
|
'rel' => $ims[$i]->rel,
|
|
|
|
'value' => $ims[$i]->field_value,
|
|
|
|
);
|
|
|
|
|
|
|
|
$iArrays[] = $ia;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $iArrays;
|
|
|
|
}
|
|
|
|
|
2011-03-16 02:10:18 +09:00
|
|
|
function getWebsites()
|
|
|
|
{
|
|
|
|
$sites = (isset($this->fields['website'])) ? $this->fields['website'] : null;
|
|
|
|
$wArrays = array();
|
|
|
|
|
|
|
|
if (empty($sites)) {
|
|
|
|
$wArrays[] = array(
|
|
|
|
'label' => _m('Website'),
|
|
|
|
'type' => 'website'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
for ($i = 0; $i < sizeof($sites); $i++) {
|
|
|
|
$wa = array(
|
|
|
|
'label' => _m('Website'),
|
|
|
|
'type' => 'website',
|
|
|
|
'index' => intval($sites[$i]->value_index),
|
|
|
|
'rel' => $sites[$i]->rel,
|
|
|
|
'value' => $sites[$i]->field_value,
|
|
|
|
);
|
|
|
|
|
|
|
|
$wArrays[] = $wa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $wArrays;
|
|
|
|
}
|
|
|
|
|
2011-03-15 07:29:11 +09:00
|
|
|
function getExperiences()
|
|
|
|
{
|
2011-03-15 09:27:50 +09:00
|
|
|
$companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
|
2011-03-15 07:29:11 +09:00
|
|
|
$start = (isset($this->fields['start'])) ? $this->fields['start'] : null;
|
|
|
|
$end = (isset($this->fields['end'])) ? $this->fields['end'] : null;
|
|
|
|
|
2011-03-15 09:27:50 +09:00
|
|
|
$eArrays = array();
|
2011-03-15 07:29:11 +09:00
|
|
|
|
2011-03-15 09:27:50 +09:00
|
|
|
if (empty($companies)) {
|
2011-03-15 07:29:11 +09:00
|
|
|
$eArrays[] = array(
|
|
|
|
'label' => _m('Employer'),
|
|
|
|
'type' => 'experience',
|
2011-03-15 09:27:50 +09:00
|
|
|
'company' => null,
|
|
|
|
'start' => null,
|
|
|
|
'end' => null,
|
|
|
|
'current' => false,
|
2011-03-15 07:29:11 +09:00
|
|
|
'index' => 0
|
|
|
|
);
|
2011-03-15 09:27:50 +09:00
|
|
|
} else {
|
|
|
|
for ($i = 0; $i < sizeof($companies); $i++) {
|
|
|
|
$ea = array(
|
|
|
|
'label' => _m('Employer'),
|
|
|
|
'type' => 'experience',
|
|
|
|
'company' => $companies[$i]->field_value,
|
|
|
|
'index' => intval($companies[$i]->value_index),
|
|
|
|
'current' => $end[$i]->rel,
|
|
|
|
'start' => $start[$i]->date,
|
|
|
|
'end' => $end[$i]->date
|
|
|
|
);
|
|
|
|
$eArrays[] = $ea;
|
|
|
|
}
|
2011-03-15 07:29:11 +09:00
|
|
|
}
|
|
|
|
return $eArrays;
|
|
|
|
}
|
|
|
|
|
2011-03-15 12:58:35 +09:00
|
|
|
function getEducation()
|
|
|
|
{
|
|
|
|
$schools = (isset($this->fields['school'])) ? $this->fields['school'] : null;
|
|
|
|
$degrees = (isset($this->fields['degree'])) ? $this->fields['degree'] : null;
|
2011-03-15 14:02:24 +09:00
|
|
|
$descs = (isset($this->fields['degree_descr'])) ? $this->fields['degree_descr'] : null;
|
2011-03-15 12:58:35 +09:00
|
|
|
$start = (isset($this->fields['school_start'])) ? $this->fields['school_start'] : null;
|
|
|
|
$end = (isset($this->fields['school_end'])) ? $this->fields['school_end'] : null;
|
|
|
|
$iArrays = array();
|
|
|
|
|
|
|
|
if (empty($schools)) {
|
|
|
|
$iArrays[] = array(
|
|
|
|
'type' => 'education',
|
|
|
|
'label' => _m('Institution'),
|
|
|
|
'school' => null,
|
|
|
|
'degree' => null,
|
|
|
|
'description' => null,
|
|
|
|
'start' => null,
|
|
|
|
'end' => null,
|
|
|
|
'index' => 0
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
for ($i = 0; $i < sizeof($schools); $i++) {
|
|
|
|
$ia = array(
|
|
|
|
'type' => 'education',
|
|
|
|
'label' => _m('Institution'),
|
|
|
|
'school' => $schools[$i]->field_value,
|
2011-03-15 14:02:24 +09:00
|
|
|
'degree' => isset($degrees[$i]->field_value) ? $degrees[$i]->field_value : null,
|
|
|
|
'description' => isset($descs[$i]->field_value) ? $descs[$i]->field_value : null,
|
2011-03-15 12:58:35 +09:00
|
|
|
'index' => intval($schools[$i]->value_index),
|
|
|
|
'start' => $start[$i]->date,
|
|
|
|
'end' => $end[$i]->date
|
|
|
|
);
|
|
|
|
$iArrays[] = $ia;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $iArrays;
|
|
|
|
}
|
|
|
|
|
2011-03-09 12:20:43 +09:00
|
|
|
/**
|
|
|
|
* Return all the sections of the extended profile
|
|
|
|
*
|
|
|
|
* @return array the big list of sections and fields
|
|
|
|
*/
|
2011-02-03 09:23:24 +09: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-16 02:10:18 +09:00
|
|
|
'phone' => $this->getPhones(),
|
|
|
|
'im' => $this->getIms(),
|
|
|
|
'website' => $this->getWebsites()
|
2011-02-03 09:23:24 +09:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'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(
|
2011-03-15 12:58:35 +09:00
|
|
|
'experience' => $this->getExperiences()
|
2011-02-03 09:23:24 +09:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'education' => array(
|
|
|
|
'label' => _m('Education'),
|
|
|
|
'fields' => array(
|
2011-03-15 12:58:35 +09:00
|
|
|
'education' => $this->getEducation()
|
2011-02-03 09:23:24 +09:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|