b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Mirasvit / ReportApi / Config / Entity /
Filename/home/dev2.destoffenstraat.com/app/code/Mirasvit/ReportApi/Config/Entity/Table.php
Size5.33 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified15-Oct-2024 20:30
Last accessed22-Aug-2025 02:07
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Mirasvit
*
* This source file is subject to the Mirasvit Software License, which is available at https://mirasvit.com/license/.
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
* If you wish to customize this module for your needs.
* Please refer to http://www.magentocommerce.com for more information.
*
* @category Mirasvit
* @package mirasvit/module-report-api
* @version 1.0.71
* @copyright Copyright (C) 2024 Mirasvit (https://mirasvit.com/)
*/



namespace Mirasvit\ReportApi\Config\Entity;

use Mirasvit\ReportApi\Api\Config\ColumnInterface;
use Mirasvit\ReportApi\Api\Config\FieldInterface;
use Mirasvit\ReportApi\Api\Config\TableInterface;
use Mirasvit\ReportApi\Service\TableService;

class Table implements TableInterface
{
/**
* @var string
*/
protected $name;

/**
* @var string
*/
protected $group;

/**
* @var bool
*/
protected $isNative;

/**
* @var string
*/
protected $label;

/**
* @var FieldInterface[]
*/
protected $fieldsPool = [];

/**
* @var ColumnInterface[]
*/
protected $columnsPool = [];

/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface
*/
protected $connection;

/**
* @var string
*/
protected $connectionName;

/**
* @var FieldFactory
*/
protected $fieldFactory;

/**
* @var TableService
*/
private $tableService;

/**
* @var bool
*/
private $isTmp = false;

/**
* Table constructor.
* @param TableService $tableService
* @param FieldFactory $fieldFactory
* @param string $name
* @param mixed $label
* @param bool $isNative
* @param null $group
* @param string $connection
*/
public function __construct(
TableService $tableService,
FieldFactory $fieldFactory,
$name,
$label,
$isNative = false,
$group = null,
$connection = 'default'
) {
$this->name = $name;
$this->label = $label;
$this->isNative = $isNative;
$this->group = $group;
$this->connectionName = $connection;

$this->fieldFactory = $fieldFactory;
$this->tableService = $tableService;

$this->initFields();
}

/**
* @return void
*/
private function initFields()
{
$fields = $this->tableService->describeTable($this);

foreach ($fields as $fieldName => $info) {
$field = $this->fieldFactory->create([
'table' => $this,
'name' => $fieldName,
'identity' => $info['IDENTITY'] ? true : false,
]);

$this->fieldsPool[$field->getName()] = $field;
}
}

/**
* {@inheritdoc}
*/
public function getGroup()
{
return $this->group;
}

/**
* {@inheritdoc}
*/
public function getLabel()
{
return $this->label;
}

/**
* {@inheritdoc}
*/
public function isNative()
{
return $this->isNative;
}

/**
* {@inheritdoc}
*/
public function getColumn($name)
{
if (isset($this->columnsPool[$name])) {
return $this->columnsPool[$name];
} else {
throw new \Exception(__('Undefined column "%1"', $name));
}
}

/**
* {@inheritdoc}
*/
public function getColumns()
{
return $this->columnsPool;
}

/**
* @return FieldInterface
* @throws \Exception
*/
public function getPkField()
{
# exception
if ($this->getName() == 'catalog_product_entity' || $this->getName() == 'catalog_category_entity') {
foreach ($this->fieldsPool as $field) {
if ($field->getName() == 'entity_id') {
return $field;
}
}
}

foreach ($this->fieldsPool as $field) {
if ($field->isIdentity()) {
return $field;
}
}

throw new \Exception("Can't find primary field to table {$this->name}");
}

/**
* {@inheritdoc}
*/
public function getConnectionName()
{
return $this->connectionName;
}

/**
* {@inheritdoc}
*/
public function addColumn(ColumnInterface $column)
{
$this->columnsPool[$column->getName()] = $column;

return $this;
}

/**
* {@inheritdoc}
*/
public function getFields()
{
return $this->fieldsPool;
}

/**
* {@inheritdoc}
*/
public function getField($name)
{
if (key_exists($name, $this->fieldsPool)) {
return $this->fieldsPool[$name];
}

throw new \Exception(__("Field %1 does not exist in table %2", $name, $this->getName()));
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}

/**
* @return string
*/
public function __toString()
{
return "{$this->name}";
}

/**
* {@inheritdoc}
*/
public function isTmp()
{
return $this->isTmp;
}

/**
* {@inheritdoc}
*/
public function setIsTmp($isTmp = true)
{
$this->isTmp = $isTmp;

return $this;
}
}