<?php
namespace Application\Service\DB\Item;

use Application\Service\DB\Dictionary\FormVersion;
use Application\Service\Extension\Laminas;
use Interop\Container\ContainerInterface;

class ItemFormVersion extends FormVersion
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        if (!$this->tableName) {
            $this->tableName = 'yikeen_item_form_version';
        }

        parent::__construct($dbAdapter, $container);
    }

    /**
     * 重新生成表单配置, 并覆盖掉原配置
     * @param int $formId 表单id
     */
    public function generate(int $formId)
    {
        $this->update([
            'field' => Laminas::$serviceManager->itemForm->buildFieldVersion($formId)
        ], ['form_id' => $formId]);
    }
}