IMMREX7
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Carbon\Carbon;
use \App\Http\SendNotificationApi;
class ThoughtUpdate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:thought';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send thought notification to the school';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$school = DB::table('schools')->select('idSchool')->where('isThoughtAutomatic',1)->get()->pluck('idSchool')->toArray();
$isJobRun = DB::table('automatic_jobs')->where('job_name',"thoughts")->orderBy('id','DESC')->first();
if( $isJobRun == null){
$stories = DB::table('weekly_thoughts')->where('idSchool',163)->first();
if($stories != null){
DB::table('automatic_jobs')->insert([
'job_name' => "thoughts",
'job_ref' => $stories->idThought,
'created_at' => Carbon::now()->format('Y-m-d H:i:s')
]);
foreach($school as $key => $value){
$data = json_decode(json_encode($stories), true);
unset($data['idThought']);
$data['idSchool'] = $value;
$data['idFinancialYear'] = DB::table('financial_years')->where('idSchool',$value)->orderBy('idFinancialYear','DESC')->first()->idFinancialYear;
$data['publishDate'] = Carbon::now()->format('Y-m-d');
DB::table('weekly_thoughts')->insert($data);
}
$stds_birday = \App\AdmEntry::select('idStudent')->whereIn('idSchool',$school)
->where('isActive','Y')
->groupBy('idStudent')
->get()->pluck('idStudent')->toArray();
$reg_fids = DB::table('students')
->join('parents', 'students.father_mobile', '=', 'parents.mobile')
->select('parents.idFirebase')
->whereIn('students.idStudent', $stds_birday)
->get()->pluck('idFirebase')->toArray();
SendNotificationApi::sendNotification($reg_fids,"Thoughts : ".$stories->thought);
$reg_ids = DB::table('students')
->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
->select('parents.idFirebase')
->whereIn('students.idStudent', $stds_birday)
->get()->pluck('idFirebase')->toArray();
SendNotificationApi::sendNotification($reg_ids, "Thoughts : ".$stories->thought);
}
}else{
$stories = DB::table('weekly_thoughts')->where('idThought','>',$isJobRun->job_ref)->where('idSchool',163)->first();
if($stories != null){
DB::table('automatic_jobs')->insert([
'job_name' => "thoughts",
'job_ref' => $stories->idThought,
'created_at' => Carbon::now()->format('Y-m-d H:i:s')
]);
foreach($school as $key => $value){
$data = json_decode(json_encode($stories), true);
unset($data['idThought']);
$data['idSchool'] = $value;
$data['idFinancialYear'] = DB::table('financial_years')->where('idSchool',$value)->orderBy('idFinancialYear','DESC')->first()->idFinancialYear;
$data['publishDate'] = Carbon::now()->format('Y-m-d');
DB::table('weekly_thoughts')->insert($data);
}
$stds_birday = \App\AdmEntry::select('idStudent')->whereIn('idSchool',$school)
->where('isActive','Y')
->groupBy('idStudent')
->get()->pluck('idStudent')->toArray();
$reg_fids = DB::table('students')
->join('parents', 'students.father_mobile', '=', 'parents.mobile')
->select('parents.idFirebase')
->whereIn('students.idStudent', $stds_birday)
->get()->pluck('idFirebase')->toArray();
SendNotificationApi::sendNotification($reg_fids,"Thoughts : ".$stories->thought);
$reg_ids = DB::table('students')
->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
->select('parents.idFirebase')
->whereIn('students.idStudent', $stds_birday)
->get()->pluck('idFirebase')->toArray();
SendNotificationApi::sendNotification($reg_ids, "Thoughts : ".$stories->thought);
}
}
}
}
Copyright © 2021 -