public function actionIndex() { $userId = Yii::$app->user->id; // COUNT ANNOUNCEMENT $db = Yii::$app->db; $countAnnouncement = $db->cache(function ($db) use($userId) { $countAnnouncement = Announcement::find()->andFilterWhere(['user_id' => $userId])->andFilterWhere(['in', 'status', [Announcement::STATUS_ENABLED, Announcement::STATUS_SALES]])->count(); return $countAnnouncement; }, Yii::$app->params['1minuteCacheSeconds']); // COUNT PROPOSITIONS $propositionService = new PropositionService(); $countPropositions = $propositionService->getTotalPropositionCount($userId); // FAQ $faq = SelectData::getFAQ(); return $this->render('index', ['countAnnouncement' => $countAnnouncement, 'countPropositions' => $countPropositions, 'faq' => $faq]); }
/** * @return \yii\db\ActiveQuery */ public static function find() { return parent::find()->where(['enabled' => 1]); }
/** * Renders the index view for the module * @return string */ public function actionIndex() { return $this->render('index', ['announcements' => new ActiveDataProvider(['query' => Announcement::find(), 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]])]); }
public function getToUserId($announcementId) { $db = Yii::$app->db; $toUserId = $db->cache(function ($db) use($announcementId) { $toUserId = Announcement::find()->select(['user_id'])->where(['id' => $announcementId])->asArray()->one(); $toUserId = array_shift($toUserId); return $toUserId; }); return $toUserId; }
?> <span class="intro-text"><?php echo Yii::t('app', 'layout_main_title'); ?> </span> <!-- CREATED YESTARDAY --> <?php if ($controller == 'site' && $action == 'index') { ?> <?php $db = Yii::$app->db; $yestardayCreated = $db->cache(function ($db) { $yestardayCreated = Announcement::find()->andWhere('DATE(date_created) = DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))')->count(); return $yestardayCreated; }, Yii::$app->params['24hourCache']); ?> <?php if ($yestardayCreated) { ?> <div class="header-new"> <div class="header-new-text"><span><?php /*= $yestardayCreated */ ?> </span>добавлено вчера!</div> </div> <?php } ?>