IMMREX7
<?php
namespace App\Http\Controllers\Student;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use Session;
use DB;
use Carbon\Carbon;
class ViewOnlyController extends StudentController {
public function markDetails($id){
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$exam = \App\MarkExamType::where('idType', $id)->orderBy('idType')->first();
$type = \App\MarkExams::where('marks_exam.idType', '=', $id)->first();
$result = \App\ExamSheet::join('subjects', 'exam_marksheet.idSubject', '=', 'subjects.idSubject')->where('exam_marksheet.idStudent',$student->idStudent)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->get();
$examByPerformance = \App\ExamSheet::join('marks_exam_type', 'exam_marksheet.idExam', '=', 'marks_exam_type.idType')->select(DB::raw('SUM(total) as marks'),'name')->where('exam_marksheet.idStudent',$student->idStudent)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->groupBy('idExam')->get();
$top = \App\ExamSheet::select(DB::raw('SUM(total) as total'),'idStudent as id')->whereNotNull('exam_marksheet.total')->where('exam_marksheet.idClass',$student->idClass)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->groupBy('idStudent')->orderBy('total','DESC')->first();
$lowest = \App\ExamSheet::select(DB::raw('SUM(total) as total'),'idStudent as id')->where('exam_marksheet.idClass',$student->idClass)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->groupBy('idStudent')->orderBy('total','ASC')->first();
$topper = \App\ExamSheet::join('subjects', 'exam_marksheet.idSubject', '=', 'subjects.idSubject')->join('students', 'exam_marksheet.idStudent', '=', 'students.idStudent')->join('classes', 'students.idClass', '=', 'classes.idClass')
->join('sections', 'students.idSection', '=', 'sections.idSection')->where('exam_marksheet.idClass',$student->idClass)
->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('exam_marksheet.idStudent',$top->id)->where('idExam',$id)->first();
$topperResult = \App\ExamSheet::join('subjects', 'exam_marksheet.idSubject', '=', 'subjects.idSubject')->where('exam_marksheet.idStudent',$top->id)->where('exam_marksheet.idFinancialYear', $student->idFinancialYear)->where('idExam',$id)->get();
$mine = $this->prepareResult($result,$type);
$top = $this->prepareResult($topperResult,$type);
if($lowest->total == null) $lowestScore = 0 ;
else $lowestScore = $lowest->total;
return view('students.marks.exam_result', compact('examByPerformance','topper','mine','top','exam','lowestScore','student'));
}
public function markList(Request $request){
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$idExam = \App\MarkExams::where('idClass',$student->idClass)->where('idFinancialYear', $student->idFinancialYear)->whereRaw('idSection IS NULL OR idSection = ?', [$student->idSection])->groupBy('idType')->get()->pluck('idType')->toArray();
$data = \App\MarkExamType::whereIn('idType', $idExam)->orderBy('idType')->paginate()->items();
return view('students.marks.view_marklist', compact('data'));
}
private function prepareResult($result,$type){
$totalMarks = json_decode($type->marks,true);
$gradesRange = json_decode($type->grades,true);
$resultArr = array();
$overMinelTotal = 0;
$overTotal = 0;
foreach($result as $marks){
$temp = array(
"subject" => $marks->subjectName,
"full_marks" => 0,
"status" => $marks->attendance,
"theory" => $marks->marks,
"practical" => $marks->pratical,
"total" => $marks->marks + $marks->pratical,
"grade" => $marks->grade,
"percentage" => ""
);
$overMinelTotal = $overMinelTotal + $temp["total"];
foreach($totalMarks as $total){
if($total["id"] == $marks->idSubject)
{
if($total["pratical"] == "nil")
{
$temp["full_marks"] = $total["theory"];
$temp["practical"] = "NA";
}
else
$temp["full_marks"] = $total["theory"] + $total["pratical"];
$overTotal = $overTotal + $temp["full_marks"];
if($temp["full_marks"] != 0 )
{
$temp["percentage"] = ($temp["total"] / $temp["full_marks"]) * 100;
$temp["percentage"] = number_format((float)$temp["percentage"], 2, '.', '');
}
}
}
if($marks->marks != null){
foreach($gradesRange as $range){
$total = $temp["total"];
if($range["from"] <= $total && $total <= $range["to"] ){
$temp["grade"] = $range["name"];
}
}
}else{
foreach($gradesRange as $range){
$total = $temp["total"];
if($temp["grade"] == $range["name"] ){
$temp["total"] = "";
$temp["full_marks"] ="";
$temp["practical"] = "";
$temp["percentage"] = "";
$temp["percentage"] = "";
$temp["theory"] = "";
}
}
}
array_push($resultArr,$temp);
}
$grade = '';
foreach($gradesRange as $range){
if($overTotal > 0){
$total = ($overMinelTotal / $overTotal) * 100;
if($range["from"] <= $total && $total <= $range["to"] ){
$grade = $range["name"];
}
}
}
return array(
"result" => $resultArr,
"total" => $overMinelTotal,
"totalMarks" => $overTotal,
"grade" => $grade,
);
}
public function viewTimetable(Request $request) {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$periods = \App\Period::where('idSchool', '=', $student->idSchool)
->where('idClass', '=', $student->idClass)
->where('idSection', '=', $student->idSection)->get();
return view('students.viewtimetable', compact('classes', 'periods'));
}
public function viewLiveClass(Request $request){
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
if ($request->ajax()) {
$liveClass = DB::table('video_confernce')->join('classes', 'video_confernce.idClass', '=', 'classes.idClass')
->where('idFinancialYear',getFinancialYear())->where('video_confernce.idSchool','=',$student->idSchool)
->whereRaw('idSection IS NULL AND video_confernce.idClass = ?', [$student->idClass])
->orWhereRaw('idSection = ? AND video_confernce.idClass = ?', [$student->idSection,$student->idClass]);
$search = $request->input('search.value');
$start = $request->input('start');
$length = $request->input('length');
$totalFiltered = 0;
$totalData = 0;
if (isset($search)) {
$filter = DB::table('video_confernce')->where('idFinancialYear',getFinancialYear())->where('title','LIKE',"%{$search}%")->orderBy('idConference',"DESC")->where('idSchool','=',$student->idSchool)
->whereRaw('idSection IS NULL AND idClass = ?', [$student->idClass])
->orWhereRaw('idSection = ? AND idClass = ?', [$student->idSection,$student->idClass])->count();
$liveClass = $liveClass->where('title','LIKE',"%{$search}%")->orderBy('idConference',"DESC")->skip($start)->take($length)->get();
$totalFiltered = $filter;
}else{
$liveClass = $liveClass->orderBy('idConference',"DESC")->skip($start)->take($length)->get();
$totalData = DB::table('video_confernce')->where('idFinancialYear',getFinancialYear())->where('idSchool','=',$student->idSchool)
->whereRaw('idSection IS NULL AND idClass = ?', [$student->idClass])
->orWhereRaw('idSection = ? AND idClass = ?', [$student->idSection,$student->idClass])->count();
$totalFiltered = $totalData;
}
$data = array();
$i = 1;
foreach($liveClass as $value){
$nestedData = array();
array_push($nestedData, $i++);
array_push($nestedData, $value->created_on);
array_push($nestedData, $value->title);
array_push($nestedData, $value->description);
array_push($nestedData, $value->className);
if (isset($value->idSection)) {
$section = \App\Section::where('idSection', '=', $value->idSection)->first();
array_push($nestedData, $section->sectionName);
}else array_push($nestedData, "All Section");
array_push($nestedData, strtoupper($value->type));
if ($value->isActive == "Y") {
array_push($nestedData,'<a href="https://online-login.online/student/init/video/class/'.base64_encode($value->idConference).'" class="btn btn-raised btn-info waves-effect btn-round">Start Class</a>');
}else if ($value->isActive == "N") {
array_push($nestedData,"Not Started Yet");
}else if ($value->isActive == "W") {
array_push($nestedData,"Ended");
}
if ($value->isActive == "W") {
array_push($nestedData, '<a href="https://www.youtube.com/embed/'.$value->videoKey.'" class="btn btn-raised btn-info waves-effect btn-round">Play</a>');
}else array_push($nestedData,"Not Available");
array_push($data, $nestedData);
}
$json_data = array(
"draw" => intval($request->input('draw')),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
return json_encode($json_data);
}else{
return view('students.videoconf');
}
}
public function startLiveClass($id){
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$liveClass = DB::table('video_confernce')->where('idConference',base64_decode($id))->first();
$key = $liveClass->videoKey;
return view('students.videoconf_start', compact('student','key','id','liveClass'));
}
public function viewCalender() {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$holidays = \App\Holiday::where('idSchool', '=', $student->idSchool)->where('idFinancialYear', '=', getFinancialYear())->get();
return view('students.viewholiday', compact('holidays'));
}
public function viewHomework(Request $request) {
$today_date = Carbon::today()->format('Y-m-d');
if ($request->has('fromDate') && $request->fromDate != null) {
$from_date = Carbon::createFromFormat('d-m-Y', $request->fromDate);
}
if ($request->has('toDate') && $request->toDate != null) {
$to_date = Carbon::createFromFormat('d-m-Y', $request->toDate);
}
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$class_homework = \App\Homework::where('idClass', '=', $student->idClass)
->whereNull('idSection')
->whereNull('idStudent');
$section_homework = \App\Homework::where('idSection', '=', $student->idSection)
->whereNull('idStudent');
$homeworks = \App\Homework::where('idStudent', '=', $student->idStudent)
->union($class_homework)
->union($section_homework)
->orderBy('idHomework', 'desc');
if ($request->toDate != null && $request->fromDate != null) {
$homeworks = $homeworks->whereBetween('created_at', [$from_date->format('Y-m-d') . " 00:00:00", $to_date->format('Y-m-d') . " 23:59:59"])->get();
} else if ($request->has('fromDate') && $request->fromDate != null) {
$homeworks = $homeworks->whereBetween('created_at', [$from_date->format('Y-m-d') . " 00:00:00", $today_date . " 23:59:59"])->get();
} else if ($request->has('toDate') && $request->toDate != null) {
$homeworks = $homeworks->whereDate('created_at', '<=', $to_date)->get();
} else {
$homeworks = $homeworks->get();
}
return view('students.homework', compact('homeworks'));
}
public function viewHomeworkDoc($id) {
$homework = \App\Homework::findOrFail($id);
$path = storage_path('app/public/schools/' . $homework->idSchool . '/homeworks/' . $homework->homeworkFile);
return response()->file($path);
}
public function viewPracticeSet(Request $request) {
$today_date = Carbon::today()->format('Y-m-d');
if ($request->has('fromDate') && $request->fromDate != null) {
$from_date = Carbon::createFromFormat('d-m-Y', $request->fromDate);
}
if ($request->has('toDate') && $request->toDate != null) {
$to_date = Carbon::createFromFormat('d-m-Y', $request->toDate);
}
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$psets = \App\PracticeSet::where('idSchool', '=', $student->idSchool)
->where('idFinancialYear', '=', getFinancialYear())
->where('idClass', '=', $student->idClass)
->where('idSection', '=', $student->idSection)
->whereOr('idStudent', '=', $student->idStudent)
->orderBy('idSet', 'desc');
if ($request->toDate != null && $request->fromDate != null) {
$psets = $psets->whereBetween('created_at', [$from_date->format('Y-m-d') . " 00:00:00", $to_date->format('Y-m-d') . " 23:59:59"])->get();
} else if ($request->has('fromDate') && $request->fromDate != null) {
$psets = $psets->whereBetween('created_at', [$from_date->format('Y-m-d') . " 00:00:00", $today_date . " 23:59:59"])->get();
} else if ($request->has('toDate') && $request->toDate != null) {
$psets = $psets->whereDate('created_at', '<=', $to_date)->get();
} else {
$psets = $psets->get();
}
return view('students.practiceset', compact('psets'));
}
public function viewDoc($id) {
$pset = \App\PracticeSet::findOrFail($id);
$path = storage_path('app/public/schools/' . $pset->idSchool . '/practiceset/' . $pset->practiceFile);
return response()->file($path);
}
public function viewNewsLetter() {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$newsletters = \App\NewsLetter::where('idSchool', '=', $student->idSchool)
->whereRaw('(idClass=? or idClass IS NULL)',[$student->idClass])
->where('idFinancialYear', '=', getFinancialYear())
->orderBy('idNewsletter', 'desc')->paginate(10);
return view('students.viewnewsletters', compact('newsletters'));
}
public function viewShortStories() {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$stories = \App\ShortStory::where('idSchool', '=', $student->idSchool)
->where('idFinancialYear', '=', getFinancialYear())
->orderBy('idStory', 'desc')->get();
return view('students.viewshstories', compact('stories'));
}
public function viewThoughts() {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$thoughts = \App\WeekThought::where('idSchool', '=', $student->idSchool)
->where('idFinancialYear', '=', getFinancialYear())
->orderBy('idThought', 'desc')->get();
return view('students.thoughts', compact('thoughts'));
}
public function viewNoticeboards(Request $request) {
$today_date = Carbon::today()->format('Y-m-d');
if ($request->has('fromDate') && $request->fromDate != null) {
$from_date = Carbon::createFromFormat('d-m-Y', $request->fromDate);
}
if ($request->has('toDate') && $request->toDate != null) {
$to_date = Carbon::createFromFormat('d-m-Y', $request->toDate);
}
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
/*$notices = \App\Noticeboard::where('idSchool', '=', $student->idSchool)
// ->where('idClass', '=', $student->idClass)
//->where('idSection', '=', $student->idSection)
->orwhereRaw(' ( idClass=? AND idSection IS NULL )',[$student->idClass])
->orWhereRaw(' ( idClass=? AND idSection=? )',[$student->idClass,$student->idSection])
//->whereOr('idStudent', '=', $student->idStudent)
->where('idFinancialYear', '=', $student->idFinancialYear)
->orderBy('idNoticeboard', 'desc');*/
$notices = \App\Noticeboard::where('idSchool', '=', $student->idSchool)
->where('idFinancialYear', '=', $student->idFinancialYear)
->where(function($q) use ($student){
$q->orWhereNull('idClass')
->orwhereRaw(' ( idClass=? AND idSection IS NULL )',[$student->idClass])
->orWhereRaw(' ( idClass=? AND idSection=? )',[$student->idClass,$student->idSection]);
});
if ($request->toDate != null && $request->fromDate != null) {
$notices = $notices->whereBetween('created_at', [$from_date->format('Y-m-d') . " 00:00:00", $to_date->format('Y-m-d') . " 23:59:59"])->get();
} else if ($request->has('fromDate') && $request->fromDate != null) {
$notices = $notices->whereBetween('created_at', [$from_date->format('Y-m-d') . " 00:00:00", $today_date . " 23:59:59"])->get();
} else if ($request->has('toDate') && $request->toDate != null) {
$notices = $notices->whereDate('created_at', '<=', $to_date)->get();
} else {
$notices = $notices->orderBy('idNoticeboard', 'desc')->get();
}
return view('students.noticeboard', compact('notices'));
}
public function viewNDoc($id) {
$notice = \App\Noticeboard::findOrFail($id);
$path = storage_path('app/public/schools/' . $notice->idSchool . '/noticeboard/' . $notice->noticeFile);
return response()->file($path);
}
public function viewPositiveNews() {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$positive_news = \App\PositiveNews::where('idSchool', '=', $student->idSchool)
->whereOr('idClass', '=', $student->idClass)
->orderBy('idNews', 'desc')->get();
return view('students.positive_news', compact('classes', 'positive_news'));
}
public function viewGallery() {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$folders = \App\GalleryFolder::where('idSchool', '=', $student->idSchool)->paginate();
return view('students.gallery', compact('folders', 'student'));
}
public function viewFullGallery($id) {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$folders = \App\GalleryFolder::where('idSchool', '=', $student->idSchool)->where('idFolder',$id)->paginate();
return view('students.gallery', compact('folders', 'student'));
}
public function viewAttendance(Request $request) {
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$school = \App\School::where('idSchool', '=', $student->idSchool)->first();
if($request->get('date') != ""){
$now = \Carbon\Carbon::parse($request->get('date'));
$month_name = $now->format('M');
$detail = \Carbon\Carbon::parse($request->get('date'));
}else{
$now = \Carbon\Carbon::now();
$month_name = $now->format('M');
$detail = today_date();
}
$month = \App\Month::where('monthName', 'like', '%' . $month_name . '%')->first();
return view('students.view_attendance', compact('student', 'school', 'month','detail'));
}
public function viewExam(){
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$exams = \App\ExamMcq::join('subjects','exam_mcq.idSubject','subjects.idSubject')
->select('exam_mcq.*','subjects.subjectName')
->where('exam_mcq.idClass', $student->idClass)
->orWhereRaw(' ( exam_mcq.idClass=? AND exam_mcq.idSection=? )',[$student->idClass,$student->idSection])
->where('exam_mcq.idSchool', $student->idSchool)->where('exam_mcq.idFinancialYear',Session::get('idFinancialYear'))->paginate(10);
return view('students.view_exam', compact('student', 'exams'));
}
public function startExam(Request $request){
$exams = \App\ExamMcq::where('idMcq',$request->id)->first();
$date = strtotime($exams->examDate);
$now =time();
if($date < $now) {
echo 'started';
}else echo 'not started';
}
public function viewQuestions($id){
$student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
$template = \App\ExamMcq::join('subjects','exam_mcq.idSubject','subjects.idSubject')->select('exam_mcq.*','subjects.subjectName')->findOrfail($id);
$paper = DB::table('exam_ques_types')->where('idExam',$id)->get();
$questions = ['' => '-- Select Questions --','mcq' => 'MCQ Questions','images_questions' => 'Image to Questions'
,'question_image' => 'Questions to Images','image_image' => 'Image to Image','math_type' => 'Math Type','short' => 'Short Question'
,'long' => 'Long Question','image_long' => 'Image for Long Question'] ;
$options = ['' => '-- Select Correct Option --','A' => 'Option A','B' => 'Option B','C' => 'Option C','D' => 'Option D'] ;
return view('students.view_questions', compact('student','template','paper','questions','options'));
}
public function viewResults(){
}
}
Copyright © 2021 -