Commit 1af3f7a1 authored by bojanz's avatar bojanz Committed by tim.plunkett
Browse files

Issue #1605102 by bojanz: Remove profile integration.

parent 9d772270
<?php
/**
* @file
* Provide views data and handlers for user.module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function profile_views_data() {
$data['profile_values']['moved to'] = 'profile_value';
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['profile_value']['table']['group'] = t('Profile');
$data['profile_value']['table']['join'] = array(
'node' => array(
'left_table' => 'profile_value',
'left_field' => 'uid',
'field' => 'uid',
),
'users' => array(
'left_table' => 'profile_value',
'left_field' => 'uid',
'field' => 'uid',
),
);
$fields = profile_views_get_fields();
foreach ($fields as $field) {
$table_name = 'profile_value_' . str_replace('-', '_', $field->name);
$data[$table_name] = array(
'table' => array(
'group' => t('Profile'),
'join' => array(
'node' => array(
'table' => 'profile_value',
'left_table' => 'users',
'left_field' => 'uid',
'field' => 'uid',
'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
),
'users' => array(
'table' => 'profile_value',
'left_field' => 'uid',
'field' => 'uid',
'extra' => array(array('field' => 'fid', 'value' => $field->fid)),
),
),
),
);
// All fields in the table are named 'value'.
$data[$table_name]['value'] = profile_views_fetch_field($field);
}
return $data;
}
/**
* Get all profile fields
*/
function profile_views_get_fields() {
static $fields = NULL;
if (!isset($fields)) {
$fields = array();
$results = db_query("SELECT * FROM {profile_field} ORDER BY category, weight");
foreach ($results as $row) {
if (!empty($row->options)) {
if (!in_array(substr($row->options, 0, 2), array('a:', 'b:', 'i:', 'f:', 'o:', 's:', ))) {
// unserialized fields default version
$options = $row->options;
unset($row->options);
$row->options = $options;
}
else {
// serialized fields or modified version
$row->options = unserialize($row->options);
}
}
$fields[$row->fid] = $row;
}
}
return $fields;
}
/**
* Add profile fields to view table
*/
function profile_views_fetch_field($field) {
$data = array(
'title' => t('@category: @field-name', array('@category' => $field->category, '@field-name' => $field->title)),
);
// Add fields specific to the profile type.
switch ($field->type) {
case 'textfield':
$data += array(
'help' => t('Profile textfield'),
'field' => array(
'handler' => 'views_handler_field_user',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
break;
case 'textarea':
$data += array(
'help' => t('Profile textarea'),
'field' => array(
'handler' => 'views_handler_field_markup',
'format' => filter_default_format(),
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
break;
case 'checkbox':
$data += array(
'help' => t('Profile checkbox'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'accept null' => TRUE,
),
// @todo there ought to be a boolean argument handler
);
break;
case 'url':
$data += array(
'help' => t('Profile URL'),
'field' => array(
'handler' => 'views_handler_field_url',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
break;
case 'selection':
$data += array(
'help' => t('Profile selection'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_profile_selection',
'fid' => $field->fid,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
);
break;
case 'list':
$data += array(
'help' => t('Profile freeform list %field-name.', array('%field-name' => $field->title)),
'field' => array(
'handler' => 'views_handler_field_profile_list',
'no group by' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
break;
case 'date':
$data += array(
'help' => t('Profile date %field-name.', array('%field-name' => $field->title)),
'field' => array(
'handler' => 'views_handler_field_profile_date',
),
);
break;
}
// @todo: add access control to hidden fields.
return $data;
}
<?php
/**
* @file
* Definition of views_handler_field_profile_date.
*/
/**
* Field handler display a profile date
*
* The dates are stored serialized, which makes them mostly useless from
* SQL. About all we can do is unserialize and display them.
*
* @ingroup views_field_handlers
*/
class views_handler_field_profile_date extends views_handler_field_date {
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// we can't do "time ago" so remove it from the form.
unset($form['date_format']['#options']['time ago']);
}
/**
* Display a profile field of type 'date'
*/
function render($values) {
$value = $this->get_value($values);
if (!$value) {
return;
}
$value = unserialize($value);
$format = $this->options['date_format'];
switch ($format) {
case 'custom':
$format = $this->options['custom_date_format'];
break;
case 'small':
$format = variable_get('date_format_short', 'm/d/Y - H:i');
break;
case 'medium':
$format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
break;
case 'large':
$format = variable_get('date_format_long', 'l, F j, Y - H:i');
break;
}
// Note: Avoid PHP's date() because it does not handle dates before
// 1970 on Windows. This would make the date field useless for e.g.
// birthdays.
// But we *can* deal with non-year stuff:
$date = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
$replace = array(
// day
'd' => sprintf('%02d', $value['day']),
'D' => NULL,
'l' => NULL,
'N' => NULL,
'S' => date('S', $date),
'w' => NULL,
'j' => $value['day'],
// month
'F' => date('F', $date),
'm' => sprintf('%02d', $value['month']),
'M' => date('M', $date),
'n' => date('n', $date),
'Y' => $value['year'],
'y' => substr($value['year'], 2, 2),
// kill time stuff
'a' => NULL,
'A' => NULL,
'g' => NULL,
'G' => NULL,
'h' => NULL,
'H' => NULL,
'i' => NULL,
's' => NULL,
':' => NULL,
'T' => NULL,
' - ' => NULL,
':' => NULL,
);
return strtr($format, $replace);
}
}
<?php
/**
* @file
* Definition of views_handler_field_profile_list.
*/
/**
* Field handler display a profile list item.
*
* @ingroup views_field_handlers
*/
class views_handler_field_profile_list extends views_handler_field_prerender_list {
/**
* Break up our field into a proper list.
*/
function pre_render(&$values) {
$this->items = array();
foreach ($values as $value) {
$field = $this->get_value($value);
$this->items[$field] = array();
foreach (preg_split("/[,\n\r]/", $field) as $item) {
if ($item != '' && $item !== NULL) {
$this->items[$field][] = array('item' => $item);
}
}
}
}
function render_item($count, $item) {
return $item['item'];
}
function document_self_tokens(&$tokens) {
$tokens['[' . $this->options['id'] . '-item' . ']'] = t('The text of the profile item.');
}
function add_self_tokens(&$tokens, $item) {
$tokens['[' . $this->options['id'] . '-item' . ']'] = $item['item'];
}
}
<?php
/**
* @file
* Definition of views_handler_filter_profile_selection.
*/
/**
* Filter by a selection widget in the profile.
*
* @ingroup views_filter_handlers
*/
class views_handler_filter_profile_selection extends views_handler_filter_in_operator {
function get_value_options() {
if (isset($this->value_options)) {
return;
}
$this->value_options = array();
$all_options = profile_views_get_fields();
$field = $all_options[$this->definition['fid']];
$lines = preg_split("/[,\n\r]/", $field->options);
foreach ($lines as $line) {
if ($line = trim($line)) {
$this->value_options[$line] = $line;
}
}
}
}
......@@ -135,9 +135,6 @@ files[] = modules/node/views_plugin_argument_default_node.inc
files[] = modules/node/views_plugin_argument_validate_node.inc
files[] = modules/node/views_plugin_row_node_rss.inc
files[] = modules/node/views_plugin_row_node_view.inc
files[] = modules/profile/views_handler_field_profile_date.inc
files[] = modules/profile/views_handler_field_profile_list.inc
files[] = modules/profile/views_handler_filter_profile_selection.inc
files[] = modules/search/views_handler_argument_search.inc
files[] = modules/search/views_handler_field_search_score.inc
files[] = modules/search/views_handler_filter_search.inc
......
......@@ -2409,10 +2409,6 @@ function node_views_api() { return views_views_api(); }
function poll_views_api() { return views_views_api(); }
}
if (!function_exists('profile_views_api')) {
function profile_views_api() { return views_views_api(); }
}
if (!function_exists('search_views_api')) {
function search_views_api() { return views_views_api(); }
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment