|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|