2022 EduSoho开发手册 日常技巧之增加数据导出功能

2022 EduSoho开发手册 日常技巧之增加数据导出功能

注册服务

services.yml

  keshifens_export_map:
    class: KeshifenPlugin\Component\Export\Factory
    arguments: ['@service_container']
    public: true

注册Factory

Factory.php

 'KeshifenPlugin\Component\Export\Keshifen\CountExporter',
        ];
    }
}

创建导出文件

CountExporter

getUser();

        if ($user->hasPermission('admin_operation_invite_record') || $user->hasPermission('admin_v2_operation_invite_record')) {
            return true;
        }

        return false;
    }

    public function getCount()
    {
        return $this->getUserUidService()->countUserUids($this->conditions);
    }

    public function getContent($start, $limit)
    {
        return [];
    }

    public function buildCondition($conditions)
    {
        $conditions = ArrayToolkit::parts($conditions, array('keyword'));
        if (!empty($conditions['keyword'])) {
            $user = $this->getUserService()->getUserByLoginField($conditions['keyword']);

            $conditions['user_id'] = empty($user) ? '0' : $user['id'];
        }

        return $conditions;
    }

    protected function exportDataByUserUid($user_uid, $users)
    {
        $content   = [];
        return $content;
    }

    /**
     * @return UserService
     */
    protected function getUserService()
    {
        return $this->getBiz()->service('User:UserService');
    }

    /**
     * @return UserUidService
     */
    protected function getUserUidService()
    {
        return $this->getBiz()->service('UserUidPlugin:UserUid:UserUidService');
    }

    protected function getSettingService()
    {
        return $this->getBiz()->service('System:SettingService');
    }
}

前台导出文件

index.html.twig

  
{% include 'export/export-btn.html.twig' with { 'exportFileName' : 'keshifens:count', 'targetFormId' : 'user-keshifen-form' } %}

你可能感兴趣的:(2022 EduSoho开发手册 日常技巧之增加数据导出功能)