diff --git a/src/app/Http/Controllers/LoseRootController.php b/src/app/Http/Controllers/LoseRootController.php index b1baefd..8161def 100644 --- a/src/app/Http/Controllers/LoseRootController.php +++ b/src/app/Http/Controllers/LoseRootController.php @@ -3,11 +3,149 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Maatwebsite\Excel\Facades\Excel; +use PhpOffice\PhpSpreadsheet\IOFactory; class LoseRootController extends Controller { // - public function index_file(){ - return view("a"); + private $_row_unit = 1; + private $_curriculum_six_id = 666; + private $_curriculum_seven_id = 777; + private $_curriculum_eight_id = 888; + private $_curriculum_nine_id = 999; + public function index_file() + { + return view("pages.home"); } + public function read_file(Request $request) + { + $file = $request->file('file_handle'); + // ĐỌC DỮ LIỆU TỪ FILE EXCEL + $data_class_6 = $this->read_excel($file, "class_6"); // LỚP 6 + // $data_class_7 = $this->read_excel($file, "class_7"); // LỚP 7 + // $data_class_8 = $this->read_excel($file, "class_8"); // LỚP 8 + // $data_class_9 = $this->read_excel($file, "class_9"); // LỚP 9 + + // TẠO LỘ TRÌNH LỚP + $trip_loseroot = $this->create_trip_loseroot($data_class_6); + // DỮ LIỆU ĐỂ ADD VÀO GIÁO TRÌNH (KEY = UNIT_ID) + $generate = $this->generate_curriculum($data_class_6, $this->_curriculum_six_id); + + dd($generate); + } + public function create_trip_loseroot($data) + { + if (!empty($data)) { + + } + } + public function generate_curriculum($data, $curriculum_id) + { + $data_by_skill = []; + $data_unit_topic = []; + // sắp sếp lại các bài vào unit + if (!empty($data)) { + // gán từng unit thành skill + foreach ($data as $num_week => $raw_data) { + foreach ($raw_data as $key_raw => $value_raw) { + $data_by_skill[$key_raw][$num_week] = $value_raw; + } + } + } + if (!empty($data_by_skill)) { + // gán các unit gồm các topic + $week_unit_topic = []; + foreach ($data_by_skill as $skill => $skill_raw) { + foreach ($skill_raw as $week_num => $raw) { + array_walk($raw, function ($v, $k) use (&$week_unit_topic) { + $topic_id = (int) $v; + $week_unit_topic[$k][] = $topic_id; + }); + } + } + // lọc các topic cho vào bài + if (!empty($week_unit_topic)) { + foreach ($week_unit_topic as $week_number => $week_unit) { + $data_unit_topic[$week_number] = array_unique($week_unit); + } + } + } + return $data_unit_topic; + } + public function create_curriculum() + { + $data_curriculum = [ + 'id' => $curriculum_id, + 'name' => null, + 'image_intro' => $curriculum_name, + 'author' => "Sunday English", + 'goal' => null, + 'description' => null, + 'category_id' => $curriculum_name, + 'status' => $curriculum_name, + 'created_at' => $curriculum_name, + 'created_by' => $curriculum_name, + 'updated_at' => $curriculum_name, + 'deleted' => $curriculum_name, + 'json_data_curriculum' => $curriculum_name, + 'updated_by' => $curriculum_name, + 'type' => $curriculum_name, + 'grade_id' => $curriculum_name, + 'curriculum_avatar' => $curriculum_name, + 'type_grade' => $curriculum_name, + 'allow_learning_free' => $curriculum_name, + 'curriculum_rootlessness' => $curriculum_name, + ]; + } + public function read_excel($file, $sheet_name) + { + $spreadsheet = IOFactory::load($file); + $sheet = $spreadsheet->getSheetByName($sheet_name); + $sheet = $spreadsheet->getActiveSheet(); + + // Lấy tất cả dữ liệu từ sheet và chuyển đổi thành mảng + $data = []; + foreach ($sheet->getRowIterator() as $row) { + $rowData = []; + foreach ($row->getCellIterator() as $cell) { + $value = $cell->getCalculatedValue(); + $rowData[] = trim($value); + + } + if (!empty($rowData[0])) { + $data[] = $rowData; + } + } + $list_week_format = []; + $row_unit = $data[$this->_row_unit]; + $list_unit = []; + if (!empty($row_unit)) { + foreach ($row_unit as $row_u) { + if (is_numeric($row_u)) { + $list_unit[] = $row_u; + } + } + } + if (!empty($data)) { + foreach ($data as $d_unit) { + if (is_numeric($d_unit[0])) { + $week = $d_unit[0]; + $skill = $d_unit[1]; + unset($d_unit[0], $d_unit[1], $d_unit[2]); + $unit_id = 0; + $unit_topic = []; + foreach ($d_unit as $final_unit) { + if (!empty($final_unit)) { + $unit_id += 1; + $unit_topic[$unit_id] = $final_unit; + } + } + $list_week_format[$week][$skill] = $unit_topic; + } + } + } + return $list_week_format; + } + } diff --git a/src/composer.lock b/src/composer.lock index 22444a4..50a44b2 100644 --- a/src/composer.lock +++ b/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6ee4d4ca68d92432687da1c588234379", + "content-hash": "8a2df282297b0fd146f440cab283b05f", "packages": [ { "name": "brick/math", @@ -61,6 +61,87 @@ ], "time": "2023-01-15T23:15:59+00:00" }, + { + "name": "composer/semver", + "version": "3.4.0", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/35e8d0af4486141bc745f23a29cc2091eb624a32", + "reference": "35e8d0af4486141bc745f23a29cc2091eb624a32", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "ircs://irc.libera.chat:6697/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.4.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2023-08-31T09:50:34+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.2", @@ -1879,6 +1960,86 @@ ], "time": "2023-10-17T14:13:20+00:00" }, + { + "name": "maatwebsite/excel", + "version": "3.1.50", + "source": { + "type": "git", + "url": "https://github.com/SpartnerNL/Laravel-Excel.git", + "reference": "d79e66391aa306983bb7e234503f5605c3e33348" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/d79e66391aa306983bb7e234503f5605c3e33348", + "reference": "d79e66391aa306983bb7e234503f5605c3e33348", + "shasum": "" + }, + "require": { + "composer/semver": "^3.3", + "ext-json": "*", + "illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0", + "php": "^7.0||^8.0", + "phpoffice/phpspreadsheet": "^1.18", + "psr/simple-cache": "^1.0||^2.0||^3.0" + }, + "require-dev": { + "orchestra/testbench": "^6.0||^7.0||^8.0", + "predis/predis": "^1.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Maatwebsite\\Excel\\ExcelServiceProvider" + ], + "aliases": { + "Excel": "Maatwebsite\\Excel\\Facades\\Excel" + } + } + }, + "autoload": { + "psr-4": { + "Maatwebsite\\Excel\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Patrick Brouwers", + "email": "patrick@spartner.nl" + } + ], + "description": "Supercharged Excel exports and imports in Laravel", + "keywords": [ + "PHPExcel", + "batch", + "csv", + "excel", + "export", + "import", + "laravel", + "php", + "phpspreadsheet" + ], + "support": { + "issues": "https://github.com/SpartnerNL/Laravel-Excel/issues", + "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.50" + }, + "funding": [ + { + "url": "https://laravel-excel.com/commercial-support", + "type": "custom" + }, + { + "url": "https://github.com/patrickbrouwers", + "type": "github" + } + ], + "time": "2023-11-06T11:29:48+00:00" + }, { "name": "maennchen/zipstream-php", "version": "3.1.0", diff --git a/src/resources/views/includes/footer.blade.php b/src/resources/views/includes/footer.blade.php new file mode 100644 index 0000000..fb80270 --- /dev/null +++ b/src/resources/views/includes/footer.blade.php @@ -0,0 +1 @@ +