XF 2.1 Extend reaction system for implement into addon Social Group

Kevin RG

Active member
Hello XenForo Community :)

I would like add reaction system of xenforo into addon Social Group, i have create addon for extend the extension, but i have a problem and i don't see a solution about my error.

I have this error :
Code:
LogicException: Unknown relation or alias Reactions accessed on xf_tl_group in src/XF/Mvc/Entity/Finder.php at line 753
XF\Mvc\Entity\Finder->join() in src/XF/Mvc/Entity/Finder.php at line 746
XF\Mvc\Entity\Finder->join() in src/XF/Mvc/Entity/Finder.php at line 644
XF\Mvc\Entity\Finder->with() in src/XF/Mvc/Entity/Manager.php at line 147
XF\Mvc\Entity\Manager->find() in src/addons/Truonglv/Groups/ControllerPlugin/Assertion.php at line 59
Truonglv\Groups\ControllerPlugin\Assertion->assertGroupViewable() in src/addons/Induste/SGEnhencement/XF/Pub/Controller/Group.php at line 43
Induste\SGEnhencement\XF\Pub\Controller\Group->actionReactions() in src/XF/Mvc/Dispatcher.php at line 321
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 248
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 100
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2178
XF\App->run() in src/XF.php at line 390
XF::runApp() in index.php at line 20

I have create the content type :

1578074521922.webp

In spoiler you can see my files Reaction\Group and Extended Entity.

PHP:
<?php

namespace Induste\SGEnhencement\Reaction;

use Truonglv\Groups\App;
use XF\Mvc\Entity\Entity;
use XF\Reaction\AbstractHandler;

class Group extends AbstractHandler
{
    public function reactionsCounted(Entity $entity)
    {
        if (!($entity instanceof \Truonglv\Groups\Entity\Group)) {
            return false;
        }

        return $entity->isVisible();
    }

    public function getEntityWith()
    {
        return ['full'];
    }

    public function getTemplateName()
    {
        return 'public:tlg_reaction_item_group';
    }
}

PHP:
<?php
namespace Induste\SGEnhencement\XF\Entity;

use XF\Mvc\Entity\Structure;
use XF\Entity\ReactionTrait;

class Group extends \Truonglv\Groups\Entity\Group
{
    use ReactionTrait;

    public static function getStructure(Structure $structure)
    {
        $structure = parent::getStructure($structure);

        $structure->columns['reaction_score'] = ['type' => self::UINT, 'default' => 0];
        $structure->columns['reactions']      = ['type' => self::JSON_ARRAY, 'nullable' => true];
        $structure->columns['reaction_users'] = ['type' => self::JSON_ARRAY];

        $structure->behaviors = [
            'XF:Reactable' => ['stateField' => 'state'],
        ];

        $structure->withAliases = [
            'full' => [
                'User',
                'User.Profile',
                'User.Privacy',
                function () {
                    if (\XF::options()->showMessageOnlineStatus) {
                        return 'User.Activity';
                    }

                    return null;
                },
                function () {
                    $userId = \XF::visitor()->user_id;
                    if ($userId) {
                        return [
                            'Reactions|' . $userId
                        ];
                    }

                    return null;
                }
            ],
            'api' => [
                'User',
                'User.api',
                'User.Profile'
            ]
        ];

        return  $structure;
    }

    public function canReact(&$error = null)
    {
        $visitor = \XF::visitor();
        if (!$visitor->user_id) {
            return false;
        }

        if (!$this->getContent()) {
            return false;
        }

        if ($visitor->user_id === $this->user_id) {
            $error = \XF::phraseDeferred('reacting_to_your_own_content_is_considered_cheating');

            return false;
        }

        return true;
    }

}
?>

Thanks you in advance for your help !
Best regards,
Kevin
 
You will need to, at the very least, add the structure elements from the trait:

PHP:
 static::addReactableStructureElements($structure);

You will likely also need to add the XF:Reactable behavior, and I think you will want to create alert and news feed handlers as reactions tie into those systems as well.
 
You will need to, at the very least, add the structure elements from the trait:

PHP:
 static::addReactableStructureElements($structure);

You will likely also need to add the XF:Reactable behavior, and I think you will want to create alert and news feed handlers as reactions tie into those systems as well.
Thanks for your help ! It works perfectly ! Yes, once the implementation is finished, I will create alerts and news feeds, but I have already created these actions on my latest addons.

That should do it, well I hope ^^
 
Back
Top Bottom