/** * Execute Purchase article by U_User * * @param sfWebRequets $request */ public function executePurchase(sfWebRequest $request) { if (!$this->getUser()->isAuthenticated()) { $this->redirect('@home'); } $article_id = $request->getParameter('id'); $user = $this->getUser()->getGuardUser(); $user->purchaseArticle($article_id); $oArticle = ContentTable::getInstance()->findOneById($article_id); if ($user->getLastPurchase() != date('Y-m-d')) { $user->setLastPurchase(date('Y-m-d')); $user->save(); // update full statistics $oStatisticsFull = StatisticsTable::getInstance()->getFullStatistics(Period::getCurrentPeriod()->getId()); $oStatisticsFull->set(date("j") . '_buy', $oStatisticsFull->get(date("j") . '_buy') + 1); $oStatisticsFull->save(); } // update category statistic $oStatisticsCat = StatisticsTable::getInstance()->getFullStatistics(Period::getCurrentPeriod()->getId(), $oArticle->getCategory()->getId()); $oStatisticsCat->set(date("j") . '_buy', $oStatisticsCat->get(date("j") . '_buy') + 1); $oStatisticsCat->save(); $oArticle->setPurchaseCnt($oArticle->getPurchaseCnt() + 1); $oArticle->save(); $oCategory = $oArticle->getCategory(); $oCategory->setPurchaseCnt($oCategory->getPurchaseCnt() + 1); $oCategory->save(); $oUser = $oArticle->getUser(); $oUser->setSells($oUser->getSells() + 1); $oUser->save(); $this->redirect('@article_by_categories?id=' . $article_id . '&sburl=1'); }
/** * Show Visit stats * * @param sfWebRequest $request */ public function executeVisit(sfWebRequest $request) { $this->form = new CategorySelectForm(); $iCategoryId = 1; $iPeriodId = Period::getCurrentPeriod()->getId(); if ($request->getParameter('category', false)) { $this->form->bind($request->getParameter($this->form->getName())); $iCategoryId = $this->form->getValue('id_category'); $this->form->setDefault('id_category', $iCategoryId); } $this->aFullData = StatisticsTable::getInstance()->getFullStatistics($iPeriodId); $this->aDataByCategory = StatisticsTable::getInstance()->getFullStatistics($iPeriodId, $iCategoryId); }
/** * U_User посмотрел категорию. Учитываем только один заход за день * * @param int $iUserId * @param int $iCategoryId */ public static function uuserViewCategory($iUserId = 0, $iCategoryId = 0) { $q = Doctrine_Query::create()->select('sc.user_id')->from('StatisticsCategory sc')->where('sc.visit_date = CURDATE()')->andWhere('sc.category_id = ?', $iCategoryId)->andWhere('sc.user_id = ?', $iUserId)->limit(1); if (false !== $q->fetchOne()) { return; } // No first visit // New u_user $oStatsCategory = new StatisticsCategory(); $oStatsCategory->setCategoryId($iCategoryId); $oStatsCategory->setUserId($iUserId); $oStatsCategory->setVisitDate(date('Y-m-d')); $oStatsCategory->save(); // Update category stats $oStatistics = StatisticsTable::getInstance()->getFullStatistics(Period::getCurrentPeriod(), $iCategoryId); if (!$oStatistics instanceof Statistics) { throw new sfException('Cannon get Statistics object'); } $callMethodGet = 'get' . date('j') . 'Login'; $callMethodSet = 'set' . date('j') . 'Login'; $oStatistics->{$callMethodSet}($oStatistics->{$callMethodGet}() + 1); $oStatistics->save(); }
/** * Execute Login Form action * * @param sfWebRequest $request */ public function executeLoginForm(sfWebRequest $request) { $this->form = new LoginForm(); if ($request->isMethod('post') && null !== $request->getParameter($this->form->getName())) { $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $values = $this->form->getValues(); $this->getUser()->signin($values['user'], true); $oUser = $this->getUser()->getGuardUser(); if ($oUser->getLastLogin() != date("Y-m-d") && $oUser->getUtype() == 'uuser') { // statistic writing // set last login $oUser->setLastLogin(date("Y-m-d")); $oUser->save(); // get current statistic raw $oStatistics = StatisticsTable::getInstance()->getFullStatistics(Period::getCurrentPeriod()->getId()); // update login statistic $oStatistics->set(date("j") . '_login', $oStatistics->get(date("j") . '_login') + 1); $oStatistics->save(); } return $this->getController()->redirect('@homepage'); } } }