web: limit the number of subscriptions to 4, explicitely mark the non-aliased URLs

This commit is contained in:
Bart Van Der Meerssche 2009-09-05 19:00:37 +00:00
parent 82dfb52a1f
commit 679fb06f5d
1 changed files with 25 additions and 12 deletions

View File

@ -23,7 +23,7 @@
/** /**
* @file * @file
* Logs metering values reported through XML-RPC in the Drupal & RRD database and displays them in different charts * Support module for charting data stored in RRD's
*/ */
@ -246,8 +246,21 @@ function _logger_dashboard($type, $function, $interval) {
function _logger_add($uid) { function _logger_add($uid) {
global $user; global $user;
$rtid = db_result(db_query("SELECT rtid FROM {user_relationship_types} where name = '%s'", 'subscription')); $result = db_fetch_array(db_query("SELECT COUNT(rid), MAX(rid), ur.rtid FROM {user_relationships} ur INNER JOIN {user_relationship_types} urt ON ur.rtid = urt.rtid WHERE requester_id = %d AND urt.name = '%s' GROUP BY ur.rtid", $user->uid, 'subscription'));
user_relationships_request_relationship($user->uid, $uid, $rtid, TRUE);
// max subscriptions = 4
if ($result['COUNT(rid)'] < 4) {
user_relationships_request_relationship($user->uid, $uid, $result['rtid'], TRUE);
}
else {
//check whether the requested relationship doesn't already exist
if (!db_result(db_query("SELECT rid FROM {user_relationships} WHERE requester_id = %d AND requestee_id = %d AND rtid = %d", $user->uid, $uid, $result['rtid']))) {
// if not, delete the most recently added relationship and replace it with the newly selected one
db_query("DELETE FROM {user_relationships} WHERE rid = %d", $result['MAX(rid)']);
user_relationships_request_relationship($user->uid, $uid, $result['rtid'], TRUE);
}
}
$destination = drupal_get_destination(); $destination = drupal_get_destination();
drupal_goto($destination); drupal_goto($destination);
} }
@ -340,7 +353,7 @@ function logger_block($op = 'list', $delta = 0, $edit = array()) {
$result = db_query("SELECT u.uid, u.name, ur.rid FROM ({users} u INNER JOIN {user_relationships} ur ON u.uid = ur.requestee_id) INNER JOIN {user_relationship_types} urt ON ur.rtid = urt.rtid WHERE ur.requester_id = %d AND urt.name = '%s' ORDER BY ur.rid", $user->uid, 'subscription'); $result = db_query("SELECT u.uid, u.name, ur.rid FROM ({users} u INNER JOIN {user_relationships} ur ON u.uid = ur.requestee_id) INNER JOIN {user_relationship_types} urt ON ur.rtid = urt.rtid WHERE ur.requester_id = %d AND urt.name = '%s' ORDER BY ur.rid", $user->uid, 'subscription');
$items = array(); $items = array();
while ($subscription = db_fetch_object($result)) { while ($subscription = db_fetch_object($result)) {
$items[] = l('[x]', 'logger/remove/'. $subscription->rid, array('attributes' => array('title' => "unsubscribe from ". $subscription->name ."'s stream"), 'query' => $destination)) .' '. l($subscription->name, 'user/'. $subscription->uid, array()); $items[] = l('[x]', 'logger/remove/'. $subscription->rid, array('attributes' => array('title' => "unsubscribe from ". $subscription->name ."'s stream"), 'query' => $destination, 'alias' => TRUE)) .' '. l($subscription->name, 'user/'. $subscription->uid, array('alias' => FALSE));
} }
$block['subject'] = t('Subscriptions'); $block['subject'] = t('Subscriptions');
$block['content'] = theme('logger_item_list', $items); $block['content'] = theme('logger_item_list', $items);
@ -352,7 +365,7 @@ function logger_block($op = 'list', $delta = 0, $edit = array()) {
$result = db_query("SELECT u.uid, u.name FROM ({users} u INNER JOIN {users_roles} ur ON u.uid = ur.uid) INNER JOIN {role} r ON ur.rid = r.rid WHERE r.name = '%s' AND NOT u.uid = %d ORDER BY u.name", 'fluksonian', $user->uid); $result = db_query("SELECT u.uid, u.name FROM ({users} u INNER JOIN {users_roles} ur ON u.uid = ur.uid) INNER JOIN {role} r ON ur.rid = r.rid WHERE r.name = '%s' AND NOT u.uid = %d ORDER BY u.name", 'fluksonian', $user->uid);
$items = array(); $items = array();
while ($fluksonian = db_fetch_object($result)) { while ($fluksonian = db_fetch_object($result)) {
$items[] = l('[+]', 'logger/add/'. $fluksonian->uid, array('attributes' => array('title' => "subscribe to ". $fluksonian->name ."'s stream"), 'query' => $destination)) .' '. l($fluksonian->name, 'user/'. $fluksonian->uid, array()); $items[] = l('[+]', 'logger/add/'. $fluksonian->uid, array('attributes' => array('title' => "subscribe to ". $fluksonian->name ."'s stream"), 'query' => $destination, 'alias' => TRUE)) .' '. l($fluksonian->name, 'user/'. $fluksonian->uid, array('alias' => FALSE));
} }
$block['subject'] = t('Fluksonians'); $block['subject'] = t('Fluksonians');
$block['content'] = theme('logger_item_list', $items); $block['content'] = theme('logger_item_list', $items);
@ -365,17 +378,17 @@ function logger_block($op = 'list', $delta = 0, $edit = array()) {
switch ($unit) { switch ($unit) {
case 'watt': case 'watt':
$items[] = 'watt'; $items[] = 'watt';
$items[] = l('kWh/year', 'logger/unit/kwh', array('attributes' => array('title' => "switch to kWh/year"), 'query' => $destination)); $items[] = l('kWh/year', 'logger/unit/kwh', array('attributes' => array('title' => "switch to kWh/year"), 'query' => $destination, 'alias' => TRUE));
$items[] = l('euro/year', 'logger/unit/eur', array('attributes' => array('title' => "switch to euro/year"), 'query' => $destination)); $items[] = l('euro/year', 'logger/unit/eur', array('attributes' => array('title' => "switch to euro/year"), 'query' => $destination, 'alias' => TRUE));
break; break;
case 'kwh': case 'kwh':
$items[] = l('watt', 'logger/unit/watt', array('attributes' => array('title' => "switch to watt"), 'query' => $destination)); $items[] = l('watt', 'logger/unit/watt', array('attributes' => array('title' => "switch to watt"), 'query' => $destination, 'alias' => TRUE));
$items[] = 'kWh/year'; $items[] = 'kWh/year';
$items[] = l('euro/year', 'logger/unit/eur', array('attributes' => array('title' => "switch to euro/year"), 'query' => $destination)); $items[] = l('euro/year', 'logger/unit/eur', array('attributes' => array('title' => "switch to euro/year"), 'query' => $destination, 'alias' => TRUE));
break; break;
case 'eur': case 'eur':
$items[] = l('watt', 'logger/unit/watt', array('attributes' => array('title' => "switch to watt"), 'query' => $destination)); $items[] = l('watt', 'logger/unit/watt', array('attributes' => array('title' => "switch to watt"), 'query' => $destination, 'alias' => TRUE));
$items[] = l('kWh/year', 'logger/unit/kwh', array('attributes' => array('title' => "switch to kWh/year"), 'query' => $destination)); $items[] = l('kWh/year', 'logger/unit/kwh', array('attributes' => array('title' => "switch to kWh/year"), 'query' => $destination, 'alias' => TRUE));
$items[] = 'euro/year'; $items[] = 'euro/year';
break; break;
} }