Fixing admin funcionality add user to group see #5611

skala
Julio Montoya 15 years ago
parent 6b2fba8b8e
commit 6e965b8cad
  1. 2
      main/admin/add_users_to_group.php
  2. 1
      main/inc/lib/display.lib.php
  3. 84
      main/inc/lib/group_portal_manager.lib.php
  4. 11
      main/inc/lib/sortabletable.class.php
  5. 2
      main/inc/lib/usermanager.lib.php
  6. 43
      main/social/groups.php

@ -217,6 +217,8 @@ if($_POST['form_sent']) {
}
if ($form_sent == 1) {
GroupPortalManager::delete_users($group_id);
$result = GroupPortalManager::add_users_to_groups($UserList, array($group_id));

@ -317,6 +317,7 @@ class Display {
$column = 0;
$default_items_per_page = isset ($paging_options['per_page']) ? $paging_options['per_page'] : 20;
$table = new SortableTableFromArray($content, $column, $default_items_per_page, $name);
if (is_array($query_vars)) {
$table->set_additional_parameters($query_vars);
}

@ -260,7 +260,7 @@ class GroupPortalManager
$sql = "SELECT g.picture_uri, g.name, g.description, g.id
FROM $tbl_group g
INNER JOIN $table_group_rel_user gu
ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition ";
ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition ORDER BY created_on desc ";
$result=Database::query($sql,__FILE__,__LINE__);
$array = array();
@ -275,6 +275,76 @@ class GroupPortalManager
return $array;
}
/** Gets the inner join of users and group table
* @author Julio Montoya
* @return int access url id
* @return array Database::store_result of the result
* */
function get_groups_by_popularity($num = 10, $with_image = false)
{
$where = '';
$table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
if (empty($num)) {
$num = 10;
} else {
$num = intval($num);
}
$sql = "SELECT count(user_id) as count, g.picture_uri, g.name, g.description, g.id
FROM $tbl_group g
INNER JOIN $table_group_rel_user gu
ON gu.group_id = g.id GROUP BY g.id ORDER BY count DESC LIMIT $num";
$result=Database::query($sql,__FILE__,__LINE__);
$array = array();
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($with_image == true) {
$picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
$img = '<img src="'.$picture['file'].'" />';
$row['picture_uri'] = $img;
}
$array[$row['id']] = $row;
}
return $array;
}
/** Gets the last groups created
* @author Julio Montoya
* @return int access url id
* @return array Database::store_result of the result
* */
function get_groups_by_age($num = 10, $with_image = false)
{
$where = '';
$table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
if (empty($num)) {
$num = 10;
} else {
$num = intval($num);
}
$sql = "SELECT g.picture_uri, g.name, g.description, g.id
FROM $tbl_group g
INNER JOIN $table_group_rel_user gu
ON gu.group_id = g.id ORDER BY created_on desc LIMIT $num ";
$result=Database::query($sql,__FILE__,__LINE__);
$array = array();
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($with_image == true) {
$picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
$img = '<img src="'.$picture['file'].'" />';
$row['picture_uri'] = $img;
}
$array[$row['id']] = $row;
}
return $array;
}
function get_users_by_group($group_id='', $with_image = false)
{
$where = '';
@ -396,10 +466,10 @@ class GroupPortalManager
$table_group_rel_user= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
$return_value = 0;
if (!empty($user_id) && !empty($group_id)) {
$sql = "SELECT relation_type FROM $table_group_rel_user WHERE id = ".intval($group_id)." AND user_id = ".intval($user_id)." ";
$sql = "SELECT relation_type FROM $table_group_rel_user WHERE group_id = ".intval($group_id)." AND user_id = ".intval($user_id)." ";
$result = Database::query($sql, __FILE__, __LINE__);
if (Database::num_rows($result)>0) {
$row = Database::fetch_row($result);
$row = Database::fetch_array($result,'ASSOC');
$return_value = $row['relation_type'];
}
}
@ -545,7 +615,7 @@ class GroupPortalManager
if ($role == 0) {
$sql = "INSERT INTO $table_url_rel_group
SET user_id = ".intval($user_id).", group_id = ".intval($group_id).", relation_type = ".intval($relation_type)."";
$result = Database::query($sql, __FILE__, __LINE__);
if ($result)
$result_array[$group_id][$user_id]=1;
@ -567,10 +637,10 @@ class GroupPortalManager
* @param int url id
* @return boolean true if success
* */
function delete_url_rel_user($user_id, $url_id)
function delete_users($group_id)
{
$table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql= "DELETE FROM $table_url_rel_user WHERE user_id = ".Database::escape_string($user_id)." AND access_url_id=".Database::escape_string($url_id)." ";
$table_= Database :: get_main_table(TABLE_MAIN_USER_REL_GROUP);
$sql= "DELETE FROM $table_ WHERE group_id = ".intval($group_id);
$result = Database::query($sql, __FILE__, __LINE__);
return $result;
}

@ -491,8 +491,15 @@ class SortableTable extends HTML_Table {
.search_users_grid_nav { float:right;}
</style>';
$items = $this->get_clean_html(); // getting the items of the table
if ($hide_navigation == true ) {
$items = $this->table_data; //this is a faster way to get what we want
} else {
//the normal way
$items = $this->get_clean_html(); // getting the items of the table
}
// the generating of style classes must be improved. Maybe we need a a table name to create style on the fly:
// i.e: .whoisonline_table_grid_container instead of .grid_container
// where whoisonline is the table's name like drupal's template engine

@ -2652,7 +2652,7 @@ class UserManager
</div>
<div>
<input type="text" size="30" value="'.Security::remove_XSS($query).'" tabindex="1" id="standard_q" name="q"/>
<input type="submit" value="search"/>
<button class="search" value="search"/>'.get_lang('Search').'</button>
</div>
</td>
</tr>

@ -104,22 +104,51 @@ if ($group_id != 0 ) {
} else {
echo '<h1>'.get_lang('Newest').'</h1>';
echo '<h1>'.get_lang('Popular').'</h1>';
echo '<h1>'.get_lang('MyGroups').'</h1>';
$results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0, true);
// Newest groups ----------------
$results = GroupPortalManager::get_groups_by_age(10 , true);
$groups = array();
foreach ($results as $result) {
$id = $result['id'];
$url_open = '<a href="groups.php?id='.$id.'">';
$url_close = '</a>';
$url_close = '</a>';
$groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close);
}
if (count($groups) > 0) {
echo '<h1>'.get_lang('Newest').'</h1>';
Display::display_sortable_grid('search_users', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
}
// Pop groups ----------------
$results = GroupPortalManager::get_groups_by_popularity(10 , true);
$groups = array();
foreach ($results as $result) {
$id = $result['id'];
$url_open = '<a href="groups.php?id='.$id.'">';
$url_close = '</a>';
$groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close,$result['count']);
}
if (count($groups) > 0) {
echo '<h1>'.get_lang('Popular').'</h1>';
Display::display_sortable_grid('search_users', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,true));
}
Display::display_sortable_grid('search_users', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
// My groups
$results = GroupPortalManager::get_groups_by_user(api_get_user_id(), 0, true);
$groups = array();
foreach ($results as $result) {
$id = $result['id'];
$url_open = '<a href="groups.php?id='.$id.'">';
$url_close = '</a>';
$groups[]= array($url_open.$result['picture_uri'].$url_close, $url_open.$result['name'].$url_close);
}
echo '<h1>'.get_lang('MyGroups').'</h1>';
if (count($groups) > 0) {
Display::display_sortable_grid('search_users', array(), $groups, array('hide_navigation'=>true, 'per_page' => 100), $query_vars, false, array(true, true, true,false));
} else {
echo get_lang('CreateAgroup');
}
}

Loading…
Cancel
Save