Exemple #1
0
 public function save()
 {
     $model = new Announcement();
     if ($this->id) {
         $model = Announcement::findOne($this->id);
     }
     foreach ($this->attributes as $attribute => $value) {
         if (array_key_exists($attribute, $model->attributes)) {
             $model->{$attribute} = $value;
         }
     }
     $model->categories = $this->categories;
     $model->articles = $this->articles;
     $model->params = ['titleLength' => $this->titleLength, 'textLength' => $this->textLength];
     return $model->save();
 }
 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]);
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public static function find()
 {
     return parent::find()->where(['enabled' => 1]);
 }
 public function actionToggle()
 {
     if (!\Yii::$app->request->isAjax) {
         throw new BadRequestHttpException("Данный запрос возможен только через ajax!");
     }
     if (!($attribute = \Yii::$app->request->post("attribute"))) {
         throw new InvalidParamException("Не передан attribute!");
     }
     if (!($key = \Yii::$app->request->post("key"))) {
         throw new InvalidParamException("Не передан key!");
     }
     if (!($value = \Yii::$app->request->post("value"))) {
         throw new InvalidParamException("Не передан value!");
     } else {
         $value = $value == 'true' ? true : false;
     }
     $model = Announcement::findOne($key);
     if (!$model) {
         throw new NotFoundHttpException("Не найдены новости с передаными идентификаторами!");
     }
     $model->setAttribute($attribute, $value);
     return $model->save(false);
 }
Exemple #5
0
 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;
 }
Exemple #6
0
?>

                <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 
    }
    ?>