content_profile_views_handler_relationship.inc in Content Profile 6
File
views/content_profile_views_handler_relationship.inc
View source
<?php
class content_profile_views_handler_relationship extends views_handler_relationship {
function option_definition() {
$options = parent::option_definition();
$options['type'] = array(
'default' => '',
);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['type'] = array(
'#type' => 'radios',
'#title' => t('Content type'),
'#default_value' => $this->options['type'],
'#options' => content_profile_get_types('names'),
'#required' => TRUE,
);
}
function query() {
$join = new views_join();
$join->definition = array(
'table' => 'node',
'field' => 'uid',
'left_table' => !empty($this->relationship) ? $this->relationship : 'users',
'left_field' => 'uid',
'extra' => array(
array(
'field' => 'type',
'value' => $this->options['type'],
),
),
);
if (!empty($this->options['required'])) {
$join->definition['type'] = 'INNER';
}
$join
->construct();
$this
->ensure_my_table();
$alias = $join->definition['table'] . '_' . $join->definition['left_table'];
$this->alias = $this->query
->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
}
}