space_taxonomy.inc in Spaces 6.3
File
spaces_taxonomy/plugins/space_taxonomy.inc
View source
<?php
class space_taxonomy extends space_type_purl {
var $term = NULL;
function title() {
return $this->term->name;
}
function load() {
if ($this->id === 0) {
return TRUE;
}
else {
if ($this->term = taxonomy_get_term($this->id)) {
return TRUE;
}
}
return FALSE;
}
function router($op, $object = NULL) {
switch ($op) {
case 'init':
if (implode('/', array(
arg(0),
arg(1),
)) === 'taxonomy/term' && arg(2)) {
$terms = taxonomy_terms_parse_string(arg(2));
if (!empty($terms['tids'])) {
foreach ($terms['tids'] as $tid) {
if ($term = taxonomy_get_term($tid)) {
$this
->router_term($term);
}
}
}
}
break;
case 'node':
$node = $object;
if (!empty($node->taxonomy)) {
foreach ($node->taxonomy as $term) {
if ($term->vid == variable_get('spaces_taxonomy_vid', 0)) {
$this
->router_term($term);
}
}
}
break;
}
return;
}
protected function router_term($term) {
if ($term->vid == variable_get('spaces_taxonomy_vid', 0)) {
$space = spaces_load('taxonomy', $term->tid);
if ($space && (!$this->active || $this->id != $space->id)) {
$space
->activate();
}
}
}
function views_filter(&$query, $base_table = '', $relationship = '') {
switch ($base_table) {
case 'node':
$table = $query
->ensure_table('term_node', $relationship);
$query
->add_where(0, "{$table}.tid = %d", $this->id);
break;
}
}
}