Custom Managing Members in Admin

Hi i just want to add in the view for managing members, right now the current table view is
Delete?-Username-Title-Actions
I want to add two columns, rank position and category. How can I do that?
Delete?-Username-Title-Category-Rank-Actions
 

Basti

Administrator
Staff member
Hmm something must have been lost at some update, could have sworn we had this already.

Pls download and unzip the attached file and replace sourses/admin/manage.php

Now with the core edit in place you can make use of the 2 plugin hooks found in that file
in your plugin add the file admin_manage_build_page.php and place something like this to add something to the table heading .eg.
Code:
$extra_heading .= '<th>category</th>';
and admin_manage_member_loop.php you do
Code:
$extra .= "<td>{$row['category']}</td>";
The actual code for the category rank, overall rank, you already have, you just need to place before the query to get the rank
Code:
// Make ORDER BY clause
    $order_by = $this->rank_by($CONF['ranking_method'])." DESC, unq_{$CONF['ranking_method']}_overall DESC";
so your code would end up like
Code:
    // Make ORDER BY clause
    $order_by = $this->rank_by($CONF['ranking_method'])." DESC, unq_{$CONF['ranking_method']}_overall DESC";

   $rank_overall = 1;
    $rank_result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
    while (list($username) = $DB->fetch_array($rank_result))
    {
        if($username == $row['username'])
        {
            break;
        }
        $rank_overall++;
    }

   // Escape users category
    $category_rank_sql = $DB->escape($category_raw, 1);

    $rank_category = 1;
    $rank_result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 AND category = '{$category_rank_sql}' ORDER BY {$order_by}", __FILE__, __LINE__);
    while (list($username) = $DB->fetch_array($rank_result))
    {
        if($username == $row['username'])
        {
            break;
        }
        $rank_category++;
    }
 

Attachments

// Make ORDER BY clause
$order_by = $this->rank_by($CONF['ranking_method'])." DESC, unq_{$CONF['ranking_method']}_overall DESC";

$rank_overall = 1;
$rank_result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
while (list($username) = $DB->fetch_array($rank_result))
{
if($username == $row['username'])
{
break;
}
$rank_overall++;
}

// Escape users category
$category_rank_sql = $DB->escape($category_raw, 1);

$rank_category = 1;
$rank_result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 AND category = '{$category_rank_sql}' ORDER BY {$order_by}", __FILE__, __LINE__);
while (list($username) = $DB->fetch_array($rank_result))
{
if($username == $row['username'])
{
break;
}
$rank_category++;
}




Where do I put this code?
 

Basti

Administrator
Staff member
I gave you plugin before, remember? CategoryListCount
Make the files in there, or a new plugin, up to you.

I showed you how to create a table heading and a table column, right? And you have the code which calculates the rank.
You just have to replace/duplicate what I showed you

admin_manage_build_page.php
Code:
$extra_heading .= '<th>category</th>';
$extra_heading .= '<th>rank category</th>';
$extra_heading .= '<th>rank overall</th>';
admin_manage_member_loop.php you do
Code:
  // Make ORDER BY clause
  $order_by = $this->rank_by($CONF['ranking_method'])." DESC, unq_{$CONF['ranking_method']}_overall DESC";

  $rank_overall = 1;
    $rank_result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 ORDER BY {$order_by}", __FILE__, __LINE__);
    while (list($username) = $DB->fetch_array($rank_result))
    {
        if($username == $row['username'])
        {
            break;
        }
        $rank_overall++;
    }

  // Escape users category
    $category_rank_sql = $DB->escape($category_raw, 1);

    $rank_category = 1;
    $rank_result = $DB->query("SELECT sites.username FROM {$CONF['sql_prefix']}_sites sites, {$CONF['sql_prefix']}_stats stats WHERE sites.username = stats.username AND active = 1 AND category = '{$category_rank_sql}' ORDER BY {$order_by}", __FILE__, __LINE__);
    while (list($username) = $DB->fetch_array($rank_result))
    {
        if($username == $row['username'])
        {
            break;
        }
        $rank_category++;
    }

    $extra .= "<td>{$row['category']}</td>";
    $extra .= "<td>{$rank_category}</td>";
    $extra .= "<td>{$rank_overall}</td>";
 

Basti

Administrator
Staff member
You need again replace manage.php, download and replace attached file

Then in your existing plugin file admin_manage_build_page.php
Code:
// Add new item to sort array
$filter_array[] = 'Rank';

// extend the security checks, used in the pagination and query to get members
if (!empty($FORM['filter']))
{
  switch ($FORM['filter'])
  {
    case 'Rank':  $filter = $this->rank_by($CONF['ranking_method'])." {$order}, unq_{$CONF['ranking_method']}_overall"; break;

    // The default $filter = $filter is what we already defined before this plugin hook
    default:  $filter = $filter; break;
  }
}
You may notice, we only set a sinlg extra filter for ranks, that is because in order to rank by category, you actually need to search for the category, as the category rank is nothing stored in database
Now in the same plugin setup a new file called admin_manage_extend_search.php
in there paste
Code:
if (preg_match('/^category\s(.+)/i', $FORM['search'], $matches))
{
  if (isset($matches[1]))
  {
    $search_name = htmlspecialchars($matches[0], ENT_QUOTES, "UTF-8");
    $search_name_sql = $DB->escape($matches[1], 1);
    $search_sql = "AND category = '{$search_name_sql}'";
  }
}
Now how things work?
- You select from filter the option rank.If you leave the search field empty, it ranks by overall rank
- to rank by category, you actually need to fetch the category, that's why we extended the search
You need again select rank, but additionally insert into the search field "category my category name"
Its important that you write category itself before your actual category name so the default search is not triggered

This is a bit complicated, but no other way, as again you cannot sort your list without having the category name at hand, that's why we search for it.
 

Attachments

Last edited:
So for what i understand is that if i want to sort by rank by Category i need to input the Category name first? In the text field?
 

Basti

Administrator
Staff member
Yes with the word "category" before your actual category name. Else we cannot difference between a normal search which looks at username, title etc.
"category My Category"
 

Basti

Administrator
Staff member
Pls download zip again and let me know, I forgot to modify the query, it only grabbed from sites tables, so order by rank wasn't working
 

Basti

Administrator
Staff member
Yea the latest sorry ( post #10 ), I updated the other zip just now also just to keep it consistent
 
Its already working .. big thanks..
But I wonder it didn't sort out the position rank well and duplicate rank position found.

See screenshot attached.
 

Attachments

Last edited:
Top