<?php

namespace addons\poster;

use app\common\library\Menu;
use think\Addons;
use think\Request;

/**
 * 超级海报管理插件
 */
class Poster extends Addons
{
    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'poster',
                'title'   => '超级海报',
                'icon'    => 'fa fa-qrcode',
                'remark'  => '设计生成海报，支持会员昵称、头像、自定义图片、自定义二维码。',
                'sublist' => [
                    ['name' => 'poster/index', 'title' => '查看'],
                    ['name' => 'poster/add', 'title' => '添加'],
                    ['name' => 'poster/edit', 'title' => '修改'],
                    ['name' => 'poster/del', 'title' => '删除'],
                    ['name' => 'poster/multi', 'title' => '批量更新'],
                    ['name' => 'poster/posterrecord', 'title' => '查看记录'],
                    ['name' => 'poster/clear', 'title' => '清除海报'],
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('poster');
        return true;
    }
    
    /**
     * 插件启用方法
     */
    public function enable()
    {
        Menu::enable('poster');
    }

    /**
     * 插件禁用方法
     */
    public function disable()
    {
        Menu::disable('poster');
    }

    /**
     * 会员中心边栏后
     * @return mixed
     * @throws \Exception
     */
    public function userSidenavAfter()
    {
        $request = Request::instance();
        $controllername = strtolower($request->controller());
        $actionname = strtolower($request->action());
        $data = [
            'actionname'     => $actionname,
            'controllername' => $controllername
        ];
        return $this->fetch('view/hook/user_sidenav_after', $data);
    }
}
