new feature

master
Lìu Văn Quyết 2 years ago
parent aed29143fe
commit f35a5b2472
  1. 142
      src/app/Http/Controllers/LoseRootController.php
  2. 163
      src/composer.lock
  3. 1
      src/resources/views/includes/footer.blade.php
  4. 12
      src/resources/views/includes/head.blade.php
  5. 17
      src/resources/views/includes/header.blade.php
  6. 38
      src/resources/views/layouts/default.blade.php
  7. 7
      src/resources/views/pages/contact.blade.php
  8. 22
      src/resources/views/pages/home.blade.php
  9. 9
      src/routes/web.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;
}
}

163
src/composer.lock generated

@ -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",

@ -0,0 +1 @@
<div id="copyright text-right">© Copyright 2023 quyetlv </div>

@ -0,0 +1,12 @@
<meta charset="utf-8">
<meta name="description" content="">
<meta name="Saquib" content="Blade">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>Checkout our layout</title>
<!-- load bootstrap from a cdn -->
{{-- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/3.0.3/css/bootstrap-combined.min.css"> --}}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

@ -0,0 +1,17 @@
{{-- <div class="navbar">
<div class="navbar-inner">
<a id="logo" href="/">Single Malt</a>
<ul class="nav">
<li><a href="/">Home</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</div>
</div> --}}

@ -0,0 +1,38 @@
<!doctype html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="container">
<header class="row">
@include('includes.header')
</header>
<div id="main" class="content">
@yield('content')
</div>
<footer class="row">
{{-- @include('includes.footer') --}}
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
</body>
</html>

@ -0,0 +1,7 @@
@extends('layouts.default')
@section('content')
i am the contact page
@stop

@ -0,0 +1,22 @@
@extends('layouts.default')
@section('content')
<div class="container">
<form action="{{ route('loseroot.file.read') }}" method="post" enctype="multipart/form-data">
@csrf
<div class="row pt-5">
<div class="col">
<div class="mb-3">
{{-- <label for="formFile" class="form-label">Default file input example</label> --}}
<input class="form-control" type="file" id="formFile" name="file_handle">
</div>
</div>
<div class="col">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
@stop

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\LoseRootController;
use Illuminate\Support\Facades\Route;
/*
@ -13,6 +14,10 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::get('/', function () {
return view('welcome');
// Route::get('/', function () {
// return view('welcome');
// });
Route::prefix('lose-root')->group(function () {
Route::get('/handle-file', [LoseRootController::class,'index_file'])->name('loseroot.file.index');
Route::post('/read-file', [LoseRootController::class,'read_file'])->name('loseroot.file.read');
});

Loading…
Cancel
Save