profile_fields.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008 function panels_profile_fields_panels_content_types() {
00009 $items = array();
00010 if (module_exists('profile') && !is_null(profile_categories())) {
00011 $items['profile_fields'] = array(
00012 'title' => t('Profile Fields'),
00013 'content_types' => 'panels_profile_fields_content_type',
00014
00015 'single' => TRUE,
00016 'render callback' => 'panels_profile_fields_content',
00017 'add callback' => 'panels_profile_fields_configure',
00018 'edit callback' => 'panels_profile_fields_configure',
00019 'title callback' => 'panels_profile_fields_configure_title',
00020 );
00021 }
00022 return $items;
00023 }
00024
00025
00026
00027
00028 function panels_profile_fields_content($conf, $panel_args, $context) {
00029 $account = isset($context->data) ? drupal_clone($context->data) : NULL;
00030 $block = new stdClass();
00031 $block->module = 'profile fields';
00032
00033 if ($account) {
00034
00035 $category = str_replace("_", " ", $conf['category']);
00036
00037
00038 $block->subject = $category;
00039
00040
00041 $profile = profile_view_profile($account);
00042 if (is_array($profile[$category])) {
00043 foreach ($profile[$category] as $field) {
00044 $vars[$field['class']]['title'] = $field['title'];
00045 $vars[$field['class']]['value'] = $field['value'];
00046 }
00047 }
00048
00049 if (sizeof($vars) == 0) {
00050
00051 $output = $conf['empty'];
00052 }
00053 else {
00054
00055 $output = theme('profile_fields_pane', $category, $vars);
00056 }
00057
00058 $block->content = $output;
00059 $block->delta = $account->uid;
00060 }
00061 else {
00062 $block->subject = $conf['category'];
00063 $block->content = t('Profile content goes here.');
00064 $block->delta = 'unknown';
00065 }
00066
00067 return $block;
00068 }
00069
00070
00071
00072
00073 function theme_profile_fields_pane($category, $vars) {
00074 if (is_array($vars)) {
00075 foreach ($vars as $class => $field) {
00076 $output .= '<dl class="profile-category">';
00077 $output .= '<dt class="profile-' . $class . '">' . $field['title'] . '</dt>';
00078 $output .= '<dd class="profile-' . $class . '">' . $field['value'] . '</dd>';
00079 $output .= '</dl>';
00080 }
00081 }
00082
00083 return $output;
00084 }
00085
00086
00087
00088
00089 function panels_profile_fields_content_type() {
00090 return array(
00091 'description' => array(
00092 'title' => t('Profile Category'),
00093 'icon' => 'icon_user.png',
00094 'path' => panels_get_path('content_types/user'),
00095 'description' => t('Profile category contents.'),
00096 'required context' => new panels_required_context(t('User'), 'user'),
00097 'category' => array(t('User context'), -9),
00098 ),
00099 );
00100 }
00101
00102
00103
00104
00105 function _panels_profile_fields_options() {
00106 $cat_list = array();
00107
00108 $categories = profile_categories();
00109 foreach ($categories as $key => $value) {
00110 $cat_list[str_replace(" ", "_", $value['name'])] = $value['title'];
00111 }
00112
00113 return $cat_list;
00114 }
00115
00116
00117
00118
00119 function panels_profile_fields_configure($id, $parents, $conf = array()) {
00120
00121 if (empty($conf)) {
00122 $conf = array('title' => '', 'category' => '', 'empty' => '');
00123 }
00124
00125 $form['category'] = array(
00126 '#type' => 'radios',
00127 '#title' => t('Which category'),
00128 '#options' => _panels_profile_fields_options(),
00129 '#default_value' => $conf['category'],
00130 '#prefix' => '<div class="clear-block no-float">',
00131 '#suffix' => '</div>',
00132 );
00133
00134 $form['empty'] = array(
00135 '#type' => 'textarea',
00136 '#title' => 'Empty text',
00137 '#description' => t('Text to display if category has no data. Note that title will not display unless overridden.'),
00138 '#rows' => 5,
00139 '#default_value' => $conf['empty'],
00140 '#prefix' => '<div class="clear-block no-float">',
00141 '#suffix' => '</div>',
00142 );
00143
00144 return $form;
00145 }
00146
00147
00148
00149
00150 function panels_profile_fields_configure_title($conf, $context) {
00151 return t('"@s" profile fields', array('@s' => $conf['category']));
00152 }
00153