Last active
June 4, 2020 16:54
-
-
Save chrisvasey/333af7bdf962385289cc6e5e2450441a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function createSingleAction($title,$message,$candidate_id,$user_id) { | |
$action = new Action; | |
$action->title = $title; | |
$action->message = $message; | |
$action->candidate_id =$candidate_id; | |
$action->user_id = $user_id; | |
$action->save(); | |
} | |
public function createActions() { | |
// RUN THROUGH CRON | |
$user_notifications = array(); | |
$actionCount = 0; | |
$userActions = array(); | |
$candidates = Candidate::where('Deleted',0)->get(); | |
Candidate::where('Deleted', 0)->chunkById(100, function ($c) { | |
Action::where('candidate_id',$c->id)->delete(); | |
if ($c->progress->last()->stage == 'applied' && $c->progress->last()->status == 'yes' && (strtotime($c->progress->last()->updated_at) < strtotime(date('jS M Y',strtotime('-3 weeks'))))) { | |
$title = $c->first_name . " " . $c->surname . " Expressed Interest"; | |
$message = "You should contact them soon!"; | |
$candidate_id = $c->id; | |
$users = $c->job->getSiteOrCustomer()->users->where('candidate_check',1); | |
foreach ($users as $u) { | |
$this->createSingleAction($title,$message,$candidate_id,$u->id); | |
if (isset($userActions[$u->id])){ | |
$userActions[$u->id] = $userActions[$u->id]+1; | |
} else { | |
$userActions[$u->id] = 1; | |
} | |
$actionCount++; | |
} | |
} | |
if ($c->progress->last()->stage == 'applied' && $c->progress->last()->status == 'yes' && (strtotime($c->progress->last()->updated_at) < strtotime(date('jS M Y',strtotime('-3 weeks'))))) { | |
$title = $c->first_name . " " . $c->surname . " Expressed Interest"; | |
$message = "You should contact them soon!"; | |
$candidate_id = $c->id; | |
$users = $c->job->getSiteOrCustomer()->users->where('candidate_check',1); | |
foreach ($users as $u) { | |
$this->createSingleAction($title,$message,$candidate_id,$u->id); | |
if (isset($userActions[$u->id])){ | |
$userActions[$u->id] = $userActions[$u->id]+1; | |
} else { | |
$userActions[$u->id] = 1; | |
} | |
$actionCount++; | |
} | |
} | |
}); | |
return $actionCount . ' Actions Created'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment