'updated_backend_queries'

parent 71980c9f
This diff is collapsed.
<?php
namespace App\Http\Controllers;
use App\Models\Activity;
use App\Models\Feedback;
use App\Models\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CommonController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
public function getActivityCount() {
return response()->json( ['activityCount'=> Activity::count()] );
}
public function getCommentCount() {
return response()->json( ['commentCount'=> Feedback::count()] );
}
public function login(Request $request) {
$user = Admin::Where('username',$request->email)
->Where('password',$request->password)->first();
return response()->json( ['user'=> $user],200 );
}
public function getActivityChatData() {
$counts = DB::table('activities')
->select(DB::raw('count(student_id) as count, type'))
->groupBy('type')
->get();
return response()->json( ['counts' => $counts] );
}
}
...@@ -4,30 +4,62 @@ namespace App\Http\Controllers; ...@@ -4,30 +4,62 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Quiz; use App\Models\Quiz;
use App\Models\QuizRecord;
use App\Models\ResultSummary;
use App\Models\ActivityMaster;
use App\Models\User;
use DB;
use Log;
class QuizController extends Controller { class QuizController extends Controller {
/** /**
* Get all students * Get all students
*/ */
public function get_all() { public function get_all() {
return response()->json( Quiz::get() ); try {
$quiz_records = QuizRecord::get() ;
return response()->json([ 'quiz_records' => $quiz_records], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
} }
/** public function getActivityMaster() {
* Get student by id try {
*/ $data = ActivityMaster::get() ;
public function get_by_id( $id ) { return response()->json( $data, 200);
return response()->json( Quiz::find($id) ); } catch ( \Exception $e ) {
return response()->json( ['message' => $e->getmessage()], 500 );
}
} }
/** public function getActivityMasterById($id) {
* Get all students count try {
*/ $data = ActivityMaster::Where('activity_id',$id)->first();
public function get_count() { return response()->json( $data, 200);
return response()->json( Quiz::count() ); } catch ( \Exception $e ) {
return response()->json( ['message' => $e->getmessage()], 500 );
}
} }
// /**
// * Get all students count
// */
// public function get_count() {
// try {
// $quiz_counts = QuizRecord::count() ;
// return response()->json([ 'quiz_counts' => $quiz_counts], 200);
// } catch ( \Exception $e ) {
// Log::error( $e );
// return response()->json( ['message' => $e->getmessage()], 500 );
// }
// }
/** /**
* Get student by gender * Get student by gender
*/ */
...@@ -47,17 +79,42 @@ class QuizController extends Controller { ...@@ -47,17 +79,42 @@ class QuizController extends Controller {
public function get_players_count() { public function get_players_count() {
$players_count = 30; try {
return response()->json( $players_count ); $players_count = User::count() ;
return response()->json([ 'players_count' => $players_count], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
} }
public function get_quiz_count() { public function get_quiz_count() {
$quiz_count = 20;
return response()->json( $quiz_count ); try {
$quiz_count = User::count() ;
return response()->json([ 'quiz_count' => $quiz_count], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
} }
public function get_avg_time() { public function get_avg_time() {
$players_count = 45; try {
$QuizRecord = QuizRecord::get();
$QuizRecordCount = QuizRecord::count();
$duration = 0;
$avg_time = 0;
foreach ($QuizRecord as $item) {
$duration += $item->duration;
}
$avg_time = $duration/$QuizRecordCount;
return response()->json([ 'avg_time' => $avg_time], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
return response()->json( $players_count ); return response()->json( $players_count );
} }
...@@ -87,7 +144,46 @@ class QuizController extends Controller { ...@@ -87,7 +144,46 @@ class QuizController extends Controller {
return response()->json( $difficult_quiz ); return response()->json( $difficult_quiz );
} }
public function getCompletedStudents($id) {
$count = DB::table('tbl_student')
->leftJoin('activities', 'tbl_student.student_id', '=', 'activities.student_id')
->select(DB::raw('count(activities.student_id)*100/count(tbl_student.student_id) as count'))
->Where('activities.activity_id',$id)
->first();
return response()->json( ['count'=>$count] );
}
public function getRankings($id) {
$ranking = DB::table('tbl_result_summary')
->select(DB::raw('count(student_id) as count, grade'))
->groupBy('grade')
->Where('activity_id',$id)
->get();
return response()->json( $ranking );
}
public function getLowStudents($id) {
$students = ResultSummary::with('info')
->Where('marks' ,'<=', '30')
->Where('activity_id',$id)
->get();
return response()->json( ['students' => $students] );
}
public function getDiffQuiz( $id ) {
try {
$quiz = DB::table('tbl_question')
->join('tbl_result', function($join)
{
$join->on('tbl_question.question_id', '=', 'tbl_result.question_id');
$join->on('tbl_result.user_answer', '!=', 'tbl_result.right_answer');
})
->select('tbl_question.*')
->Where('activity_id', $id)->distinct()->get();
return response()->json([ 'quiz' => $quiz], 200);
} catch ( \Exception $e ) {
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
} }
...@@ -4,6 +4,10 @@ namespace App\Http\Controllers; ...@@ -4,6 +4,10 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Students; use App\Models\Students;
use App\Models\Prediction;
use App\Models\ResultSummary;
use Illuminate\Support\Facades\DB;
class StudentsController extends Controller { class StudentsController extends Controller {
...@@ -11,14 +15,20 @@ class StudentsController extends Controller { ...@@ -11,14 +15,20 @@ class StudentsController extends Controller {
* Get all students * Get all students
*/ */
public function get_all() { public function get_all() {
return response()->json( Students::get() ); try {
$students = Students::all();
return response()->json([ 'students' => $students], 200);
} catch ( \Exception $e ) {
//Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
} }
/** /**
* Get student by id * Get student by id
*/ */
public function get_by_id( $id ) { public function get_by_id( $id ) {
return response()->json( Students::find($id) ); return response()->json( Students::where('student_id' , $id)->first());
} }
/** /**
...@@ -45,28 +55,38 @@ class StudentsController extends Controller { ...@@ -45,28 +55,38 @@ class StudentsController extends Controller {
return response()->json( $Students ); return response()->json( $Students );
} }
public function get_attendance() { public function get_attendance($sId) {
$attendance = 84; $counts = DB::select(DB::raw('select count(attendanceid) as count from attendance where MONTH(date) = month(CURRENT_DATE) and student_id = '.$sId));
return response()->json( $attendance ); return response()->json($counts);
} }
public function get_works() { public function get_works($id) {
$works = 20; $works = ResultSummary::Where('student_id',$id)->orderByDesc('added_date')->first();
return response()->json( $works ); return response()->json( $works );
} }
public function get_last_performamce() { public function get_last_performamce($sId) {
$performance = [ // $performance = [
0 => [ // 0 => [
'subject' => 'English', // 'subject' => 'English',
'marks' => 80 // 'marks' => 80
], // ],
1 => [ // 1 => [
'subject' => 'ICT', // 'subject' => 'ICT',
'marks' => 90 // 'marks' => 90
], // ],
]; // ];
$performance = DB::table('activities')
->select(DB::raw('count(marks) as marks, type as subject'))
->groupBy('type')
->Where('student_id',$sId)
->get();
return response()->json( $performance ); return response()->json( $performance );
} }
public function getPredictedData( $id ) {
return response()->json( ['result' => Prediction::where('student_id' , $id)->get()]);
}
} }
...@@ -19,7 +19,7 @@ class CorsMiddleware ...@@ -19,7 +19,7 @@ class CorsMiddleware
$headers = [ $headers = [
'Access-Control-Allow-Methods' => 'POST,GET,OPTIONS,PUT,DELETE', 'Access-Control-Allow-Methods' => 'POST,GET,OPTIONS,PUT,DELETE',
'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization', 'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization',
]; ];
if ($request->getMethod() == "OPTIONS"){ if ($request->getMethod() == "OPTIONS"){
//The client-side application can set only headers allowed in Access-Control-Allow-Headers //The client-side application can set only headers allowed in Access-Control-Allow-Headers
return response()->json('OK',200,$headers); return response()->json('OK',200,$headers);
...@@ -31,4 +31,4 @@ class CorsMiddleware ...@@ -31,4 +31,4 @@ class CorsMiddleware
return $response; return $response;
} }
} }
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Activity extends Model {
protected $table = 'activities';
protected $fillable = [
'activity_id',
'student_id',
'level',
'type',
'content',
'date_time',
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ActivityMaster extends Model {
protected $table = 'activity_master';
protected $fillable = [
'activity_id',
'activity_title',
'subject',
'no_of_students',
'avg_time',
'no_of_quiz'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Admin extends Model {
protected $table = 'admin';
protected $fillable = [
'id',
'username',
'password'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Feedback extends Model {
protected $table = 'feedback';
protected $fillable = [
'name',
'parent_id',
'subject',
'feedback',
'date',
'time',
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class History extends Model {
protected $table = 'history';
protected $fillable = [
'username',
'eid',
'score',
'score',
'level',
'correct',
'wrong',
'date',
'timestamp',
'status',
'score_updated'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Prediction extends Model {
protected $table = 'student_prediction';
protected $fillable = [
'student_id', 'actual', 'predicted'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class QuizRecord extends Model {
protected $table = 'quizrecord';
protected $fillable = [
'recid',
'rollno',
'duration',
'endtime',
'date',
'url'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ResultSummary extends Model {
protected $table = 'tbl_result_summary';
protected $fillable = [
'summary_id',
'student_id',
'marks',
'activity_id',
'grade',
'subject',
];
public $timestamps = false;
public function info()
{
return $this->belongsTo('App\Models\Students', 'student_id', 'student_id');
}
}
...@@ -6,15 +6,19 @@ use Illuminate\Database\Eloquent\Model; ...@@ -6,15 +6,19 @@ use Illuminate\Database\Eloquent\Model;
class Students extends Model { class Students extends Model {
protected $table = 'user'; protected $table = 'tbl_student';
protected $fillable = [ protected $fillable = [
'name', 'student_id',
'rollno', 'first_name',
'branch', 'last_name',
'gender', 'email',
'username', 'username',
'phno',
'password', 'password',
'contact',
'grade',
'is_active',
'added_date',
'updated_date',
]; ];
public $timestamps = false; public $timestamps = false;
} }
...@@ -19,7 +19,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac ...@@ -19,7 +19,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
* @var array * @var array
*/ */
protected $fillable = [ protected $fillable = [
'name', 'email', 'name', 'email', 'rollno', 'branch','gender','phno','username'
]; ];
/** /**
......
...@@ -73,12 +73,10 @@ $app->configure('app'); ...@@ -73,12 +73,10 @@ $app->configure('app');
*/ */
$app->middleware([ $app->middleware([
App\Http\Middleware\CorsPolicy::class, App\Http\Middleware\CorsMiddleware::class,
App\Http\Middleware\HttpsProtocol::class
]); ]);
// $app->routeMiddleware([
// 'auth' => App\Http\Middleware\Authenticate::class,
// ]);
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
...@@ -18,26 +18,41 @@ $router->get('/', function () use ($router) { ...@@ -18,26 +18,41 @@ $router->get('/', function () use ($router) {
}); });
$router->group(['prefix' => 'api' ], function () use ($router) { $router->group(['prefix' => 'api' ], function () use ($router) {
$router->post('login', 'CommonController@login');
//Students Master //Students Master
$router->group(['prefix' => 'students'], function () use ($router) { $router->group(['prefix' => 'students'], function () use ($router) {
$router->get('all', 'StudentsController@get_all'); $router->get('all', 'StudentsController@get_all');
$router->get('view/{id}', 'StudentsController@get_by_id'); $router->get('view/{id}', 'StudentsController@get_by_id');
$router->get('count', 'StudentsController@get_count'); $router->get('count', 'StudentsController@get_count');
$router->get('get-attendance', 'StudentsController@get_attendance'); $router->get('get-attendance/{sId}', 'StudentsController@get_attendance');
$router->get('get-works', 'StudentsController@get_works'); $router->get('get-works/{id}', 'StudentsController@get_works');
$router->get('get-last-performance', 'StudentsController@get_last_performamce'); $router->get('get-last-performance/{sId}', 'StudentsController@get_last_performamce');
$router->post('search', 'StudentsController@search'); $router->post('search', 'StudentsController@search');
$router->get('prediction/{id}', 'StudentsController@getPredictedData');
}); });
$router->group(['prefix' => 'quiz'], function () use ($router) { $router->group(['prefix' => 'quiz'], function () use ($router) {
$router->get('all', 'QuizController@get_all'); $router->get('all', 'QuizController@get_all');
$router->get('view/{id}', 'QuizController@get_by_id'); $router->get('view/{id}', 'QuizController@get_by_id');
$router->get('count', 'QuizController@get_count');
$router->get('get-players-count', 'QuizController@get_players_count'); $router->get('get-players-count', 'QuizController@get_players_count');
$router->get('get-quiz-count', 'QuizController@get_quiz_count'); $router->get('get-quiz-count', 'QuizController@get_quiz_count');
$router->get('get-avg-time', 'QuizController@get_avg_time'); $router->get('get-avg-time', 'QuizController@get_avg_time');
$router->get('help-needed-students', 'QuizController@help_needed_students'); $router->get('help-needed-students', 'QuizController@help_needed_students');
$router->get('difficult-quiz', 'QuizController@difficult_quiz'); $router->get('difficult-quiz', 'QuizController@difficult_quiz');
$router->get('activity-master', 'QuizController@getActivityMaster');
$router->get('activity-master/{id}', 'QuizController@getActivityMasterById');
$router->get('completed/{id}', 'QuizController@getCompletedStudents');
$router->get('rankings/{id}', 'QuizController@getRankings');
$router->get('lowStudents/{id}', 'QuizController@getLowStudents');
$router->get('diffquiz/{id}', 'QuizController@getDiffQuiz');
});
$router->group(['prefix' => 'common'], function () use ($router) {
$router->get('activities/count', 'CommonController@getActivityCount');
$router->get('comments/count', 'CommonController@getCommentCount');
$router->get('activity/chart', 'CommonController@getActivityChatData');
}); });
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment