| 1 |
<?php
|
| 2 |
// $Id: og_titles.module,v 1.1 2008/10/15 02:01:02 mradcliffe Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @File
|
| 6 |
* Organic Groups Titles
|
| 7 |
* add arbitrary custom titles to organic group members
|
| 8 |
*
|
| 9 |
* Matthew Radcliffe <mradcliffe@kosada.com>
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* hook_help implementation
|
| 14 |
* @param $path
|
| 15 |
* @param $arg
|
| 16 |
*/
|
| 17 |
function og_titles_help($path,$arg)
|
| 18 |
{
|
| 19 |
switch($path)
|
| 20 |
{
|
| 21 |
case 'admin/help#og_titles':
|
| 22 |
return '<p>'.t('Extends Organic Groups allowing you to add arbitrary tiles or ranks per user in a group.');
|
| 23 |
}
|
| 24 |
} // function og_titles_help
|
| 25 |
|
| 26 |
|
| 27 |
/**
|
| 28 |
* hook_menu implementation
|
| 29 |
*/
|
| 30 |
function og_titles_menu()
|
| 31 |
{
|
| 32 |
$items['og/users/%node/titles'] = array(
|
| 33 |
'title' => 'Member Titles',
|
| 34 |
'description' => 'Manage custom member titles',
|
| 35 |
'page callback' => 'drupal_get_form',
|
| 36 |
'page arguments' => array('og_titles_view_titles',1),
|
| 37 |
'access callback' => 'og_is_group_admin',
|
| 38 |
'access arguments' => array(2),
|
| 39 |
'type' => MENU_LOCAL_TASK,
|
| 40 |
'weight' => 5,
|
| 41 |
);
|
| 42 |
|
| 43 |
return $items;
|
| 44 |
} // funtion og_titles_menu
|
| 45 |
|
| 46 |
|
| 47 |
/**
|
| 48 |
* member titles admin page
|
| 49 |
* @param $form_state reference to the form
|
| 50 |
* @param $node hopefully the group node object or nid i.e. arg(2)
|
| 51 |
* @return $form the form to be returned
|
| 52 |
*/
|
| 53 |
function og_titles_view_titles(&$form_state, $node)
|
| 54 |
{
|
| 55 |
if ( ! is_numeric($node->nid) )
|
| 56 |
{
|
| 57 |
if ( ! is_numeric(arg(2)) )
|
| 58 |
{
|
| 59 |
drupal_set_message('error: gid is not numeric: '.$node.' or '.arg(2));
|
| 60 |
return;
|
| 61 |
}
|
| 62 |
else
|
| 63 |
$gid = arg(2);
|
| 64 |
}
|
| 65 |
else
|
| 66 |
$gid = $node->nid;
|
| 67 |
|
| 68 |
$form = array();
|
| 69 |
|
| 70 |
$res = db_query("SELECT ogu.uid, u.name, ogt.title, ogu.nid FROM {og_uid} ogu LEFT OUTER JOIN {og_uid_titles} ogt ON (ogu.uid = ogt.uid AND ogu.nid = ogt.nid) INNER JOIN {users} u ON (u.uid = ogu.uid) WHERE ogu.nid = %d",$gid);
|
| 71 |
|
| 72 |
while ( $titles = db_fetch_object($res) )
|
| 73 |
{
|
| 74 |
|
| 75 |
$form[$titles->uid] = array(
|
| 76 |
'#type' => 'textfield',
|
| 77 |
'#title' => t($titles->name . '\'s title'),
|
| 78 |
'#default_value' => '',
|
| 79 |
'#value' => $titles->title,
|
| 80 |
'#size' => 60,
|
| 81 |
'#maxlength' => 64,
|
| 82 |
);
|
| 83 |
}
|
| 84 |
|
| 85 |
$form['nid'] = array(
|
| 86 |
'#type' => 'value',
|
| 87 |
'#value' => $gid
|
| 88 |
);
|
| 89 |
|
| 90 |
$form['submit'] = array(
|
| 91 |
'#type' => 'submit',
|
| 92 |
'#value' => t('Save'),
|
| 93 |
);
|
| 94 |
|
| 95 |
|
| 96 |
return $form;
|
| 97 |
} // function og_titles_view_titles
|
| 98 |
|
| 99 |
|
| 100 |
/**
|
| 101 |
* submit function for admin page
|
| 102 |
* @param $form
|
| 103 |
* @param $form_state
|
| 104 |
*/
|
| 105 |
function og_titles_view_titles_submit($form, &$form_state)
|
| 106 |
{
|
| 107 |
$nid = $form['nid']['#value'];
|
| 108 |
$users = _og_titles_get_uids($nid);
|
| 109 |
|
| 110 |
foreach ( $users as $usr )
|
| 111 |
{
|
| 112 |
if ( $form['#post'][$usr->uid] <> '')
|
| 113 |
{
|
| 114 |
if ( isset($usr->title))
|
| 115 |
db_query("UPDATE {og_uid_titles} SET title = '%s' WHERE uid = %d and nid = %d",$form['#post'][$usr->uid],$usr->uid,$nid);
|
| 116 |
else
|
| 117 |
db_query("INSERT INTO {og_uid_titles} (nid,uid,title) VALUES (%d,%d,'%s')",$nid,$usr->uid,$form['#post'][$usr->uid]);
|
| 118 |
}
|
| 119 |
}
|
| 120 |
} // function og_titles_view_titles_submit
|
| 121 |
|
| 122 |
|
| 123 |
/**
|
| 124 |
* grab the user id and title from the og_uid_titles table (private)
|
| 125 |
* @param $nid the group node id
|
| 126 |
* @return $uids an array of og_uid_titles result objects.
|
| 127 |
*/
|
| 128 |
function _og_titles_get_uids($nid)
|
| 129 |
{
|
| 130 |
$uids = array();
|
| 131 |
|
| 132 |
if ( !is_numeric($nid) )
|
| 133 |
return $uids;
|
| 134 |
|
| 135 |
$res = db_query("SELECT ogu.uid, ogt.title FROM og_uid ogu LEFT OUTER JOIN og_uid_titles ogt ON (ogu.uid = ogt.uid AND ogu.nid = ogt.nid) INNER JOIN users u WHERE ogu.uid = u.uid AND ogu.nid = %d",$nid);
|
| 136 |
|
| 137 |
while ( $og_usr = db_fetch_object($res) )
|
| 138 |
array_push($uids,$og_usr);
|
| 139 |
|
| 140 |
return $uids;
|
| 141 |
|
| 142 |
} // function _og_titles_get_uids
|
| 143 |
|