AndrewSimm
Well-known member
I have extended XF\Pub\Controller\Member with the intent of adding the option for moderators to discourage users. When I try and use the same functions used in Admin/Users I am unable to get it to work. If I use the finder and save then it works. What do I need to do to get the below code to work or should I stick with the way I am doing it?
	
	
	
		
				
			
		PHP:
	
	<?php
namespace Andrew\ModeratorPanel\XF\Pub\Controller;
use XF\Mvc\FormAction;
class Member extends XFCP_Member
{
    protected function memberSaveProcess(\XF\Entity\User $user)
    {
        $visitor = \XF::visitor();
        if ($visitor->canDiscourageUsers())
        {
            $form = $this->formAction();
            $input = $this->filter([
                'option' => [
                    'is_discouraged' => 'bool'
                ]
            ]);
            $userOptions = $user->getRelationOrDefault('Option');
            $form->setupEntityInput($userOptions, $input['option']);
            /* This works but probably isn't the right way to do it
                $user_id = $user->user_id;
                $input = $this->filter([
                    'option' => [
                        'is_discouraged' => 'bool'
                    ]
                ]);
                $finder = \XF::finder('XF:UserOption');
                $userOption = $finder
                    ->where('user_id',$user_id)
                    ->fetchOne();
                $userOption->is_discouraged = $input['option']['is_discouraged'];
                $userOption->save();
            */
        }
        $response = parent::memberSaveProcess($user);
        return $response;
    }
} 
 
		 
 
		

 
 
		 
 
		 
 
		 
 
		