Skip to content

Instantly share code, notes, and snippets.

@cesarockstar1985
Last active April 25, 2023 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarockstar1985/380b72601ddcc30861d99f04221a6400 to your computer and use it in GitHub Desktop.
Save cesarockstar1985/380b72601ddcc30861d99f04221a6400 to your computer and use it in GitHub Desktop.
$followUp = $this->Bonds->FollowUps->find()->where(['bond_id' => $bondId])->first();
if ($elemId == 'enableFollowUp') {
if ($followUp) {
$followUp->enabled = !$followUp->enabled;
} else {
$followupData = [
'last_run' => date('Y-m-d H:i:s'),
'email_daily_sent_count' => 0,
'email_monthly_sent_count' => 0,
'enabled' => 1,
'bond_id' => $bondId,
];
$followUp = $this->FollowUps->newEntity($followupData);
}
} else {
if (!$followUp || $followUp->enabled == 0) {
$error = true;
} else {
$followUp->last_run = date('Y-m-d H:i:s');
$followUp->email_daily_sent_count = 0;
$followUp->email_monthly_sent_count = 0;
$followUp->enabled = 1;
}
}
if ($error || !$this->FollowUps->save($followUp)) {
$jsonResponse['success'] = 'false';
} else {
$jsonResponse['followUp'] = $followUp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment