<?php
declare (strict_types = 1);

namespace app\controller;

use Curl\Curl;
use app\kernel\Lebolebo\Account;
use app\kernel\Lebolebo\Curriculum;

class Test
{
    public function login()
    {
        $account = new Account();
        dump($account);
        dump($account->login('13088393927','HIMIsm1yxpt4'));
    }
    public function index()
    {
        $savepath = store_path() . '/lebolebo/';
        $curl = new Curl();
        $curr = new Curriculum();
        $course = $curr->list(0);
        foreach ($course['data']['list'] as $list){
            $c = $savepath . $list['courseName'];
            is_dir($c) || mkdir($c);
            dump($curr->course($list['courseCode']));
            $detail = $curr->detail($list['id']);
            dump($detail);
            $courseCover = $c . '/courseCover' . '.png';
            is_file($courseCover) || $curl->download($detail['data']['courseCover'],$courseCover);
            $d = $curr->courseUnitList($list['courseCode']);
            $courseUnits = $d['data']['courseUnit'];
            foreach ($courseUnits as $courseUnit){
                $courseUnitName = $c . '/' . str_ireplace('/','-',$courseUnit['courseUnitName']);
                if(!is_dir($t)){
                    dump($t);
                    mkdir($t);
                }
                $selectByCourseUnits = $curr->selectByCourseUnits($courseUnit['courseCode'],$courseUnit['courseUnitCode']);
                foreach ($selectByCourseUnits['data'] as $selectByCourseUnit){
                    $sessionName = $courseUnitName . '/' . $selectByCourseUnit['sessionName'];
                    if(!is_dir($sessionName)){
                        dump($sessionName);
                        mkdir($sessionName,0755,true);
                    }
                    $t = $curr->selectByCourseSessionCode($selectByCourseUnit['courseSessionCode']);
                    // 0: {type: 1, des: "PPT-HTML"}
                    // 1: {type: 2, des: "讲义"}
                    // 2: {type: 3, des: "课前预习"}
                    // 3: {type: 4, des: "测一测"}
                    // 4: {type: 5, des: "玩一玩"}
                    // 5: {type: 6, des: "试一试"}
                    // 6: {type: 9, des: "知识点"}
                    // 7: {type: 10, des: "名人名言"}
                    // 8: {type: 11, des: "录播课"}
                    // 9: {type: 13, des: "教辅"}
                    // 10: {type: 14, des: "备课"}
                    // 11: {type: 15, des: "课程内容"}
                    // 12: {type: 16, des: "课后拓展"}
                    // 13: {type: 18, des: "素养目标"}
                    $ts = $t['data'];
                    foreach ($ts as $kk ){
                        switch ($kk['resourceType']) {
                            case '1':// PPT-HTML
                                if(!isset($kk['content'])){
                                    continue;
                                }
                                $filename = $kk['content']['fileName'];
                                $name = $kk['content']['fileUrl'];
                                if(!is_file($sessionName . '/' . $filename)){
                                    $curl->download($name,$sessionName . '/' . $filename);
                                }
                                break;
                            case '2':
                                break;
                            case '3':
                                break;
                            case '4':
                                break;
                            case '5':
                                break;
                            case '6':
                                break;
                            case '9':
                                break;
                            case '10':
                                break;
                            case '11':
                                break;
                            case '13':
                                break;
                            case '14':
                                break;
                            case '15':
                                break;
                            case '16':
                                break;
                            case '18':
                                break;
                            default:
                                break;
                        }
                        // break;
                    }
                }
            }
            // break;
        }
        // dump($course);
    }
    public function __call($method,$args)
    {
        dump('没有'.$method);
    }
}