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

use Interop\Container\ContainerInterface;

class ItemFormFieldRadio extends \Application\Service\DB\AbstractDb
{
    /** @var int 表单关联 */
    public const RELATION_CLASSIFICATION_FORM = 1;
    /** @var int 字段关联 */
    public const RELATION_CLASSIFICATION_FIELD = 2;

    public function __construct($dbAdapter, ContainerInterface $container)
    {
        if (!$this->tableName) {
            $this->tableName = 'yikeen_dictionary_form_field_radio';
        }

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


    /**
     * Notes:获取指定条件下的数据
     * User: lltyy
     * DateTime: 2024/5/15 9:20
     *
     * @param $where 条件
     * @param $columns 字段
     * @param string $key 键值
     * @param int $is_more 是否有多笔数据【0 否 1 是】
     * @return array
     */
    public function fetchDataByKey($where,$columns,$key='id',$is_more = 0){
        $datas = [];
        $cond = [
            'where'=>$where,
            'columns'=>$columns,
            'order'=>['form_id','parent','order']
        ];
        $infoDatas = $this->fetchAll($cond);
        if(!empty($infoDatas)){
            foreach($infoDatas as $infoKey=>$infoData){
                $data_key = isset($infoData[$key]) && !empty($infoData[$key]) ? $infoData[$key] : '';
                if($is_more == 1){
                    $datas[$data_key][] = $infoData;
                }else{
                    $datas[$data_key] = $infoData;
                }
                unset($infoDatas[$data_key]);
            }
        }
        unset($cond);
        unset($infoDatas);

        return $datas;
    }
}