<?php

namespace Application\Service\DB\Item;

use Interop\Container\ContainerInterface;

class PatientAeContent extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        if (!$this->tableName) {
            $this->tableName = 'yikeen_item_patient_ae_content';
        }

        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,$order=['id'],$key='id',$is_more = 0){
        $datas = [];
        $cond = [
            'where'=>$where,
            'columns'=>$columns,
            'order'=>$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;
    }

    public function save(array $saveData)
    {
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
        if (isset($trace[1])) {
            $caller = $trace[1];
            $source = "文件: {$caller['file']}\n";
            $source.= "行号: {$caller['line']}\n";
            $source.= "函数: {$caller['function']}\n";
        }
        $saveData['source'] = $source;
        $content = print_r($saveData, true);

        file_put_contents(APP_PATH.'/data/aeSave.txt',$content,FILE_APPEND);
        return parent::save($saveData); // TODO: Change the autogenerated stub
    }
    
}
