Custom Managing Members in Admin

Discussion in 'General Help' started by softdevsalon, Feb 27, 2019.

  1. softdevsalon
    • Licensed

    softdevsalon Member

    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
  2. Basti
    • Staff

    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++;
        }
    

    Attached Files:

  3. softdevsalon
    • Licensed

    softdevsalon Member

    where can I find or put the admin_manage_build_page.php and admin_manage_member_loop.php?
  4. softdevsalon
    • Licensed

    softdevsalon Member

    // 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?
  5. softdevsalon
    • Licensed

    softdevsalon Member

    Not just the category I want to show the rank also
  6. softdevsalon
    • Licensed

    softdevsalon Member

    Tried in the plugins, but I dont know how to show the rank in admin manage page.
  7. Basti
    • Staff

    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>";
  8. softdevsalon
    • Licensed

    softdevsalon Member

    Thank you so much for this
    Basti likes this.
  9. softdevsalon
    • Licensed

    softdevsalon Member

    One more thing, How do I sort it via custom the one you made? via rank overall, and by rank category.
  10. Basti
    • Staff

    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.

    Attached Files:

    Last edited: Mar 6, 2019
  11. softdevsalon
    • Licensed

    softdevsalon Member

    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?
  12. Basti
    • Staff

    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"
  13. softdevsalon
    • Licensed

    softdevsalon Member

    Ok got it. Will try tomorrow the code. Thank you.

  14. softdevsalon
    • Licensed

    softdevsalon Member

    Just tried this. I've got this.

    Fatal error: Database error in "\bm\sources\admin\manage.php" on line 249
  15. Basti
    • Staff

    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
  16. softdevsalon
    • Licensed

    softdevsalon Member

    The latest zip you sent yesterday?
  17. Basti
    • Staff

    Basti Administrator Staff Member

    Yea the latest sorry ( post #10 ), I updated the other zip just now also just to keep it consistent
  18. softdevsalon
    • Licensed

    softdevsalon Member

    Another error found.
    Fatal error: Unsupported operand types in \bm\sources\admin\manage.php on line 101
  19. Basti
    • Staff

    Basti Administrator Staff Member

  20. softdevsalon
    • Licensed

    softdevsalon Member

    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.

    Attached Files:

    Last edited: Mar 7, 2019

Share This Page