Updated success screen
This commit is contained in:
@@ -5,6 +5,7 @@ namespace frontend\controllers;
|
|||||||
use common\models\Meal;
|
use common\models\Meal;
|
||||||
use common\models\MealForm;
|
use common\models\MealForm;
|
||||||
use common\models\search\MealSearch;
|
use common\models\search\MealSearch;
|
||||||
|
use DateTime;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\filters\AccessControl;
|
use yii\filters\AccessControl;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
@@ -63,9 +64,10 @@ class MealController extends Controller
|
|||||||
$model = new MealForm();
|
$model = new MealForm();
|
||||||
|
|
||||||
if (Yii::$app->request->isPost) {
|
if (Yii::$app->request->isPost) {
|
||||||
|
$model->load(Yii::$app->request->post());
|
||||||
$model->picture = UploadedFile::getInstance($model, 'picture');
|
$model->picture = UploadedFile::getInstance($model, 'picture');
|
||||||
if ($model->upload()) {
|
if ($model->upload()) {
|
||||||
$id = \Yii::$app->gemini->mealInquiry($model->filepath);
|
$id = \Yii::$app->gemini->mealInquiry($model);
|
||||||
return Yii::$app->response->redirect(['meal/success', 'id' => $id]);
|
return Yii::$app->response->redirect(['meal/success', 'id' => $id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,9 +80,7 @@ class MealController extends Controller
|
|||||||
public function actionSuccess($id)
|
public function actionSuccess($id)
|
||||||
{
|
{
|
||||||
$model = $this->findModel($id);
|
$model = $this->findModel($id);
|
||||||
$startOfDay = strtotime('today midnight');
|
$sum = Meal::find()
|
||||||
$endOfDay = strtotime('tomorrow midnight') - 1;
|
|
||||||
$today = Meal::find()
|
|
||||||
->select([
|
->select([
|
||||||
'SUM(calories) AS calories',
|
'SUM(calories) AS calories',
|
||||||
'SUM(protein) AS protein',
|
'SUM(protein) AS protein',
|
||||||
@@ -88,13 +88,22 @@ class MealController extends Controller
|
|||||||
'SUM(carbohydrates) AS carbohydrates',
|
'SUM(carbohydrates) AS carbohydrates',
|
||||||
'SUM(fiber) AS fiber'
|
'SUM(fiber) AS fiber'
|
||||||
])
|
])
|
||||||
->where(['user_id' => Yii::$app->user->id])
|
->where(['user_id' => Yii::$app->user->id, 'date' => $model->date])
|
||||||
->andWhere(['between', 'created_at', $startOfDay, $endOfDay])
|
|
||||||
->asArray()
|
->asArray()
|
||||||
->one();
|
->one();
|
||||||
$today = array_merge(['calories' => 0, 'protein' => 0, 'fat' => 0, 'carbohydrates' => 0, 'fiber' => 0], $today);
|
$sum = array_merge(['calories' => 0, 'protein' => 0, 'fat' => 0, 'carbohydrates' => 0, 'fiber' => 0], $sum);
|
||||||
|
|
||||||
return $this->render('success', ['model' => $model, 'today' => $today]);
|
$today = new DateTime();
|
||||||
|
$modelDate = new DateTime($model->date); // @todo should be a date object
|
||||||
|
$diff = $today->diff($modelDate);
|
||||||
|
|
||||||
|
$sum['title'] = match ($diff->days) {
|
||||||
|
0 => 'Today So Far',
|
||||||
|
1 => 'Yesterday\'s Sum',
|
||||||
|
default => $modelDate->format('M jS'),
|
||||||
|
};
|
||||||
|
|
||||||
|
return $this->render('success', ['model' => $model, 'sum' => $sum]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ var isMobile = window.innerWidth < 768; // Adjust as needed for tablets
|
|||||||
<!-- Daily Totals Section -->
|
<!-- Daily Totals Section -->
|
||||||
<div class="col-md-6 d-flex mt-3 mt-md-0">
|
<div class="col-md-6 d-flex mt-3 mt-md-0">
|
||||||
<div class="card p-3 w-100 h-100 d-flex flex-column" style="max-width: 400px; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 200;">
|
<div class="card p-3 w-100 h-100 d-flex flex-column" style="max-width: 400px; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 200;">
|
||||||
<h4 class="card-title text-center">📊 <strong>Today So Far</strong></h4>
|
<h4 class="card-title text-center">📊 <strong><?=$sum['title']?></strong></h4>
|
||||||
<div class="row flex-grow-1">
|
<div class="row flex-grow-1">
|
||||||
<div class="col-6 text-end">
|
<div class="col-6 text-end">
|
||||||
<p class="mb-0"><strong>🔥 Calories</strong></p>
|
<p class="mb-0"><strong>🔥 Calories</strong></p>
|
||||||
@@ -93,11 +93,11 @@ var isMobile = window.innerWidth < 768; // Adjust as needed for tablets
|
|||||||
<p class="mb-0"><strong>🌾 Fiber</strong></p>
|
<p class="mb-0"><strong>🌾 Fiber</strong></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 text-start">
|
<div class="col-6 text-start">
|
||||||
<p class="mb-0"><?= $today['calories']; ?> kcal</p>
|
<p class="mb-0"><?= $sum['calories']; ?> kcal</p>
|
||||||
<p class="mb-0"><?= $today['protein']; ?> g</p>
|
<p class="mb-0"><?= $sum['protein']; ?> g</p>
|
||||||
<p class="mb-0"><?= $today['fat']; ?> g</p>
|
<p class="mb-0"><?= $sum['fat']; ?> g</p>
|
||||||
<p class="mb-0"><?= $today['carbohydrates']; ?> g</p>
|
<p class="mb-0"><?= $sum['carbohydrates']; ?> g</p>
|
||||||
<p class="mb-0"><?= $today['fiber']; ?> g</p>
|
<p class="mb-0"><?= $sum['fiber']; ?> g</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user