<?php
/**
 * Class represents records from table integrations
 * {autogenerated}
 * @property int $integration_id PK
 * @property string $comment
 * @property string|null $plugin
 * @property string|null $vars
 * {/autogenerated}
 */
class Integration extends ResourceAbstract
{
    public function getLinkTitle()
    {
        return null;
    }
}

/** @extends ResourceAbstractTable<Integration> */
class IntegrationTable extends ResourceAbstractTable
{
    protected $_key = 'integration_id';
    protected $_table = '?_integration';
    protected $_recordClass = 'Integration';

    public function getAccessType()
    {
        return ResourceAccess::INTEGRATION;
    }

    public function getAccessTitle()
    {
        return ___('Integrations');
    }

    public function getPageId()
    {
        return 'integrations';
    }

    public function getTitleField()
    {
        return 'comment';
    }

    /** @return array of Integration */
    public function getAllowedResources(User $user, $pluginId)
    {
        $ret = [];
        foreach ($this->getDi()->resourceAccessTable
                    ->getAllowedResources($user, ResourceAccess::INTEGRATION) as $r)
            if ($r->plugin == $pluginId) $ret[] = $r;
        return $ret;
    }
}