--- nodefamily.module.bak 2007-01-12 17:36:59.000000000 +0000 +++ nodefamily.module 2007-01-12 17:42:16.000000000 +0000 @@ -375,12 +375,12 @@ /* * Returns an array of all parent content types for the given child content type */ -function nodefamily_get_parent_types(&$type) { +function nodefamily_get_parent_types($type = NULL) { $relations = variable_get('nodefamily_relations',array()); $parents = array(); foreach($relations as $parent => $children) { - if (in_array($type, array_keys($children))) { + if($type == NULL || in_array($type, array_keys($children))) { $parents[] = $parent; } } @@ -390,10 +390,10 @@ /* * Returns an array of all child content types for the given parent content type */ -function nodefamily_get_child_types(&$type) { +function nodefamily_get_child_types($type = NULL) { $relations = variable_get('nodefamily_relations',array()); - if (array_key_exists($type, $relations)) { + if ($type == NULL || array_key_exists($type, $relations)) { return array_keys($relations[$type]); } else { @@ -743,6 +743,42 @@ /** + * @ingroup hook_block implementation + * implementation of hook_block + * @todo make sure we only load lonely nodes + */ +function nodefamily_block($op = 'list', $delta = 0, $edit = array()){ + // The $op parameter determines what piece of information is being requested. + switch ($op) { + case 'list': + foreach (nodefamily_get_parent_types() as $type) { + $blocks[$type]['info'] = t('My nodefamily for %type', array('%type' => node_get_name($type))); + } + return $blocks; + case 'view': default: + $block['subject'] = t('My %type', array('%type' => node_get_name($delta))); + $block['content'] = nodefamily_block_contents($delta); + return $block; + } +} + +/** + * @ingroup hook_block implementation + * Generate the content for the block + * @todo unhardcode the [] bracketses + */ +function nodefamily_block_contents($type) { + global $user; + $node = node_load(array('type' => $type, 'uid' => $user->uid)); + if ($children = nodefamily_relation_load($node)) { + foreach ($children as $profile) { + $items[] = l($profile->title, 'node/'. $profile->nid) .' ['. l(t('edit'), 'node/'. $profile->nid .'/edit') .']'; + } + return theme('item_list', $items); + } +} + +/** * Views integration */ @@ -994,4 +1030,4 @@ $tablename = $query->get_table_name($table, $num); $query->add_where("%s.type = '%s'", $tablename, $filter['options']); } -} \ No newline at end of file +}