TYPO3 TCA用户功能

时间:2018-08-21 10:39:56

标签: typo3 typo3-8.x

Kinda卡住了。

我们有提供给公司的产品。 因此这将是一个mm字段,实现起来没有问题,但问题出在日期上,因为每种产品的到期日期都取决于公司。

因此决定删除产品mm,并将带有日期的产品ID放入公司作为一个字段。

但是由于我们发送的输入是一个数组,因此无法将其保存在那里。

我该如何解决这个问题? 这是我在该领域的tca:

'product' => [
    'exclude' => true,
    'label' => 'LLL:EXT:wemessage_checklist/Resources/Private/Language/locallang_db.xlf:tx_wemessagechecklist_domain_model_company.product',
    'config' => [
       'type' => 'user',
       'userFunc' => Wemessage\WemessageChecklist\UserFunc\Checklist::class.'->renderChecklists',               
    ],
],

这是呈现html的功能:

public function renderChecklists($PA, $fObj){
    $checked = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_wemessagechecklist_domain_model_company', 'hidden=0 and deleted=0 and uid='.$PA['row']['uid'].' and pid='.$PA['row']['pid']);
    $allProducts = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_wemessagechecklist_domain_model_product', 'hidden= 0 and deleted = 0');
    foreach($allProducts as $product){
        $html .= '<div>';
        $html .= '<input type="hidden" name="data[tx_wemessagechecklist_domain_model_company]['.$PA['row']['uid'].'][product]['.$product['uid'].']" class="product"/>';
        $html .= '<input type="checkbox" class="tocheck" value="'.$product['uid'].'" /><span style="margin: 0 10px;">'.$product['name'].'</span><span style="margin: 0 10px;">Verval datum</span><input type="date" class="date" />';
        $html .= '</div>';
    }
    $html .= '<script>
        TYPO3.jQuery(".tocheck").click(function(){
            var val = TYPO3.jQuery(this).val();
            if(TYPO3.jQuery(this).prop("checked")){
                TYPO3.jQuery(this).parent().find(".product").val(val);
            }
        });
        TYPO3.jQuery(".date").change(function(){
            var x = new Date(TYPO3.jQuery(this).val()).getTime();
            var b = TYPO3.jQuery(this).parent().find(".product").val();
            TYPO3.jQuery(this).parent().find(".product").val(b+":"+x);
        });
        </script>';
    return $html;
}

可能的另一个选择是实现AJAX调用以处理独立表中的数据。尽管如果有其他解决方案,我们将很高兴听到。

1 个答案:

答案 0 :(得分:0)

您仍然应该建立公司与产品之间的MM关系或更好的内联(IRRE)连接,因为它们也可以拥有自己的TCA,因此可以在MM关系记录本身中添加开始时间,结束时间和其他值

该概念称为“中间表”,并在此处进行了描述:https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Inline.html#attributes-on-anti-symmetric-intermediate-table

这是从IRRE教程扩展中获取的经过修改的TCA。它仅包含连接和时间戳字段的必要设置-随时为公司和产品添加自己的字段:

$TCA["company"] = Array (
    "columns" => Array (
        "products" => Array (
            "config" => Array (
                "type" => "inline",
                "foreign_table" => "company_product_intermediate",
                "foreign_field" => "company_id",
                "foreign_sortby" => "companysort",
                "foreign_label" => "product_id",
                "maxitems" => 10,
                'appearance' => array(
                    'showSynchronizationLink' => 1,
                    'showAllLocalizationLink' => 1,
                    'showPossibleLocalizationRecords' => 1,
                    'showRemovedLocalizationRecords' => 1,
                ),
                'behaviour' => array(
                    'localizationMode' => 'select',
                ),
            )
        ),
    ),
);



$TCA["company_product_intermediate"] = Array (
    "columns" => Array (
        "company_id" => Array (
            "config" => Array (
                "type" => "select",
                "foreign_table" => "company",
                "maxitems" => 1,
            )
        ),
        "product_id" => Array (
            "config" => Array (
                "type" => "select",
                "foreign_table" => "product",
                "maxitems" => 1,
            )
        ),
        "companysort" => Array (
            "config" => Array (
                "type" => "passthrough",
            )
        ),
        "productsort" => Array (
            "config" => Array (
                "type" => "passthrough",
            )
        ),
        "timestamp" => Array (
            "config" => Array (
                "type" => "input",
            )
        ),
    ),
);



$TCA["product"] = Array (
    "columns" => Array (
        "companies" => Array (
            "config" => Array (
                "type" => "inline",
                "foreign_table" => "company_product_intermediate",
                "foreign_field" => "product_id",
                "foreign_sortby" => "productsort",
                "foreign_label" => "company_id",
                "maxitems" => 10,
                'appearance' => array(
                    'showSynchronizationLink' => 1,
                    'showAllLocalizationLink' => 1,
                    'showPossibleLocalizationRecords' => 1,
                    'showRemovedLocalizationRecords' => 1,
                ),
                'behaviour' => array(
                    'localizationMode' => 'select',
                ),
            )
        ),
    ),
);