delete: controller not incude on system
This commit is contained in:
parent
58ab368174
commit
e310054277
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Literacy;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class LiteracyAnswerController extends Controller
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
@ -1,495 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Literacy;
|
|
||||||
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Models\NodeJS\Project;
|
|
||||||
use App\Models\Literacy\LiteracyTopic;
|
|
||||||
use App\Models\Literacy\LiteracyTopic_detail;
|
|
||||||
use App\Models\Literacy\LiteracyUserEnroll;
|
|
||||||
use App\Models\Literacy\LiteracyMaterial;
|
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Yajra\DataTables\Facades\DataTables;
|
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Facades\File;
|
|
||||||
use Symfony\Component\Process\Process;
|
|
||||||
use Illuminate\Support\Facades\Session;
|
|
||||||
|
|
||||||
class LiteracyController extends Controller{
|
|
||||||
|
|
||||||
function materials()
|
|
||||||
{
|
|
||||||
$materials = LiteracyMaterial::all();
|
|
||||||
return view('literacy.student.materials.index', [
|
|
||||||
'materials' => $materials,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function submit_score_baru(Request $request)
|
|
||||||
{
|
|
||||||
$userId = Auth::id(); // Get the authenticated user's ID
|
|
||||||
$score = $request->input('score');
|
|
||||||
$topicsId = $request->input('topics_id');
|
|
||||||
|
|
||||||
// Insert the new score into user_submissions using the Query Builder
|
|
||||||
DB::table('react_user_submits')->insert([
|
|
||||||
'user_id' => $userId,
|
|
||||||
'score' => $score,
|
|
||||||
'topics_id' => $topicsId,
|
|
||||||
'flag' => $score > 50 ? true : false,
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now()
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Retrieve or create an entry in user_rank for specific user and topic
|
|
||||||
$currentRank = DB::table('react_student_rank')
|
|
||||||
->where('id_user', $userId)
|
|
||||||
->where('topics_id', $topicsId)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (!$currentRank) {
|
|
||||||
// If no entry exists, create one
|
|
||||||
DB::table('react_student_rank')->insert([
|
|
||||||
'id_user' => $userId,
|
|
||||||
'best_score' => $score,
|
|
||||||
'topics_id' => $topicsId,
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now()
|
|
||||||
]);
|
|
||||||
} else if ($score > $currentRank->best_score) {
|
|
||||||
// Update the best_score if the new score is higher
|
|
||||||
DB::table('react_student_rank')
|
|
||||||
->where('id_user', $userId)
|
|
||||||
->where('topics_id', $topicsId)
|
|
||||||
->update([
|
|
||||||
'best_score' => $score,
|
|
||||||
'updated_at' => now()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($score > 50 ) {
|
|
||||||
$exists = DB::table('react_student_enroll')
|
|
||||||
->where('id_users', Auth::user()->id)
|
|
||||||
->where('php_topics_detail_id', $topicsId)
|
|
||||||
->exists();
|
|
||||||
|
|
||||||
if (!$exists) {
|
|
||||||
// Record does not exist, so insert a new one
|
|
||||||
$flags = $results[0]->flag ?? 0;
|
|
||||||
if ( $flags == 0) {
|
|
||||||
DB::table('react_student_enroll')->insert([
|
|
||||||
'id_users' => Auth::user()->id,
|
|
||||||
'php_topics_detail_id' => $topicsId,
|
|
||||||
'created_at' => now()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return response()->json(['message' => 'Score submitted successfully']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(){
|
|
||||||
|
|
||||||
$actual = "";
|
|
||||||
$topics = LiteracyTopic::all();
|
|
||||||
$topics_detail = LiteracyTopic_detail::all();
|
|
||||||
$topicsCount = count($topics);
|
|
||||||
$topicsDetailCount = count($topics_detail);
|
|
||||||
|
|
||||||
$idUser = Auth::user()->id;
|
|
||||||
$roleTeacher = DB::select("select role from users where id = $idUser");
|
|
||||||
|
|
||||||
// Retrieve all completed topics based on role
|
|
||||||
if ($roleTeacher[0]->role == "student") {
|
|
||||||
$completedTopics = DB::table('react_student_enroll')
|
|
||||||
->join('users', 'react_student_enroll.id_users', '=', 'users.id')
|
|
||||||
->join('react_topics_detail', 'react_student_enroll.php_topics_detail_id', '=', 'react_topics_detail.id')
|
|
||||||
->select('react_student_enroll.*', 'users.name as user_name', 'react_topics_detail.*')
|
|
||||||
->where('react_student_enroll.id_users', $idUser)
|
|
||||||
->get();
|
|
||||||
} else if ($roleTeacher[0]->role == "teacher") {
|
|
||||||
$completedTopics = DB::table('react_student_enroll')
|
|
||||||
->join('users', 'react_student_enroll.id_users', '=', 'users.id')
|
|
||||||
->join('react_topics_detail', 'react_student_enroll.php_topics_detail_id', '=', 'react_topics_detail.id')
|
|
||||||
->select('react_student_enroll.*', 'users.name as user_name', 'react_topics_detail.*')
|
|
||||||
->get();
|
|
||||||
} else {
|
|
||||||
; // Return an empty collection if role is neither student nor teacher
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Calculate progress for each user
|
|
||||||
$progress = [];
|
|
||||||
foreach ($completedTopics as $enrollment) {
|
|
||||||
$userId = $enrollment->id_users;
|
|
||||||
if (!isset($progress[$userId])) {
|
|
||||||
$userCompletedCount = DB::table('react_student_enroll')
|
|
||||||
->where('id_users', $userId)
|
|
||||||
->count();
|
|
||||||
|
|
||||||
$progress[$userId] = [
|
|
||||||
'name' => $enrollment->user_name,
|
|
||||||
'percent' => round(($userCompletedCount / $topicsDetailCount) * 100, 2)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('literacy.student.material.index',[
|
|
||||||
'result_up' => $actual,
|
|
||||||
'topics' => $topics_detail,
|
|
||||||
'topicsCount' => $topicsDetailCount,
|
|
||||||
'completedTopics' => $completedTopics,
|
|
||||||
'role' => $roleTeacher[0] ? $roleTeacher[0]->role : '',
|
|
||||||
'progress' => $progress
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function php_material_detail(){
|
|
||||||
$phpid = isset($_GET['phpid']) ? (int)$_GET['phpid'] : '';
|
|
||||||
$start = isset($_GET['start']) ? (int)$_GET['start'] : '';
|
|
||||||
$output = isset($_GET['output']) ? $_GET['output'] : '';
|
|
||||||
|
|
||||||
$results = DB::select("select * from react_topics_detail where id_topics =$start and id ='$phpid' ");
|
|
||||||
|
|
||||||
foreach($results as $r){
|
|
||||||
|
|
||||||
if( $start == $r->id_topics){
|
|
||||||
if(empty($r->file_name)){
|
|
||||||
$contain = $r->description;
|
|
||||||
$pdf_reader = 0;
|
|
||||||
}else{
|
|
||||||
$contain = $r->file_name;
|
|
||||||
$pdf_reader = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$html_start = $this->html_persyaratan($contain,$pdf_reader);
|
|
||||||
|
|
||||||
}else{
|
|
||||||
$html_start = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// dd($html_start);
|
|
||||||
|
|
||||||
// $listTask = DB::select("select aa.*, us.name from react_user_submits aa join users us on aa.userid = us.id where php_id = $phpid and php_id_topic = $start ");
|
|
||||||
|
|
||||||
$idUser = Auth::user()->id;
|
|
||||||
$roleTeacher = DB::select("select role from users where id = $idUser");
|
|
||||||
|
|
||||||
$topics = LiteracyTopic::all();
|
|
||||||
|
|
||||||
|
|
||||||
$detail = LiteracyTopic::findorfail($start);
|
|
||||||
|
|
||||||
$topicsCount = count($topics);
|
|
||||||
$detailCount = ($topicsCount/$topicsCount)*10;
|
|
||||||
|
|
||||||
$topics_detail = LiteracyTopic_detail::all();
|
|
||||||
|
|
||||||
// Check if the record already exists
|
|
||||||
$exists = DB::table('react_student_enroll')
|
|
||||||
->where('id_users', Auth::user()->id)
|
|
||||||
->where('php_topics_detail_id', $phpid)
|
|
||||||
->exists();
|
|
||||||
|
|
||||||
if (!$exists) {
|
|
||||||
// Record does not exist, so insert a new one
|
|
||||||
$flags = $results[0]->flag ?? 0;
|
|
||||||
if ( $flags == 0) {
|
|
||||||
DB::table('react_student_enroll')->insert([
|
|
||||||
'id_users' => Auth::user()->id,
|
|
||||||
'php_topics_detail_id' => $phpid,
|
|
||||||
'created_at' => now()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$completedTopics = LiteracyUserEnroll::where('id_users', Auth::user()->id)->distinct('php_topics_detail_id')->count();
|
|
||||||
|
|
||||||
$progress = ( $completedTopics/ count($topics_detail) ) * 100;
|
|
||||||
|
|
||||||
|
|
||||||
return view('literacy.student.material.topics_detail',[
|
|
||||||
'row' => $detail,
|
|
||||||
'topics' => $topics,
|
|
||||||
'phpid' => $phpid,
|
|
||||||
'html_start' => $html_start,
|
|
||||||
'pdf_reader' => $pdf_reader ,
|
|
||||||
'topicsCount'=> $topicsCount ,
|
|
||||||
'detailCount'=> $detailCount ,
|
|
||||||
'output' => $output,
|
|
||||||
'flag' => $results[0] ? $results[0]->flag : 0,
|
|
||||||
'listTask' => [],
|
|
||||||
'role' => $roleTeacher[0] ? $roleTeacher[0]->role : '',
|
|
||||||
'progress' => round($progress, 0)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
function html_start(){
|
|
||||||
$html ="<div style='text-align:center;font-size:18px'><em>Modul kelas Belajar Pengembangan Aplikasi Android Intermediate dalam bentuk cetak (buku) maupun elektronik sudah didaftarkan ke Dirjen HKI, Kemenkumham RI. Segala bentuk penggandaan dan atau komersialisasi, sebagian atau seluruh bagian, baik cetak maupun elektronik terhadap modul kelas <em>Belajar Pengembangan Aplikasi Android Intermediate</em> tanpa izin formal tertulis kepada pemilik hak cipta akan diproses melalui jalur hukum.</em></div>";
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
function html_persyaratan($desc,$pdf_reader){
|
|
||||||
$html = $desc;
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function upload(Request $request)
|
|
||||||
{
|
|
||||||
if ($request->hasFile('upload')) {
|
|
||||||
$originName = $request->file('upload')->getClientOriginalName();
|
|
||||||
$fileName = pathinfo($originName, PATHINFO_FILENAME);
|
|
||||||
$extension = $request->file('upload')->getClientOriginalExtension();
|
|
||||||
$fileName = $fileName . '_' . time() . '.' . $extension;
|
|
||||||
|
|
||||||
$request->file('upload')->move(public_path('media'), $fileName);
|
|
||||||
|
|
||||||
$url = asset('media/' . $fileName);
|
|
||||||
|
|
||||||
return response()->json(['fileName' => $fileName, 'uploaded' => 1, 'url' => $url]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function send_task(){
|
|
||||||
$phpid = isset($_GET['phpid']) ? $_GET['phpid'] : '';
|
|
||||||
$task = isset($_GET['task']) ? $_GET['task'] : '';
|
|
||||||
$output = isset($_GET['output']) ? $_GET['output'] : '';
|
|
||||||
|
|
||||||
$task_db = DB::table('php_task')
|
|
||||||
->where('id_topics', $phpid)
|
|
||||||
->where('id', $task)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if($task_db->id == $task){
|
|
||||||
$html_start = $this->html_task();
|
|
||||||
}else{
|
|
||||||
$html_start = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
$pdf_reader = 0;
|
|
||||||
$topics = Topic::all();
|
|
||||||
$detail = Topic::findorfail($phpid);
|
|
||||||
$topicsCount = count($topics);
|
|
||||||
$persen = ($topicsCount/$topicsCount)*10;
|
|
||||||
session(['params' => $persen]);
|
|
||||||
|
|
||||||
return view('php.student.material.topics_detail',[
|
|
||||||
'row' => $detail,
|
|
||||||
'topics' => $topics,
|
|
||||||
'phpid' => $phpid,
|
|
||||||
'html_start' => $html_start,
|
|
||||||
'pdf_reader' => $pdf_reader ,
|
|
||||||
'detailCount'=> $persen,
|
|
||||||
'output' => $output,
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
|
||||||
function html_task(){
|
|
||||||
return view('php.student.task.form_submission_task',[]);
|
|
||||||
}
|
|
||||||
function php_admin(){
|
|
||||||
return view('php.admin.material.upload_materi',[]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function task_submission(Request $request){
|
|
||||||
$phpid = (int)$request->get('phpid');
|
|
||||||
$start = (int)$request->get('start');
|
|
||||||
|
|
||||||
$this->validate($request, [
|
|
||||||
'file' => 'required',
|
|
||||||
|
|
||||||
]);
|
|
||||||
|
|
||||||
// menyimpan data file yang diupload ke variabel $file
|
|
||||||
$file = $request->file('file');
|
|
||||||
|
|
||||||
$file_name = Auth::user()->name.'_'.$file->getClientOriginalName();
|
|
||||||
|
|
||||||
Storage::disk('public')->makeDirectory('private/'.Auth::user()->name);
|
|
||||||
Storage::disk('public')->put('/private/'.Auth::user()->name.'/'.$file_name,File::get($file));
|
|
||||||
$userName = Auth::user()->name;
|
|
||||||
Session::put('user_name', $userName);
|
|
||||||
$user_name = Session::get('user_name');
|
|
||||||
$name = Session::put('ori_file_name', $file_name);
|
|
||||||
|
|
||||||
$path = storage_path("app/private/{$userName}/{$file_name}");
|
|
||||||
Session::put('path', $path);
|
|
||||||
|
|
||||||
$val = session('key');
|
|
||||||
// DB::select("TRUNCATE TABLE php_user_submits");
|
|
||||||
// DB::insert("insert into php_user_submits(userid) values ('$val')");
|
|
||||||
|
|
||||||
$phpunitExecutable = base_path('vendor/bin/phpunit');
|
|
||||||
|
|
||||||
Storage::disk('local')->put('/private/testingunit/testingunit.php',File::get($file));
|
|
||||||
if($start == 43){
|
|
||||||
$unitTest = base_path('tests/CreateDatabase.php');
|
|
||||||
}else if($start == 42){
|
|
||||||
$unitTest = base_path('tests/CheckConnection.php');
|
|
||||||
}else if($start == 44){
|
|
||||||
$unitTest = base_path('tests/CreateTable.php');
|
|
||||||
}else if($start == 45){
|
|
||||||
$unitTest = base_path('tests/CreateTableGuru.php');
|
|
||||||
}else if($start == 46){
|
|
||||||
$unitTest = base_path('tests/CheckInsert.php');
|
|
||||||
}else if($start == 47){
|
|
||||||
$unitTest = base_path('tests/CheckInsertGuru.php');
|
|
||||||
}else if($start == 48){
|
|
||||||
$unitTest = base_path('tests/CheckInsertHtml.php');
|
|
||||||
}else if($start == 49){
|
|
||||||
$unitTest = base_path('tests/CheckInsertHtmlGuru.php');
|
|
||||||
}else if($start == 50){
|
|
||||||
$unitTest = base_path('tests/CheckSelectHtml.php');
|
|
||||||
}else if($start == 51){
|
|
||||||
$unitTest = base_path('tests/CheckSelectHtmlGuru.php');
|
|
||||||
}else if($start == 52){
|
|
||||||
$unitTest = base_path('tests/CheckUpdateHtml.php');
|
|
||||||
}else if($start == 53){
|
|
||||||
$unitTest = base_path('tests/CheckUpdateHtmlGuru.php');
|
|
||||||
}else if($start == 54){
|
|
||||||
$unitTest = base_path('tests/CheckDeleteHtml.php');
|
|
||||||
}else if($start == 55){
|
|
||||||
$unitTest = base_path('tests/CheckDeleteHtmlGuru.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run PHPUnit tests using exec
|
|
||||||
$output = [];
|
|
||||||
$returnVar = 0;
|
|
||||||
|
|
||||||
exec("$phpunitExecutable $unitTest", $output, $returnVar);
|
|
||||||
Storage::deleteDirectory('/private/testingunit');
|
|
||||||
|
|
||||||
// Output the results
|
|
||||||
$outputString = "<br>PHPUnit Output: <br>";
|
|
||||||
$outputString .= implode("<br>", $output) . "<br>";
|
|
||||||
$outputString .= "Return Code: $returnVar<br>";
|
|
||||||
// dd($output);
|
|
||||||
|
|
||||||
$idUser = Auth::user()->id;
|
|
||||||
$pathuser = 'storage/private/'.$userName.'/'.$file_name.'';
|
|
||||||
|
|
||||||
$flag = $returnVar == 0 ? 'true' : 'false';
|
|
||||||
|
|
||||||
DB::insert("INSERT INTO php_user_submits(userid, path, flag, php_id, php_id_topic) values ('$idUser', '$pathuser', '$flag', $phpid, $start)");
|
|
||||||
|
|
||||||
// php_user_submits
|
|
||||||
return redirect('/php/detail-topics?phpid='.$phpid.'&start='.$start.'&output='.$outputString.'');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function unittesting2(){
|
|
||||||
$val = session('key');
|
|
||||||
DB::select("TRUNCATE TABLE php_user_submits");
|
|
||||||
DB::insert("insert into php_user_submits(userid) values ('$val')");
|
|
||||||
|
|
||||||
$path_test = base_path("phpunit.xml");
|
|
||||||
$path = base_path("vendor\bin\phpunit -c $path_test");
|
|
||||||
$output = shell_exec($path);
|
|
||||||
|
|
||||||
// echo dd($output);
|
|
||||||
// echo json_encode($output);
|
|
||||||
$string = htmlentities($output);
|
|
||||||
$string = str_replace("\n", ' ', $string);
|
|
||||||
|
|
||||||
$pattern = '/PHPUnit\s+(\d+\.\d+\.\d+).*Runtime:\s+PHP\s+(\d+\.\d+\.\d+).*Time:\s+(\d+:\d+\.\d+),\s+Memory:\s+(\d+\.\d+)\s+MB\s+OK\s+\((\d+)\stests,\s+(\d+)\sassertions\)/';
|
|
||||||
|
|
||||||
if (preg_match($pattern, $string, $matches)) {
|
|
||||||
$phpUnitVersion = $matches[1];
|
|
||||||
$phpVersion = $matches[2];
|
|
||||||
$executionTime = $matches[3];
|
|
||||||
$memoryUsage = $matches[4];
|
|
||||||
$numTests = $matches[5];
|
|
||||||
$numAssertions = $matches[6];
|
|
||||||
|
|
||||||
// Output the extracted information
|
|
||||||
echo "PHPUnit version: $phpUnitVersion <br />";
|
|
||||||
echo "PHP version: $phpVersion <br />";
|
|
||||||
echo "Execution time: $executionTime <br />";
|
|
||||||
echo "Memory usage: $memoryUsage MB <br />";
|
|
||||||
echo "Number of tests: $numTests <br />";
|
|
||||||
echo "Number of assertions: $numAssertions <br />";
|
|
||||||
|
|
||||||
$ok_position = strpos($string, 'OK');
|
|
||||||
if ($ok_position !== false) {
|
|
||||||
$ok_part = substr($string, $ok_position);
|
|
||||||
echo "Tests Run : ". $ok_part;
|
|
||||||
}
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
$string = json_encode($output);
|
|
||||||
$text = str_replace("\n", ' ', $output);
|
|
||||||
// Define patterns to extract relevant information
|
|
||||||
$pattern_phpunit_version = '/PHPUnit\s+(\d+\.\d+\.\d+)/';
|
|
||||||
$pattern_php_runtime = '/Runtime:\s+PHP\s+([\d.]+)/';
|
|
||||||
$pattern_configuration = '/Configuration:\s+(.+)/';
|
|
||||||
$pattern_failure_count = '/There was (\d+) failure/';
|
|
||||||
$pattern_failure_test_case = '/Failed asserting that \'(.*?)\' contains \'(.*?)\'./';
|
|
||||||
$pattern_failure_location = '/(C:\\\\.*?\\.php):(\d+)/';
|
|
||||||
|
|
||||||
// Perform matching
|
|
||||||
preg_match($pattern_phpunit_version, $text, $matches_phpunit_version);
|
|
||||||
preg_match($pattern_php_runtime, $text, $matches_php_runtime);
|
|
||||||
preg_match($pattern_configuration, $text, $matches_configuration);
|
|
||||||
preg_match($pattern_failure_count, $text, $matches_failure_count);
|
|
||||||
preg_match($pattern_failure_test_case, $text, $matches_failure_test_case);
|
|
||||||
preg_match($pattern_failure_location, $text, $matches_failure_location);
|
|
||||||
|
|
||||||
// Extracted information
|
|
||||||
$phpunit_version = isset($matches_phpunit_version[1]) ? $matches_phpunit_version[1] : "Not found";
|
|
||||||
$php_runtime = isset($matches_php_runtime[1]) ? $matches_php_runtime[1] : "Not found";
|
|
||||||
$configuration_path = isset($matches_configuration[1]) ? $matches_configuration[1] : "Not found";
|
|
||||||
$num_failures = isset($matches_failure_count[1]) ? $matches_failure_count[1] : "Not found";
|
|
||||||
$failed_assertion = isset($matches_failure_test_case[1]) ? htmlspecialchars($matches_failure_test_case[1]) : "Not found";
|
|
||||||
$expected_content = isset($matches_failure_test_case[2]) ? htmlspecialchars($matches_failure_test_case[2]) : "Not found";
|
|
||||||
$failure_location = isset($matches_failure_location[1]) ? $matches_failure_location[1] : "Not found";
|
|
||||||
$failure_line = isset($matches_failure_location[2]) ? $matches_failure_location[2] : "Not found";
|
|
||||||
|
|
||||||
// Output extracted information
|
|
||||||
echo "PHPUnit version: $phpunit_version <br >";
|
|
||||||
echo "PHP Runtime: $php_runtime <br >";
|
|
||||||
echo "Configuration path: $configuration_path <br >";
|
|
||||||
echo "Number of failures: $num_failures <br >";
|
|
||||||
echo "Failed assertion: $failed_assertion <br >";
|
|
||||||
echo "Expected content: $expected_content <br >";
|
|
||||||
echo "Failure location: $failure_location <br >";
|
|
||||||
echo "Failure line: $failure_line <br >";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function unittesting(){
|
|
||||||
$namaFile = 'febri syawaldi_CreateDB.php';
|
|
||||||
$phpunitExecutable = base_path('vendor/bin/phpunit');
|
|
||||||
$unitTest = base_path('tests/FileReadTest.php');
|
|
||||||
|
|
||||||
// Run PHPUnit tests using exec
|
|
||||||
$output = [];
|
|
||||||
$returnVar = 0;
|
|
||||||
exec("$phpunitExecutable $unitTest", $output, $returnVar);
|
|
||||||
|
|
||||||
|
|
||||||
// Output the results
|
|
||||||
// echo "PHPUnit Output: <br>";
|
|
||||||
// echo implode("<br>", $output) . "<br>";
|
|
||||||
// echo "Return Code: $returnVar<br>";
|
|
||||||
|
|
||||||
return response()->json($output);
|
|
||||||
}
|
|
||||||
|
|
||||||
function session_progress(){
|
|
||||||
// Cek Ada Data Tidak, Enrollement User
|
|
||||||
// Jika Tidak Insert
|
|
||||||
|
|
||||||
session(['params' => $_POST['params']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Literacy;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use App\Models\Literacy\LiteracyTopic;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Yajra\DataTables\Facades\DataTables;
|
|
||||||
use App\Models\PHP\Topic;
|
|
||||||
use App\Models\Literacy\LiteracyTopic_detail;
|
|
||||||
use Illuminate\Support\Facades\Redirect;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
|
|
||||||
class LiteracyGuruController extends Controller{
|
|
||||||
|
|
||||||
// public function topics()
|
|
||||||
// {
|
|
||||||
// $topics = LiteracyTopic::all();
|
|
||||||
// return view('literacy.teacher.materials.index', compact('materials'));
|
|
||||||
// }
|
|
||||||
function topics(){
|
|
||||||
$topics = LiteracyTopic::all();
|
|
||||||
return view('literacy.teacher.topics',[
|
|
||||||
'topics' => $topics,
|
|
||||||
]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_topics( Request $request, $id ){
|
|
||||||
$detail = LiteracyTopic::findorfail($id);
|
|
||||||
$results = DB::select('SELECT * FROM react_topics_detail WHERE id_topics = ?', [$id]);
|
|
||||||
return view('literacy.teacher.topics_detail',[
|
|
||||||
'results' => $results,
|
|
||||||
'detail' => $detail->title,
|
|
||||||
'id' => $id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function simpan( Request $request){
|
|
||||||
$validatedData = $request->validate([
|
|
||||||
'title' => 'required|string|max:255',
|
|
||||||
'caption' => 'required|string|max:255',
|
|
||||||
'editor' => 'required|string',
|
|
||||||
'id' => 'required|int|max:11',
|
|
||||||
'materials' => 'required|file|max:10240', // Example: max 10MB
|
|
||||||
]);
|
|
||||||
// Periksa apakah file yang diunggah bukan PDF
|
|
||||||
if ($request->file('materials')->getClientOriginalExtension() !== 'pdf') {
|
|
||||||
return redirect()->back()->with('error', 'Materi harus berupa file PDF.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$originName = $request->file('materials')->getClientOriginalName();
|
|
||||||
$fileName = pathinfo($originName, PATHINFO_FILENAME);
|
|
||||||
$extension = $request->file('materials')->getClientOriginalExtension();
|
|
||||||
$fileName = $fileName . '_' . time() . '.' . $extension;
|
|
||||||
$new_name = str_replace(" ",'_',$fileName);
|
|
||||||
|
|
||||||
$path = $request->file('materials')->move(public_path('react/document/A1_BASIC_PHP'), $new_name);
|
|
||||||
LiteracyTopic_detail::create([
|
|
||||||
'title' => $validatedData['title'],
|
|
||||||
'id_topics' => $validatedData['id'],
|
|
||||||
'controller' => $validatedData['caption'],
|
|
||||||
'description' => $validatedData['editor'],
|
|
||||||
'folder_path' => $path, // Save the path to the uploaded file
|
|
||||||
'file_name' => $new_name,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$id = $validatedData['id'];
|
|
||||||
return Redirect::to("/literacy/teacher/topics/add/$id")->with('message', 'Data Berhasil Diinputkan');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,250 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Literacy\Student;
|
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use App\Models\Literacy\LiteracySubmitUser;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
class LiteracyLogicalController extends Controller
|
|
||||||
{
|
|
||||||
// function upload file
|
|
||||||
public function uploadFile(Request $request)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$request->validate([
|
|
||||||
'uploadFile' => 'required|file|max:1024',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($request->hasFile('uploadFile')) {
|
|
||||||
$uploadedFile = $request->file('uploadFile');
|
|
||||||
$userName = Auth::user()->name;
|
|
||||||
$fileName = $uploadedFile->getClientOriginalName();
|
|
||||||
$uploadedFile->storeAs('private/' . $userName . '/React', $fileName);
|
|
||||||
|
|
||||||
$materiType = $this->getMateriType($fileName);
|
|
||||||
$comparisonResult = $this->compareFile($materiType, $uploadedFile);
|
|
||||||
|
|
||||||
// Menyimpan data ke database dengan status berdasarkan hasil perbandingan
|
|
||||||
try {
|
|
||||||
$submitUser = new LiteracySubmitUser();
|
|
||||||
$submitUser->id_user = Auth::id();
|
|
||||||
$submitUser->nama_user = $userName;
|
|
||||||
$submitUser->materi = 'React - ' . $fileName;
|
|
||||||
$submitUser->nilai = $comparisonResult === 'Congratulations, your answer is correct.' ? 100 : 0;
|
|
||||||
$submitUser->status = $comparisonResult === 'Congratulations, your answer is correct.' ? 'True' : 'False';
|
|
||||||
$submitUser->save();
|
|
||||||
} catch (\Exception $dbException) {
|
|
||||||
// Log error and return response
|
|
||||||
Log::error('Database save failed: ' . $dbException->getMessage());
|
|
||||||
return response()->json([
|
|
||||||
'error' => 'Database save failed.',
|
|
||||||
'message' => 'There was an error saving your result to the database.',
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'uploaded' => true,
|
|
||||||
'fileName' => $fileName,
|
|
||||||
'message' => 'File uploaded successfully.',
|
|
||||||
'comparisonResult' => $comparisonResult,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return response()->json([
|
|
||||||
'error' => 'File upload failed.',
|
|
||||||
'message' => 'The upload file field is required.',
|
|
||||||
], 400);
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error('File upload failed: ' . $e->getMessage());
|
|
||||||
return response()->json([
|
|
||||||
'error' => 'File upload failed.',
|
|
||||||
'message' => $e->getMessage(),
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// function menentukan tipe materi
|
|
||||||
private function getMateriType($fileName)
|
|
||||||
{
|
|
||||||
if (strpos($fileName, 'Hello.js') !== false) {
|
|
||||||
return 'hello';
|
|
||||||
} elseif (strpos($fileName, 'Form.js') !== false) {
|
|
||||||
return 'form';
|
|
||||||
} elseif (strpos($fileName, 'Counter.js') !== false) {
|
|
||||||
return 'counter';
|
|
||||||
} elseif (strpos($fileName, 'FormStyle.js') !== false) {
|
|
||||||
return 'formStyle';
|
|
||||||
} elseif (strpos($fileName, 'Navbar.js') !== false) {
|
|
||||||
return 'navbar';
|
|
||||||
} else {
|
|
||||||
return 'unknown';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// function mengecek jawaban
|
|
||||||
private function compareFile($materiType, $uploadedFile)
|
|
||||||
{
|
|
||||||
switch ($materiType) {
|
|
||||||
case 'hello':
|
|
||||||
return $this->jawabanHello($uploadedFile);
|
|
||||||
case 'form':
|
|
||||||
return $this->jawabanForm($uploadedFile);
|
|
||||||
case 'counter':
|
|
||||||
return $this->jawabanCounter($uploadedFile);
|
|
||||||
case 'formStyle':
|
|
||||||
return $this->jawabanFormStyle($uploadedFile);
|
|
||||||
case 'navbar':
|
|
||||||
return $this->jawabanNavbar($uploadedFile);
|
|
||||||
default:
|
|
||||||
throw new \Exception('Harus Sesuai Materi');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// function mencari perbedaan
|
|
||||||
private function getDifference($uploadedContent, $answerKeyContent)
|
|
||||||
{
|
|
||||||
// Membandingkan baris per baris untuk menemukan perbedaan
|
|
||||||
$uploadedLines = explode("\n", $uploadedContent);
|
|
||||||
$answerKeyLines = explode("\n", $answerKeyContent);
|
|
||||||
|
|
||||||
$diffLines = [];
|
|
||||||
|
|
||||||
foreach ($uploadedLines as $lineNumber => $line) {
|
|
||||||
if (!isset($answerKeyLines[$lineNumber]) || $line !== $answerKeyLines[$lineNumber]) {
|
|
||||||
$diffLines[] = [
|
|
||||||
'line_number' => $lineNumber + 1,
|
|
||||||
'uploaded_line' => $line,
|
|
||||||
'answer_key_line' => isset($answerKeyLines[$lineNumber]) ? $answerKeyLines[$lineNumber] : '',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$diffMessage = '';
|
|
||||||
foreach ($diffLines as $diffLine) {
|
|
||||||
$diffMessage .= "Line{$diffLine['line_number']}: \n";
|
|
||||||
$diffMessage .= "Your Answer: {$diffLine['uploaded_line']} \n";
|
|
||||||
$diffMessage .= "Should: {$diffLine['answer_key_line']} \n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $diffMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
// function hello
|
|
||||||
private function jawabanHello($uploadedFile)
|
|
||||||
{
|
|
||||||
$uploadedContent = file_get_contents($uploadedFile->getRealPath());
|
|
||||||
|
|
||||||
$answerKeyPath = storage_path('app/private/_answerKey_/React/Hello.js');
|
|
||||||
|
|
||||||
if (!file_exists($answerKeyPath)) {
|
|
||||||
throw new \Exception('Answer key file not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$answerKeyContent = file_get_contents($answerKeyPath);
|
|
||||||
|
|
||||||
if ($uploadedContent === $answerKeyContent) {
|
|
||||||
return 'Congratulations, your answer is correct.';
|
|
||||||
} else {
|
|
||||||
$diff = $this->getDifference($uploadedContent, $answerKeyContent);
|
|
||||||
$errorMessage = 'Your answer is still wrong. Fix it again, OK? Differences in ' . $diff;
|
|
||||||
return $errorMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// function form
|
|
||||||
private function jawabanForm($uploadedFile)
|
|
||||||
{
|
|
||||||
$uploadedContent = file_get_contents($uploadedFile->getRealPath());
|
|
||||||
|
|
||||||
$answerKeyPath = storage_path('app/private/_answerKey_/React/Form.js');
|
|
||||||
|
|
||||||
if (!file_exists($answerKeyPath)) {
|
|
||||||
throw new \Exception('Answer key file not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$answerKeyContent = file_get_contents($answerKeyPath);
|
|
||||||
|
|
||||||
if ($uploadedContent === $answerKeyContent) {
|
|
||||||
return 'Congratulations, your answer is correct.';
|
|
||||||
} else {
|
|
||||||
$diff = $this->getDifference($uploadedContent, $answerKeyContent);
|
|
||||||
$errorMessage = 'Your answer is still wrong. Fix it again, OK? Differences in ' . $diff;
|
|
||||||
return $errorMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// function counter
|
|
||||||
private function jawabanCounter($uploadedFile)
|
|
||||||
{
|
|
||||||
$uploadedContent = file_get_contents($uploadedFile->getRealPath());
|
|
||||||
|
|
||||||
$answerKeyPath = storage_path('app/private/_answerKey_/React/Counter.js');
|
|
||||||
|
|
||||||
if (!file_exists($answerKeyPath)) {
|
|
||||||
throw new \Exception('Answer key file not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$answerKeyContent = file_get_contents($answerKeyPath);
|
|
||||||
|
|
||||||
if ($uploadedContent === $answerKeyContent) {
|
|
||||||
return 'Congratulations, your answer is correct.';
|
|
||||||
} else {
|
|
||||||
$diff = $this->getDifference($uploadedContent, $answerKeyContent);
|
|
||||||
$errorMessage = 'Your answer is still wrong. Fix it again, OK? Differences in ' . $diff;
|
|
||||||
return $errorMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function jawabanFormStyle($uploadedFile)
|
|
||||||
{
|
|
||||||
$uploadedContent = file_get_contents($uploadedFile->getRealPath());
|
|
||||||
|
|
||||||
$answerKeyPath = storage_path('app/private/_answerKey_/React/FormStyle.js');
|
|
||||||
|
|
||||||
if (!file_exists($answerKeyPath)) {
|
|
||||||
throw new \Exception('Answer key file not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$answerKeyContent = file_get_contents($answerKeyPath);
|
|
||||||
|
|
||||||
if ($uploadedContent === $answerKeyContent) {
|
|
||||||
return 'Congratulations, your answer is correct.';
|
|
||||||
} else {
|
|
||||||
$diff = $this->getDifference($uploadedContent, $answerKeyContent);
|
|
||||||
$errorMessage = 'Your answer is still wrong. Fix it again, OK? Differences in ' . $diff;
|
|
||||||
return $errorMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function jawabanNavbar($uploadedFile)
|
|
||||||
{
|
|
||||||
$uploadedContent = file_get_contents($uploadedFile->getRealPath());
|
|
||||||
|
|
||||||
$answerKeyPath = storage_path('app/private/_answerKey_/React/Navbar.js');
|
|
||||||
|
|
||||||
if (!file_exists($answerKeyPath)) {
|
|
||||||
throw new \Exception('Answer key file not found.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$answerKeyContent = file_get_contents($answerKeyPath);
|
|
||||||
|
|
||||||
if ($uploadedContent === $answerKeyContent) {
|
|
||||||
return 'Congratulations, your answer is correct.';
|
|
||||||
} else {
|
|
||||||
$diff = $this->getDifference($uploadedContent, $answerKeyContent);
|
|
||||||
$errorMessage = 'Your answer is still wrong. Fix it again, OK? Differences in ' . $diff;
|
|
||||||
return $errorMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function getComparisonResults($userId)
|
|
||||||
{
|
|
||||||
$results = LiteracySubmitUser::where('id_user', $userId)->get();
|
|
||||||
|
|
||||||
return response()->json($results);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user