XF 2.3 Another Help Session

Ozzy47

Well-known member
Ok, I am working on a force ignore addon where someone with the correct permission can force a user to ignore another user, or force them to ignore each other. I have everything working correctly for that.

Now the issue I am trying to combat is when a user goes to mysite.com/account/ignored they can see a list of people that they are ignoring. Then next to each person they are ignoring there is a button to Unignore. I have it working so that if they click on that button where the user is forced ignored, they get a error message stating they can not unignore that user.

However, I would like to hide the button completely if the user in their list is forced ignored. I have tried a variety of ways but have failed at every attempt. So I am wondering how to handle it if someone was to be so kind to help out.
 
Guess I should give a bit of DB info. I added three columns (I might add more as I progress) to the xf_user_ignored table. Now I want to check if the column ozzmodz_forceignore is set to 1, then hide the button.
 
Do you want to do it in code so they can't just navigate to members/name.123/ignore or will a template edit suffice?
 
On this page, I want to hide the button Unignore, for the user Dupe9 because that user is force ignored. For QuachVu, the button should show as that user is not force ignored. (prefer in code but I think I need a TM as well)

Screenshot_6-3-2025_171057_snogssite.com.webp
 
I think a template edit (to hide the button if it's a force ignore) would suffice since I am already stopping them from unignoring in code.
 
I have it working, but I am overwriting the whole function:
PHP:
class Account extends XFCP_Account
{
    public function actionIgnored()
    {
        $visitor = \XF::visitor();
        if ($ignored = $visitor->Profile->ignored)
        {
            // Fetch all ignored users
            $ignoringUsers = $this->finder(UserFinder::class)
                ->where('user_id', array_keys($ignored))
                ->order('username')
                ->fetch();

            // Fetch all ozzmodz_forceignore values for the visitor's ignored users
            $forceIgnoreRecords = $this->finder('XF:UserIgnored')
                ->where('user_id', $visitor->user_id) // Logged-in user
                ->fetch();

            // Create a map of ignored_user_id => ozzmodz_forceignore
            $forceIgnoreMap = [];
            foreach ($forceIgnoreRecords as $record) {
                $forceIgnoreMap[$record->ignored_user_id] = (bool)$record->ozzmodz_forceignore;
            }
        }
        else
        {
            $ignoringUsers = $this->em()->getEmptyCollection();
            $forceIgnoreMap = []; // No ignored users, so no force ignore data
        }

        $viewParams = [
            'ignoring' => $ignoringUsers,
            'forceIgnoreMap' => $forceIgnoreMap, // Pass the map to the template
        ];
        $view = $this->view('XF:Account\Ignored', 'account_ignored', $viewParams);
        return $this->addAccountWrapperParams($view, 'ignored');
    }
}

What do I need to not overwrite the entire function?
 
I think this is acceptable extending the original function?

PHP:
    public function actionIgnored()
    {
        // Call the parent method to get the original functionality
        $response = parent::actionIgnored();

        // Only proceed if the response is a View object
        if ($response instanceof \XF\Mvc\Reply\View)
        {
            $visitor = \XF::visitor();

            if ($ignored = $visitor->Profile->ignored)
            {
                // Fetch all ozzmodz_forceignore values for the visitor's ignored users
                $forceIgnoreRecords = $this->finder('XF:UserIgnored')
                    ->where('user_id', $visitor->user_id) // Logged-in user
                    ->fetch();

                // Create a map of ignored_user_id => ozzmodz_forceignore
                $forceIgnoreMap = [];
                foreach ($forceIgnoreRecords as $record) {
                    $forceIgnoreMap[$record->ignored_user_id] = (bool)$record->ozzmodz_forceignore;
                }
            }
            else
            {
                $forceIgnoreMap = []; // No ignored users, so no force ignore data
            }

            // Add the forceIgnoreMap to the existing view parameters
            $response->setParam('forceIgnoreMap', $forceIgnoreMap);
        }

        return $response;
    }
 
Back
Top Bottom