Skip to content
Snippets Groups Projects
Commit d3c18089 authored by baldwinlouie's avatar baldwinlouie
Browse files

Fixes for group settings page.

parent b84a2023
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -58,6 +58,15 @@ function cloud_metering_menu() { ...@@ -58,6 +58,15 @@ function cloud_metering_menu() {
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'weight' => -9, 'weight' => -9,
); );
$items['admin/config/cloud_metering/group_settings/%/%'] = array(
'title' => 'User Group Settings',
'description' => 'Set Group details and Budget',
'page callback' => 'drupal_get_form',
'page arguments' => array('cloud_metering_user_list', 4, 5),
'access arguments' => array('configure group budget'),
'type' => MENU_CALLBACK,
'weight' => -9,
);
$items['admin/config/cloud_metering/mail_settings'] = array( $items['admin/config/cloud_metering/mail_settings'] = array(
'title' => 'Mail Settings', 'title' => 'Mail Settings',
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
* @param $instance_id string The instance id * @param $instance_id string The instance id
* @return array The result of the database query * @return array The result of the database query
*/ */
function _cloud_metering_instance_cost_data($start, $end, $cloud_context = '', $instance_id = '') { function _cloud_metering_instance_cost_data($start, $end, $cloud_context = '', $instance_id = '') {
if ($start && $end) { if ($start && $end) {
...@@ -317,14 +316,244 @@ function _cloud_metering_get_template_data($template_id) { ...@@ -317,14 +316,244 @@ function _cloud_metering_get_template_data($template_id) {
function _cloud_metering_get_budget_configured_users() { function _cloud_metering_get_budget_configured_users() {
$rows = array(); $rows = array();
$query = 'SELECT * FROM {' . CLOUD_METERING_USER_BUDGET_TABLE . '} WHERE budget != 0'; $query = 'SELECT * FROM {' . CLOUD_METERING_USER_BUDGET_TABLE . '} WHERE budget != 0';
$result = db_query($query); $result = db_query($query);
while ($row = $result->fetchAssoc()) { while ($row = $result->fetchAssoc()) {
$rows[] = $row; $rows[] = $row;
} }
return $rows; return $rows;
} }
/**
* Add group budget into the database
*/
function _cloud_metering_add_group_budget($group_id, $group_threshold, $group_budget, $user_data) {
return db_insert(CLOUD_METERING_BUDGET_GROUP_TABLE)
->fields(array(
'user_data' => $user_data,
'grid' => $group_id,
'threshold' => $group_threshold,
'group_budget' => $group_budget,
))
->execute();
}
/**
* Add user budget into the database
*/
function _cloud_metering_add_user_budget($uid, $group_id, $group_threshold, $user_budget) {
return db_insert(CLOUD_METERING_USER_BUDGET_TABLE)
->fields(array(
'id' => NULL,
'uid' => $uid,
'grid' => $group_id,
'threshold' => $group_threshold,
'budget' => $user_budget,
))
->execute();
}
/**
* Update Group budget
*/
function _cloud_metering_update_group_budget($group_id, $group_threshold, $group_budget, $user_data) {
return db_update(CLOUD_METERING_BUDGET_GROUP_TABLE)
->fields(array(
'user_data' => $user_data,
'threshold' => $group_threshold,
'group_budget' => $group_budget,
))
->condition('grid', $group_id, '=')
->execute();
}
/**
* Update User Budget
*/
function _cloud_metering_update_user_budget($uid, $group_id, $user_budget) {
return db_update(CLOUD_METERING_USER_BUDGET_TABLE)
->fields(array(
'budget' => $user_budget,
))
->condition('uid', $uid, '=')
->condition('grid', $group_id, '=')
->execute();
}
/**
* Get user groups
* @param Array gids
* Optional array of group-ids to return
* @return Array
* The database rows corresponding to the groups
*/
function _cloud_metering_get_groups($gids = array()) {
$return = array();
$query = db_select(CLOUD_METERING_BUDGET_GROUP_TABLE, 'c')
->fields('c');
if (count($gids)) {
$query->condition('c.gid', $gids, 'IN');
}
$results = $query->execute();
while ($record = $results->fetchAssoc()) {
$return[] = $record;
}
return $return;
}
/**
* Get group admins
* @param Integer gid The group-id
* @return Array The group admin(s)
*/
function _cloud_metering_get_group_admins($gid) {
$query = "SELECT user_data FROM {" . CLOUD_METERING_BUDGET_GROUP_TABLE . "} WHERE gid = " . $gid;
$result = db_query($query)->fetchField();
if ($result !== FALSE) {
$result = unserialize($result);
if (is_array($result) && sizeof($result) > 0) {
$return = array();
foreach ($result as $uid => $value) {
if ($value > 0) {
$return[] = $uid;
}
}
return $return;
}
}
return array(1); // Return the super-user in case there is no group admin(s)
}
/**
* Return roles in the database
*/
function _cloud_metering_get_group_details($rid = '') {
$query = db_select('role', 'r')
->fields('r', array('rid', 'name'));
// $rid is passed, return only that role
if (!empty($rid)) {
$query->condition('r.rid', $rid);
}
else {
$query->condition('r.rid', 2, '>');
}
return $query->execute()->fetchAllAssoc('rid', PDO::FETCH_ASSOC);
}
/**
* Get Group Budget. If gid or rid are passed, add those as
* conditions to the query
*/
function _cloud_metering_get_group_budget($gid = '', $rid = '') {
$key = 'gid';
$query = db_select(CLOUD_METERING_BUDGET_GROUP_TABLE, 'cm')
->fields('cm');
if (!empty($gid)) {
$query->condition('cm.gid', $gid);
}
if (!empty($rid)) {
$query->condition('cm.grid', $rid);
$key = 'grid';
}
return $query->execute()->fetchAllAssoc($key, PDO::FETCH_ASSOC);
}
/**
* Get User Allocated Budget
*/
function _cloud_metering_get_user_budget($arg) {
$budget_query = db_query("SELECT budget FROM {" . CLOUD_METERING_USER_BUDGET_TABLE . "} WHERE uid = " . $arg )->fetchField();
if (is_numeric($budget_query)) {
return $budget_query;
}
else {
return 0;
}
}
/**
* Get Group Users Details
*/
function _cloud_metering_get_group_users_details($arg = '') {
if (!empty($arg['value'])) {
$where_query = "WHERE " . $arg['column'] . " = " . $arg['value'];
}
else {
$where_query = '';
}
$group_users_query = db_query("SELECT * FROM {" . CLOUD_METERING_USER_BUDGET_TABLE . "} " . $where_query);
$group_users = array();
foreach ($group_users_query as $u) {
$row = array();
$row['uid'] = $u->uid;
$row['gid'] = $u->gid;
$row['budget'] = $u->budget;
if (!empty($arg)) {
$group_users[$u->uid] = $row;
}
else {
$group_users[$u->gid] = $row;
}
}
return $group_users;
}
/**
* Get all Drupal Users where uid > 1
*/
function _cloud_metering_get_users_list_by_role($rid) {
$query = db_select('users', 'u')
->fields('u', array('uid', 'mail', 'name'))
->fields('ur', array('rid'))
->condition('ur.rid', $rid)
->condition('u.uid', 1, '>');
$query->innerJoin('users_roles', 'ur', 'u.uid=ur.uid');
return $query->execute()->fetchAllAssoc('uid', PDO::FETCH_ASSOC);
}
/**
* Get all Drupal Roles expect the Default Drupal roles
*/
function _cloud_metering_get_roles_list($arg = '') {
$roles = array();
$roles[0] = '--Select Role--';
if (!empty($arg)) {
$where_query = "WHERE rid =" . $arg;
}
else {
$where_query = 'WHERE rid > 2';
}
$roles_query = db_query('SELECT * FROM {role} ' . $where_query);
// while ($u = db_fetch_object($roles_query)) {
foreach ($roles_query as $u) {
$roles[$u->rid] = $u->name;
}
return $roles;
}
\ No newline at end of file
...@@ -116,7 +116,7 @@ function cloud_server_templates_menu() { ...@@ -116,7 +116,7 @@ function cloud_server_templates_menu() {
'title' => 'Template Info', 'title' => 'Template Info',
'page callback' => 'cloud_server_templates_notify', 'page callback' => 'cloud_server_templates_notify',
'page arguments' => array(3, 'view', $cloud_context), 'page arguments' => array(3, 'view', $cloud_context),
'access arguments' => array('view server templates'), 'access arguments' => array('view server template'),
'file' => '', 'file' => '',
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment