SMF Post Prefix

Started by Diego Andrés, May 11, 2015, 10:37:35 PM

Previous topic - Next topic

peter_mein

Everything OK. The cache was not yet rewritten and
still showed me the old state.

mickjav

Hi I'm sure this request will only be related to what I'm doing.

What I have done:

I have built A Synce To My Chart Weeks So when new weeks are added it creates the corresponding prefix and links it to the Chart Week.

My prefix name is created so:
2020 Jul 09: UK Singles Chart:
2020 Jun 13: Billboard Hot 100 Singles:
2020 Feb 06: UK Albums Chart:

This all works fine but my question/request is would of be possible For specific boards to to be able to change the sort order from ASC to DESC The board I wish the order to be changed for is board_ID 136

if there is a code change I could make please let me know.

Just in case it's of use to others i've posted the code.
this is what I built to synce the prefixes and chart weeks

The call is set so only admin runs it "Q: Is there a is admin context?"
//Add Any New Chart Weeks To The Prexixes
        if ($context['user']['is_guest'])
        $mem_id = 0;
        else
        $mem_id = $context['user']['id'];
        //Only Run For Admin
        if ($mem_id == 1) CheckForNewChartWeeks();

The two functions below do the work, You will need to update the "id_prefix = 805" to what you need plus I have added a tag to the prefixes table to make managing them simpler "p_type"

function CheckForNewChartWeeks()
{
    global $smcFunc;
   
    $prefix_name = '';
   
    $dbquery = $smcFunc['db_query']('', '
    SELECT w.week_id, w.wkend, c.chart_name, c.chart_name_short, c.use_prefix
    FROM {db_prefix}chart_weeks AS w
    INNER JOIN {db_prefix}chart_names AS c ON (w.chart_id = c.chart_id)
    WHERE w.prefix_id = 0 AND YEAR(w.wkend) >= 2020 AND c.use_prefix = 1
    ORDER BY YEAR(w.wkend) DESC');
       
    if ($smcFunc['db_affected_rows']() != 0)
    {
        while($row = $smcFunc['db_fetch_assoc']($dbquery)){
        $prefix_name = date("Y M d",strtotime($row['wkend'])) . ': ' .(strlen($row['chart_name_short'])>0 ? $row['chart_name_short'] : $row['chart_name']) . ':';
        addChartWeeksPrefix($row['week_id'], $prefix_name, 3);
        }
    }       
   
        $smcFunc['db_free_result']($dbquery);
}

//Auto Add Prefixes To Artists
function addChartWeeksPrefix($id, $prefix_name, $typ)
{

        global $smcFunc;

        isAllowedTo('music_can_edit_artists');
   
       
        $smcFunc['db_query']('', "INSERT INTO {db_prefix}postprefixes
                    (name, p_type)
                    VALUES('$prefix_name', '$typ')");
                   
        $prefix = $smcFunc['db_insert_id']('{db_prefix}postprefixes', 'id');
       
    //Update The Chart Week
    $smcFunc['db_query']('', "UPDATE {db_prefix}chart_weeks
                    SET prefix_id = '$prefix'
                    WHERE week_id = $id LIMIT 1");
   
    //Do Boards
    $boardquery = $smcFunc['db_query']('', '
    SELECT id_board
    FROM {db_prefix}postprefixes_boards
    WHERE id_prefix = 805');


        while ($brow = $smcFunc['db_fetch_assoc']($boardquery))
        {
            $board = $brow['id_board'];
            $smcFunc['db_query']('', "INSERT INTO {db_prefix}postprefixes_boards
                    (id_prefix, id_board)
                    VALUES('$prefix', '$board')");
        }
        $smcFunc['db_free_result']($boardquery);

    //Do Permissions
    $groupquery = $smcFunc['db_query']('', '
    SELECT id_group
    FROM {db_prefix}postprefixes_groups
    WHERE id_prefix = 805');


        while ($grow = $smcFunc['db_fetch_assoc']($groupquery))
        {
            $group = $grow['id_group'];
            $smcFunc['db_query']('', "INSERT INTO {db_prefix}postprefixes_groups
                    (id_prefix, id_group)
                    VALUES('$prefix', '$group')");
        }
        $smcFunc['db_free_result']($groupquery);       
       
}

Home of Chart Tracker Elite, Apollo & DJ 2020, Coming soon The Librarian.

Steve

I may have come across a bug. When I have a board that requires prefixes and have 'Remove 'No prefix' from the list when the board requires a prefix.' selected, the 'No Prefix' still shows in the boards requiring a prefix. Can you confirm Diego?
Autocorrect is my worst enema.

Diego Andrés

Quote from: mickjav on January 09, 2023, 03:57:16 AMThis all works fine but my question/request is would of be possible For specific boards to to be able to change the sort order from ASC to DESC The board I wish the order to be changed for is board_ID 136
Prefixes are added globally so they can be available easier.

In PostPrefix/PostPrefix.php
Add $board to the globals.
Code (Search) Select
$context['user_prefixes']['post'] = Database::pNested(
'pp.' . (!empty($modSettings['PostPrefix_select_order']) ? 'id' : 'name')
Code (Replace) Select
$custom_boards = [1];
$custom_sorting = (!empty($board) && in_array($board, $custom_boards) ? ' DESC' : '');
$context['user_prefixes']['post'] = Database::pNested(
'pp.' . (!empty($modSettings['PostPrefix_select_order']) ? 'id' : 'name') . $custom_sorting

Just put your boards in the $custom_boards array: [2,5,453,67,223]





Quote from: Steve on January 12, 2023, 06:26:54 PMI may have come across a bug. When I have a board that requires prefixes and have 'Remove 'No prefix' from the list when the board requires a prefix.' selected, the 'No Prefix' still shows in the boards requiring a prefix. Can you confirm Diego?

I reckon a few pages ago on this topic it was suggested it worked this way to prevent users from submitting topics with whatever prefix appears first on the list.

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav


Home of Chart Tracker Elite, Apollo & DJ 2020, Coming soon The Librarian.

Steve

Quote from: Steve on January 12, 2023, 06:26:54 PMI may have come across a bug. When I have a board that requires prefixes and have 'Remove 'No prefix' from the list when the board requires a prefix.' selected, the 'No Prefix' still shows in the boards requiring a prefix. Can you confirm Diego?
Quote from: Diego Andrés on January 12, 2023, 07:56:37 PMI reckon a few pages ago on this topic it was suggested it worked this way to prevent users from submitting topics with whatever prefix appears first on the list.
I don't think I understand. Why would the option be in the settings then?
Autocorrect is my worst enema.

Diego Andrés

I might remove it, or add a note that it doesn't apply for boards that require prefixes to prevent users from submitting topics without checking what prefix is selected.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Steve

Ah, okay. Thanks Diego.
Autocorrect is my worst enema.

mickjav

Hi think this may relate to @vbgamer45 pretty urls

When I use the link I created
/charts/chart-analysis/?action=post;prefix=809 all works as intended,

But when I use the new topic button link I see the prefix id I.E. charts/chart-analysis/?prefix=1 but no prefix is preselected on the post screen.


All the best mick





Home of Chart Tracker Elite, Apollo & DJ 2020, Coming soon The Librarian.

Diego Andrés

For filtering the board? I wouldn't know how to support pretty urls.
But also you provided different examples, action=post would be different than just browsing the board without action=post

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

This is the link

https://www.databasedreams.co.uk/charts/artists-forums-126/?prefix=152 but I can't see the prefix in the new topic button url anymore??, that link filters the board for that prefix which is from my artists homepage
https://www.databasedreams.co.uk/charts/index.php?action=music;area=artists;sa=home;art=-1455642346

When I get on my pc ill look into this more as was sure the new topic button included the prefix? maybe I'm seeing things  :o



Home of Chart Tracker Elite, Apollo & DJ 2020, Coming soon The Librarian.

Diego Andrés

The new topic button does not add a prefix to the url when filtering, that's not a feature... yet.  :P
I'm not sure if you added the prefix to a custom url from the music action and that's why you thought it was the same behavior?

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

Thought I was going nuts lol

All the best mick

Home of Chart Tracker Elite, Apollo & DJ 2020, Coming soon The Librarian.

Advertisement: