array('name' => t('staffbio'), 'base' => 'staffbio'));
}
/**
* Implementation of hook_help().
*/
function staffbio_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Enables the creation of bios and includes a block for listing and a helper function for use in themes or PHP nodes to display a tiled view of bios complete with vcards.');
case 'node/add#staffbio':
return t('If you have defined a role in the staffbio settings for bios to pull users from, you can associate biographical sketches with Drupal users who have been assigned that role.');
}
}
/**
* Implementation of hook_perm().
*/
function staffbio_perm() {
return array('manage staffbios');
}
/**
* Implementation of hook_access().
*/
function staffbio_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('manage staffbios');
}
if ($op == 'update' || $op == 'delete') {
if (user_access('manage staffbios') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}
/**
* Implementation of hook_view().
*/
function staffbio_view(&$node, $teaser = false, $page = false, $links = true){
$node = node_prepare($node);
$meta = db_fetch_object(db_query('SELECT u.name, u.picture FROM {node} n, {users} u, {staffbio} b WHERE n.nid=%d AND n.nid = b.nid AND b.uid = u.uid', $node->nid));
$node->staffbio_name = $meta->name;
$node->staffbio_picture = $meta->picture;
}
/**
* Implementation of hook_load().
*/
function staffbio_load(&$node){
$data = db_fetch_object(db_query("SELECT u.name, u.picture FROM {users} u, {staffbio} b WHERE b.nid = %d AND b.uid = u.uid", $node->nid));
return $data;
}
/**
* Implementation of hook_block().
*/
function staffbio_block($op = 'list', $delta = 0, $edit = array()){
switch($op){
case 'list':
$blocks[0]['info'] = t('Employee List');
return $blocks;
break;
case 'view':
switch($delta){
case 0:
$block['subject'] = t('Employee List');
$result = db_query('SELECT n.nid, u.name FROM {node} n, {staffbio} b, {users} u WHERE n.type = "staffbio" AND n.status = 1 AND n.nid = b.nid AND u.uid = b.uid ORDER BY u.name');
$block['content'] = '
' . "\n";
while($node = db_fetch_object($result)){
if($node->nid == arg(1)){
$block['content'] .= '- ' . $node->name . '
' . "\n";
}
else{
$block['content'] .= '- ' . $node->name . '
' . "\n";
}
}
$block['content'] .= '
' . "\n";
break;
}
return $block;
break;
case 'configure':
break;
case 'save':
break;
}
}
/**
* Get a list of staffbio nodes and return as an array.
*/
function staffbio_list(){
$bios = array();
$result = db_query('SELECT n.nid FROM {node} n, {staffbio} b, {users} u WHERE n.type = "staffbio" AND n.status = 1 AND n.nid = b.nid AND u.uid = b.uid ORDER BY u.name');
while($node = db_fetch_object($result)){
$node = node_load(array('nid' => $node->nid));
array_push($bios,$node);
}
return $bios;
}
/**
* Helper function that displays bios in an unordered list that can be styled to appear as a tiled list of avavatars. Includes vcard microformat.
*/
function theme_staffbio_tiles(){
global $base_url;
$bios = staffbio_list();
$output = '' . "\n";
$output .= '' . "\n";
foreach($bios as $node){
//$node = node_load(array('nid' => $node->nid));
$node = node_prepare($node);
$output .= '- ' . "\n";
$output .= '

'. "\n";
$output .= '' . $node->title . '' . "\n";
$output .= '' . $node->name . '' . "\n";
$output .= ' ' . "\n";
}
$output .= '
' . "\n";
return $output;
}
/**
* Implementation of hook_menu().
*/
function staffbio_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/staffbio', 'title' => t('staffbio'),
'access' => staffbio_access('create', NULL));
}
//Add staffbio stylesheet to header.
//$xpi_module_path = drupal_get_path('module', 'staffbio');
//$head = theme_stylesheet_import($xpi_module_path . '/staffbio.css') . "\n";
$head = theme_stylesheet_import('modules/staffbio/staffbio.css') . "\n";
drupal_set_html_head($head);
if(arg(0) == 'about' && is_numeric(arg(1))){
$node = node_load(array('nid' => arg(1)));
if($node->nid && $node->type == 'staffbio'){
$items[] = array('path' => 'about/' . arg(1), 'title' => t('staffbio'),
'callback' => 'node_page', 'access' => user_access('access content', NULL));
}
}
return $items;
}
function staffbio_update(&$node){
db_query('UPDATE {staffbio} SET uid = %d WHERE nid=%d', $node->staffbio_uid, $node->nid);
}
function staffbio_insert(&$node){
db_query('INSERT INTO {staffbio} (nid, uid) VALUES(%d, %d)', $node->nid, $node->staffbio_uid);
}
function staffbio_delete(&$node){
db_query('DELETE FROM {staffbio} WHERE nid=%d', $node->nid);
}
function staffbio_settings(){
$roles = array();
$result = db_query('SELECT rid, name FROM {role}');
while($role = db_fetch_object($result)){
$roles[$role->rid] = $role->name;
}
$form['staffbio_role'] = array(
'#type' => 'select',
'#title' => t('Role to select employees from'),
'#default_value' => variable_get('staffbio_role', 2),
'#options' => $roles,
'#description' => t('Select the role from which users for biographies should be selected.'),
);
return $form;
}
/**
* Implementation of hook_form().
*/
function staffbio_form(&$node) {
$uids = array();
$result = db_query('SELECT u.uid, u.name FROM {users} u, {role} r, {users_roles} ur WHERE u.uid = ur.uid AND ur.rid = r.rid AND r.rid = %d ORDER BY u.name', variable_get('staffbio_role',2));
while($f_user = db_fetch_object($result)){
$uids[$f_user->uid] = $f_user->name;
}
$form['staffbio_uid'] = array(
'#type' => 'select',
'#title' => t('Employee Name'),
'#default_value' => $node->uid,
'#options' => $uids,
'#description' => t('Select a user to associate this bio with.'),
);
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => t('Bio'),
'#default_value' => $node->body,
'#cols' => 60,
'#rows' => 20,
'#attributes' => NULL,
'#required' => TRUE,
);
$form['body_filter']['format'] = filter_form($node->format);
return $form;
}
?>