104 lines
4.3 KiB
PHP
104 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Http\Requests\LambdaRequest;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Log;
|
|
use App\Models\User;
|
|
|
|
class UpdateScores extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'scores:update';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
|
|
|
|
public function handle()
|
|
{
|
|
$contacts = DB::table('lms_courses_completion')->select("contact_id")->where('created_date', '>=', date("Y-m-d H:i:s", strtotime("-15 min")) )->get();
|
|
$conts = [];
|
|
foreach($contacts as $c) {
|
|
$conts[] = $c->contact_id;
|
|
}
|
|
$contacts = array_unique($conts);
|
|
|
|
if(sizeof($contacts) > 0) {
|
|
$courses = LambdaRequest::getrequest('lms', 'courses/get_all', ['status' => 'active'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
|
foreach($courses->data->items as $course) {
|
|
unset($course->subscribed_users);
|
|
$lessons = LambdaRequest::getrequest('lms', 'lessons/list', ['id'=>$course->id, 'partition' => 'rapport-crestroad'], env('LAMBDA_ACCESS_TOKEN', 'default_value'));
|
|
$articles = [];
|
|
$quizs = [];
|
|
foreach($lessons->data->lessons as $lesson){
|
|
foreach($lesson->articles as $article){
|
|
if($article->type == 'article') {
|
|
$articles[] = $article->entity_id;
|
|
}
|
|
if($article->type == 'quiz') {
|
|
$quizs[] = $article->entity_id;
|
|
}
|
|
}
|
|
}
|
|
$course->articles = $articles;
|
|
$course->quizs = $quizs;
|
|
$allcourses[$course->id] = $course;
|
|
}
|
|
|
|
foreach($contacts as $contact) {
|
|
$arts = DB::table('lms_courses_completion')->select("course_id", "article_id")->where('contact_id', $contact)->get();
|
|
$articles = [];
|
|
foreach($arts as $art) {
|
|
$articles[] = $art->article_id;
|
|
}
|
|
|
|
if(count($articles) > 0 ) {
|
|
foreach($allcourses as $course) {
|
|
$completed_articles = array_intersect($course->articles, $articles);
|
|
$counts[$course->id]['articles'] = count($completed_articles);
|
|
|
|
$completed_articles = array_intersect($course->quizs, $articles);
|
|
$counts[$course->id]['quiz'] = count($completed_articles);
|
|
}
|
|
$data = ['english_article_count' => isset($counts['1692237077-7be9a215-dae1-4af0-9350-d336ea54176f']) && isset($counts['1692237077-7be9a215-dae1-4af0-9350-d336ea54176f']['articles']) ? $counts['1692237077-7be9a215-dae1-4af0-9350-d336ea54176f']['articles'] : 0,
|
|
'english_quiz_count' => isset($counts['1692237077-7be9a215-dae1-4af0-9350-d336ea54176f']) && isset($counts['1692237077-7be9a215-dae1-4af0-9350-d336ea54176f']['quiz']) ? $counts['1692237077-7be9a215-dae1-4af0-9350-d336ea54176f']['quiz'] : 0,
|
|
|
|
'hindi_article_count' => isset($counts['1692263655-25749640-2bfb-476c-9116-cbc9aa958335']) && isset($counts['1692263655-25749640-2bfb-476c-9116-cbc9aa958335']['articles']) ? $counts['1692263655-25749640-2bfb-476c-9116-cbc9aa958335']['articles'] : 0,
|
|
'hindi_quiz_count' => isset($counts['1692263655-25749640-2bfb-476c-9116-cbc9aa958335']) && isset($counts['1692263655-25749640-2bfb-476c-9116-cbc9aa958335']['quiz']) ? $counts['1692263655-25749640-2bfb-476c-9116-cbc9aa958335']['quiz'] : 0
|
|
];
|
|
DB::table("lms_users")->where('contact_id', $contact)->update($data);
|
|
//print_r($counts);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|