Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* Elgg flex profile model
* Functions to save and display profile data
*
* @package Elgg
* @subpackage Form
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Kevin Jardine <kevin@radagast.biz>
* @copyright Radagast Solutions 2008
* @link http://radagast.biz/
*/
// Load form model
require_once(dirname(dirname(dirname(__FILE__))) . "/form/models/model.php");
// Load form profile model
require_once(dirname(dirname(dirname(__FILE__))) . "/form/models/profile.php");
// Eventually this will be very flexible and return different forms for
// different entities.
// Right now it just returns the first public profile form available.
function flexprofile_get_profile_form($user=null) {
return form_get_latest_public_profile_form(1);
}
// use the specified profile form to return the data (indexed by summary area) from the specified user
function flexprofile_get_data_for_summary_display($form, $user) {
$form_id = $form->getGUID();
$data = form_get_data_from_profile($form_id,$user);
$area_data = array();
$maps = form_get_maps($form_id);
if ($maps) {
foreach($maps as $map) {
$field = get_entity($map->field_id);
//print($field->internal_name.','.$field->field_type.','.$field->choice_type.','.$field->default_value.'<br />');
$internalname = $field->internal_name;
if (isset($data[$internalname]) && $data[$internalname]->value) {
$area = $field->area;
if ($area) {
if (!isset($area_data[$area])) {
$area_data[$area] = array();
}
$item = new StdClass();
$item->internalname = $internalname;
$item->title = form_field_t($form,$field,'title');
$item->description = form_field_t($form,$field,'description');
if ($field->field_type == 'choices') {
$item->fieldtype = $field->choice_type;
$choices = form_get_field_choices($field->getGUID());
$this_choice = '';
foreach($choices as $choice) {
if ($choice->value == $data[$internalname]->value) {
$this_choice = $choice;
break;
}
}
$item->value = form_choice_t($form,$field,$this_choice);
} else {
$item->fieldtype = $field->field_type;
$item->value = $data[$internalname]->value;
}
$area_data[$area][] = $item;
}
}
}
}
return $area_data;
}
// Return the form fields (indexed by tab), optionally prepopulated with data from the specified user.
function flexprofile_get_data_for_edit_form($form, $user=null) {
if ($user) {
$data = form_get_data_from_profile($form->getGUID(),$user);
} else {
$data = array();
}
$tab_data = array();
$tabs = form_display_by_tab($form,$data);
// add access control pulldowns
if ($tabs) {
foreach ($tabs as $tab => $tab_items) {
$tab_data[$tab] = '';
foreach ($tab_items as $item) {
$internalname = $item->internalname;
$access_id = $item->default_access;
$access_bit = '<p class="form-field-access">';
$access_bit .= elgg_view('input/access', array('internalname' => 'flexprofile_access['.$internalname.']','value'=>$access_id));
$access_bit .= '</p>';
$tab_data[$tab] .= $item->html.$access_bit;
}
}
}
return $tab_data;
}
function flexprofile_set_data($entity,$data) {
global $CONFIG;
$entity_guid = $entity->getGUID();
foreach($data as $name => $item) {
remove_metadata($entity_guid, $name);
$value = $item->value;
if (is_array($value)) {
// currently tags are the only field_type returning multiple values
$i = 0;
foreach($value as $interval) {
$i++;
if ($i == 1) { $multiple = false; } else { $multiple = true; }
create_metadata($entity_guid, $name, $interval, 'text', $entity_guid, $item->access_id, $multiple);
}
} else {
create_metadata($entity_guid, $name, $value, '', $entity_guid, $item->access_id);
}
}
}
?>