IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Console/Commands/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Console/Commands/StoriesUpdate.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
use Carbon\Carbon;
use \App\Http\SendNotificationApi;

class StoriesUpdate extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:stories';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send stories 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('isStoriesAutomatic',1)->get()->pluck('idSchool')->toArray();
        $isJobRun = DB::table('automatic_jobs')->where('job_name',"stories")->orderBy('id','DESC')->first();
        if( $isJobRun == null){
            $stories = DB::table('short_stories')->where('idSchool',163)->first();
            if($stories != null){
                DB::table('automatic_jobs')->insert([
                    'job_name' => "stories",
                    'job_ref' => $stories->idStory,
                    '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['idStory']); 
                    $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('short_stories')->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,"Short Stories : ".$stories->title);
                $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, "Short Stories : ".$stories->title);
            }            
        }else{
            $stories = DB::table('short_stories')->where('idStory','>',$isJobRun->job_ref)->where('idSchool',163)->first();
            if($stories != null){
                DB::table('automatic_jobs')->insert([
                    'job_name' => "stories",
                    'job_ref' => $stories->idStory,
                    '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['idStory']); 
                    $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('short_stories')->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,"Short Stories : ".$stories->title);
                $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, "Short Stories : ".$stories->title);
            } 
        }        
    }
}

Copyright © 2021 - 2025 IMMREX7