Got it working! 🍎

This commit is contained in:
Chris Smith
2025-02-19 21:43:44 +01:00
parent 658718ca06
commit 61e85ae9a2
20 changed files with 651 additions and 1200 deletions

View File

@@ -7,18 +7,22 @@ namespace common\models;
*
* @property int $id
* @property string $file_name
* @property string $food_name
* @property int $calories
* @property int $protein
* @property int $fat
* @property int $carbohydrates
* @property int $fiber
* @property int $meal
* @property int $user_id
* @property int $created_at
* @property int $updated_at
*/
class Meal extends \yii\db\ActiveRecord
{
public $base64File;
/**
* {@inheritdoc}
*/
@@ -33,8 +37,8 @@ class Meal extends \yii\db\ActiveRecord
public function rules()
{
return [
[['file_name', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'meal', 'created_at', 'updated_at'], 'required'],
[['calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'meal', 'created_at', 'updated_at'], 'integer'],
[['food_name', 'file_name', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'meal', 'created_at', 'updated_at'], 'required'],
[['user_id', 'calories', 'protein', 'fat', 'carbohydrates', 'fiber', 'meal', 'created_at', 'updated_at'], 'integer'],
[['file_name'], 'string', 'max' => 255],
];
}

View File

@@ -54,26 +54,24 @@ class User extends ActiveRecord implements IdentityInterface
];
// register event
$this->on(self::EVENT_AFTER_INSERT, [$this, 'emailTrigger']);
$this->on(self::EVENT_AFTER_UPDATE, [$this, 'emailTrigger']);
//$this->on(self::EVENT_AFTER_INSERT, [$this, 'emailTrigger']);
//$this->on(self::EVENT_AFTER_UPDATE, [$this, 'emailTrigger']);
}
public function emailTrigger(AfterSaveEvent $event)
{
if ($event->sender->status == self::STATUS_ACTIVE && !$event->sender->welcome_email_sent) {
Yii::$app->queue->push(new EmailJob([
'templateAlias' => EmailJob::WELCOME_EMAIL,
'email' => $event->sender->email,
'templateModel' => [
"name" => $event->sender->first_name,
"action_url" => Yii::$app->urlManager->createAbsoluteUrl(['site/login']),
]
]));
Yii::$app->queue->push(new EmailJob([
'templateAlias' => EmailJob::WELCOME_EMAIL,
'email' => $event->sender->email,
'templateModel' => [
"name" => $event->sender->first_name,
"action_url" => Yii::$app->urlManager->createAbsoluteUrl(['site/login']),
]
]));
$event->sender->welcome_email_sent = true;
$event->sender->save(false);
}
$event->sender->welcome_email_sent = true;
$event->sender->save(false);
}
@@ -91,7 +89,7 @@ class User extends ActiveRecord implements IdentityInterface
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_UNVERIFIED],
['status', 'default', 'value' => self::STATUS_VERIFIED],
[['email'], 'email'],
[['email'], 'unique'],
[['sales_agent_id', 'created_at', 'updated_at'], 'integer'],