| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* $Id:$
|
| 4 |
* @package OG_MMGBR
|
| 5 |
* @category NeighborForge
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_install().
|
| 10 |
*/
|
| 11 |
function og_multiple_mandatory_groups_by_role_install() {
|
| 12 |
$query_results = drupal_install_schema('og_multiple_mandatory_groups_by_role');
|
| 13 |
|
| 14 |
//setup vars for default (un-deleteable mandatory group lists
|
| 15 |
$all_users_rid = -1;
|
| 16 |
$all_users_name = t('All users');
|
| 17 |
$all_users_mand_groups = array();
|
| 18 |
$group_owners_rid = 0;
|
| 19 |
$group_owners_name = t('Group admins');
|
| 20 |
$group_owners_mand_groups = array();
|
| 21 |
|
| 22 |
if ($all = variable_get(og_mandatory_group, FALSE)) {
|
| 23 |
$all_users_mand_groups = $all;
|
| 24 |
drupal_set_message(t('Found previously used Mandatory Group variables...'));
|
| 25 |
drupal_set_message(t('using existing Mandatory Groups for new <em>All Users</em> category...'));
|
| 26 |
if (db_table_exists(og_multi_mand_groups_role_groups)) {
|
| 27 |
drupal_set_message(t('using existing Mandatory Groups for new <em>Available Groups</em> table...'));
|
| 28 |
foreach ($all as $gid => $value) {
|
| 29 |
$sql = "SELECT n.title FROM {node} n WHERE n.nid = %d";
|
| 30 |
$result = db_fetch_object(db_query($sql, $gid));
|
| 31 |
if (db_query("INSERT INTO {og_multi_mand_groups_role_groups} VALUES (%d, '%s')", $gid, $result->title)) {
|
| 32 |
drupal_set_message(t("added <em>%name</em> to the group availability table...", array('%name' => $result->title)));
|
| 33 |
}
|
| 34 |
}
|
| 35 |
}
|
| 36 |
db_query("DELETE FROM {variable} WHERE name = '%s'", 'og_mandatory_group');
|
| 37 |
}
|
| 38 |
if ($group_o = variable_get(og_mandatory_group_admin, array())) {
|
| 39 |
$group_owners_mand_groups = $group_o;
|
| 40 |
db_query("DELETE FROM {variable} WHERE name = '%s'", 'og_mandatory_group_admin');
|
| 41 |
}
|
| 42 |
|
| 43 |
//insert the defaults into the new db table
|
| 44 |
if (db_table_exists(og_multi_mand_groups_role)) {
|
| 45 |
$query3 = db_query("INSERT INTO {og_multi_mand_groups_role} VALUES (%d, '%s', '%s')", $all_users_rid, $all_users_name, serialize($all_users_mand_groups));
|
| 46 |
$query4 = db_query("INSERT INTO {og_multi_mand_groups_role} VALUES (%d, '%s', '%s')", $group_owners_rid, $group_owners_name, serialize($group_owners_mand_groups));
|
| 47 |
}
|
| 48 |
|
| 49 |
//make sure all went well
|
| 50 |
if ($query_results[0]['success'] && $query_results[1]['success'] && $query3 && $query4) {
|
| 51 |
drupal_set_message('The OG Multiple Mandatory Groups by Role module was installed successfully. Two tables were added to the database. Default settings were initialized.');
|
| 52 |
}
|
| 53 |
else {
|
| 54 |
drupal_set_message('There was an error installing the OG Multiple Mandatory Groups by Role database table.', 'error');
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Implementation of hook_schema().
|
| 60 |
*/
|
| 61 |
function og_multiple_mandatory_groups_by_role_schema() {
|
| 62 |
$schema['og_multi_mand_groups_role'] = array(
|
| 63 |
'fields' => array(
|
| 64 |
'rid' => array('type' => 'int', 'unsigned' => FALSE, 'length' => 11, 'not null' => TRUE, 'default' => 0, 'description' => 'The role id from the {roles} table.'),
|
| 65 |
'role_name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The name of the role, copied here for convenience.'),
|
| 66 |
'mand_groups' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'description' => 'A serialized array listing groups that are mandatory for the above {roles}.'),
|
| 67 |
),
|
| 68 |
'primary key' => array('rid'),
|
| 69 |
'description' => 'Keeps track of which roles have mandatory groups.',
|
| 70 |
);
|
| 71 |
$schema['og_multi_mand_groups_role_groups'] = array(
|
| 72 |
'fields' => array(
|
| 73 |
'gid' => array('type' => 'int', 'unsigned' => TRUE, 'length' => 11, 'not null' => TRUE, 'default' => 0, 'description' => 'The group id from the {og} table.'),
|
| 74 |
'group_name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The name of the group, copied here for convenience.'),
|
| 75 |
),
|
| 76 |
'primary key' => array('gid'),
|
| 77 |
'description' => 'A list of groups ear-marked by the admin as possible groups to make mandatory.',
|
| 78 |
);
|
| 79 |
|
| 80 |
return $schema;
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Implementation of hook_uninstall().
|
| 85 |
*/
|
| 86 |
function og_multiple_mandatory_groups_by_role_uninstall() {
|
| 87 |
$query_results = drupal_uninstall_schema('og_multiple_mandatory_groups_by_role');
|
| 88 |
|
| 89 |
if ($query_results[0]['success'] && $query_results[1]['success']) {
|
| 90 |
drupal_set_message('The OG Multiple Mandatory Groups by Role module was uninstalled successfully.');
|
| 91 |
}
|
| 92 |
else {
|
| 93 |
drupal_set_message('There was an error removing the OG Multiple Mandatory Groups by Role database table.', 'error');
|
| 94 |
}
|
| 95 |
}
|