| 1 |
<?php
|
| 2 |
/*
|
| 3 |
Current function are stripped to absolute minimum. Most import about this module is the basic DB structures that will be needed in the other modules.
|
| 4 |
For the future it is expected that some basic functions needed by several AC modules will get abstracted to this module.
|
| 5 |
|
| 6 |
by Mixel Kiemen
|
| 7 |
*/
|
| 8 |
|
| 9 |
function adaptive_context_help($field)
|
| 10 |
{
|
| 11 |
switch ($field)
|
| 12 |
{
|
| 13 |
case 'admin/modules#description':
|
| 14 |
return t('basic modules for adaptive context package, defines groups DB structure.');
|
| 15 |
}
|
| 16 |
}
|
| 17 |
|
| 18 |
//the hook_group_audience_sugestions (hook from node_access)
|
| 19 |
function adaptive_context_group_audience_sugestions($node)
|
| 20 |
{
|
| 21 |
$groupquery = db_query("SELECT g.type, g.gid, g.name FROM {ac_group} g INNER JOIN {ac_part} gp ON gp.pid=g.gid AND gp.pid=$node->uid AND gp.type='member'");
|
| 22 |
$usergroups = array();
|
| 23 |
while($object = db_fetch_object($groupquery))
|
| 24 |
$usergroups[$object->type][$object->gid] = $object->name;
|
| 25 |
return $usergroups;
|
| 26 |
}
|
| 27 |
|
| 28 |
/***********************************************************/
|
| 29 |
/* group functions */
|
| 30 |
/***********************************************************/
|
| 31 |
//some generaly used DB functions
|
| 32 |
|
| 33 |
//returns a query that will get all the parts for a part-type (used by node_access)
|
| 34 |
function ac_parts_query($pid, $ptype)
|
| 35 |
{
|
| 36 |
return "SELECT gid, cid FROM {ac_part} gp_aud WHERE gp_aud.pid=$pid AND gp_aud.ptype= '$ptype'";
|
| 37 |
}
|
| 38 |
|
| 39 |
//get the group by id
|
| 40 |
function ac_group_load($gid)
|
| 41 |
{
|
| 42 |
if(!$gid)
|
| 43 |
return;
|
| 44 |
$group = db_fetch_object(db_query("SELECT * FROM {ac_group} WHERE gid = $gid"));
|
| 45 |
ac_group_module_invoke('load', $group);
|
| 46 |
return $group;
|
| 47 |
}
|
| 48 |
|
| 49 |
function ac_group_module_invoke($op, &$group)
|
| 50 |
{
|
| 51 |
foreach (module_list() as $module)
|
| 52 |
{
|
| 53 |
$function = $module .'_groupAPI';
|
| 54 |
if (function_exists($function))
|
| 55 |
$function($op, $group);
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
/***********************************************************/
|
| 60 |
/* ac_block functions */
|
| 61 |
/***********************************************************/
|
| 62 |
//Two blocks for user and group are created. Other modules will use the blocks to add functions
|
| 63 |
|
| 64 |
//By saving the menu $pid we can add functions to the menu later on
|
| 65 |
function adaptive_context_menu($may_cache)
|
| 66 |
{
|
| 67 |
$links = array();
|
| 68 |
if ($may_cache)
|
| 69 |
{
|
| 70 |
$item = array('mid' => 0, 'pid' => 0, 'path' => '', 'weight' => 0, 'type' => MENU_CUSTOM_MENU, 'title' =>'Identity space');
|
| 71 |
if(!ac_block_mid('Identity space'))
|
| 72 |
menu_edit_item_save($item);
|
| 73 |
|
| 74 |
$item = array('mid' => 0, 'pid' => 0, 'path' => '', 'weight' => 0, 'type' => MENU_CUSTOM_MENU, 'title' =>'Group space');
|
| 75 |
if(!ac_block_mid('Group space'))
|
| 76 |
menu_edit_item_save($item);
|
| 77 |
}
|
| 78 |
return $links;
|
| 79 |
}
|
| 80 |
|
| 81 |
function adaptive_context_block($op='list', $delta=0, $edit = array())
|
| 82 |
{
|
| 83 |
if ($op == "list")
|
| 84 |
{
|
| 85 |
$block[0]["info"] = t('Identity space');
|
| 86 |
$block[1]["info"] = t('Group space');
|
| 87 |
} else if ($op == 'view')
|
| 88 |
switch($delta)
|
| 89 |
{
|
| 90 |
case 0:
|
| 91 |
$uid = ac_block_id('user');
|
| 92 |
if(!$uid)
|
| 93 |
break;
|
| 94 |
$thisuser = user_load(array('uid'=>$uid));
|
| 95 |
$output = theme('menu_tree',ac_block_mid('Identity space'));
|
| 96 |
$block['subject'] = $thisuser->name.'<hr><div align="right"><font size=1>Identity space</font></div>';
|
| 97 |
$block['content'] = $output;
|
| 98 |
break;
|
| 99 |
case 1:
|
| 100 |
$gid = ac_block_id('group');
|
| 101 |
if(!$gid)
|
| 102 |
break;
|
| 103 |
$group = ac_group_load($gid);
|
| 104 |
$output .= theme('menu_tree', ac_block_mid('Group space'));
|
| 105 |
$block['subject'] = $group->name.'<hr><div align="right"><font size=1>Group space</font></div>';
|
| 106 |
$block['content'] = $output;
|
| 107 |
break;
|
| 108 |
}
|
| 109 |
return $block;
|
| 110 |
}
|
| 111 |
|
| 112 |
//use the user api to save the identity $uid => user block change when klicking on user
|
| 113 |
function adaptive_context_user($type, &$edit, &$thisuser, $category = NULL)
|
| 114 |
{
|
| 115 |
global $user;
|
| 116 |
if($user->uid != $thisuser->uid)
|
| 117 |
ac_block_id('user', $thisuser->uid);
|
| 118 |
}
|
| 119 |
|
| 120 |
//getting and setting the block_id
|
| 121 |
// TO DO make it work with cookie instead of var.
|
| 122 |
function ac_block_id($level, $lid = NULL)
|
| 123 |
{
|
| 124 |
global $user;
|
| 125 |
if (!$user->uid)
|
| 126 |
return 0;
|
| 127 |
|
| 128 |
if (!is_null($lid)) // => set
|
| 129 |
variable_set('ac_block_id_'.$level.$user->uid, $lid);
|
| 130 |
|
| 131 |
return variable_get('ac_block_id_'.$level.$user->uid, 0);
|
| 132 |
}
|
| 133 |
|
| 134 |
function ac_block_mid($title)
|
| 135 |
{
|
| 136 |
$query = db_query("SELECT mid FROM {menu} WHERE title ='$title'");
|
| 137 |
if(!db_num_rows($query))
|
| 138 |
return 0;
|
| 139 |
|
| 140 |
return db_result($query);
|
| 141 |
}
|
| 142 |
?>
|