KSA
Well-known member
I am trying to extend UserPrivacy to have ignored users unable to view profile page of users who ignored them. My code works fine except that I want to make :allow profile access upon ignore optional. I assume I need to create column in the xf_user_option table so added that by
My UserPrivacy class extension
My Account class extension
My UserOption class extension
then went ahead and created TM
Now the 1/0 value should return false/true or is there something I am not understanding here or missing
This is my first attempt trying to get familiar with the programming language so please save the laughs.
PHP:
$this->schemaManager()->alterTable('xf_user_option', function(Alter $table)
{
$table->addColumn('myaddon_enabled', 'tinyInt')->setDefault(1);
});
My UserPrivacy class extension
PHP:
<?php
namespace addon\XF\Entity;
class UserPrivacy extends XFCP_UserPrivacy
{
public function isPrivacyCheckMet($privacyKey, \XF\Entity\User $user)
{
if ($this->user_id == $user->user_id || $user->canBypassUserPrivacy())
{
return true;
}
if ($this->User->isIgnoring($user))
{
return false;
}
return parent::isPrivacyCheckMet($privacyKey, $user);
}
}
My Account class extension
PHP:
<?php
namespace myaddon\XF\Pub\Controller;
use XF\Entity\User;
class Account extends XFCP_Account
{
protected function preferencesSaveProcess(User $visitor)
{
$form = parent::preferencesSaveProcess($visitor);
$input = $this->filter([
'option' => ['my_addon_enabled' => 'bool']
]);
$userOptions = $visitor->getRelationOrDefault('Option');
$form->setupEntityInput($userOptions, $input['option']);
return $form;
}
}
My UserOption class extension
PHP:
<?php
namespace myaddon\ddon\Name\XF\Entity;
use XF\Mvc\Entity\Structure;
class UserOption extends XFCP_UserOption
{
public static function getStructure(Structure $structure)
{
$parent = parent::getStructure($structure);
$parent->columns['myaddon_enabled'] = ['type' => self::BOOL, 'default' => true];
return $parent;
}
}
then went ahead and created TM
HTML:
<xf:radiorow name="option[myaddon_enabled]" value="{$xf.visitor.Option.myaddon_enabled}"
label="{{ phrase('xxxxxxx') }}"
explain="{{ phrase('xxxxxxxxxxx') }}">
<xf:option value="1">{{ phrase('yes') }}</xf:option>
<xf:option value="0">{{ phrase('no') }}</xf:option>
</xf:radiorow>
Now the 1/0 value should return false/true or is there something I am not understanding here or missing
This is my first attempt trying to get familiar with the programming language so please save the laughs.
Last edited: