/** * User purchase article * * @param int $user_id * @param int $article_id * @return bool */ public function userPurchaseArticle($user_id, $article_id, $transaction) { if (!($article = ContentTable::getInstance()->getArticleForSale($article_id))) { return false; } $this->setIdUser($user_id); $this->setIdContent($article_id); $this->setIdCategory($article->getIdCategory()); $this->setTransaction($transaction); $this->save(); return true; }
/** * Get query for Category Articles List * * @param int $u_user_id - U_user ID or 0 * @return object Doctrine_Query */ public function getCategoryArticlesListQuery($u_user_id = 0) { $q = ContentTable::getInstance()->addContentPublishedListQuery(); $alias = $q->getRootAlias(); $q->andWhere($alias . '.id_category=?', $this->getId()); $q->andWhere($alias . '.id_user NOT IN (SELECT uu.id FROM user as uu WHERE uu.is_blocked = 1)'); // Filter by U_user purchased content if ($u_user_id != 0) { $q->andWhere($alias . '.id NOT IN (SELECT cp.id_content FROM ContentPurchase cp WHERE cp.id_user=?)', $u_user_id); } $q->orderBy('updated_at DESC'); return $q; }
/** * U_user purchase content: Transfer money from u_user to system * * @param <User> $user - instance of User purchased content * @param <int> $content_id - purchased article ID * @return bool */ public function purchaseContent(User $u_user, $content_id) { $article = ContentTable::getInstance()->getArticleForSale($content_id); if (!is_object($article)) { return false; } $p_user = $article->getTranslator(); $this->setOperation('purchase'); $this->setPeriod(Period::getCurrentPeriod()); $this->setAmount($article->getPrice()); $r2r_price = (int) ($article->getPrice() * Setting::getR2RPercent()) / 100; $p_user_price = $article->getPrice() - $r2r_price; $this->setIdSender($u_user->getId()); $this->setIdReceiver($p_user->getId()); // Update U_User balance $this->setSenderBalanceBefore($u_user->getBalans()); $u_user->setBalans($u_user->getBalans() - $this->getAmount()); $this->setSenderBalanceAfter($u_user->getBalans()); // Save U_User balance $u_user->save(); $u_user = null; $p_user = null; // System balance if (!($systemBalance = BalanceSystem::getCurrentBalanceInstance())) { return false; } // u_user Charges $systemBalance->setChargesUser($systemBalance->getChargesUser() + $this->getAmount()); // get p_user tariff plan $article_user_tariff = $article->getPUserTariff(); // p_user to pay and stats adn R2R summ if ($article_user_tariff == 'standart') { $systemBalance->setToPayStandart($systemBalance->getToPayStandart() + $p_user_price); $systemBalance->setSalesStandart($systemBalance->getSalesStandart() + 1); $systemBalance->setR2rStandart($systemBalance->getR2rStandart() + $r2r_price); } elseif ($article_user_tariff == 'expert') { $systemBalance->setToPayExpert($systemBalance->getToPayExpert() + $p_user_price); $systemBalance->setSalesExpert($systemBalance->getSalesExpert() + 1); $systemBalance->setR2rExpert($systemBalance->getR2rExpert() + $r2r_price); } elseif ($article_user_tariff == 'super') { $systemBalance->setToPaySuper($systemBalance->getToPaySuper() + $p_user_price); $systemBalance->setSalesSuper($systemBalance->getSalesSuper() + 1); $systemBalance->setR2rSuper($systemBalance->getR2rSuper() + $r2r_price); } // Save system balance $systemBalance->save(); $systemBalance = null; // BalanceUser u_user: update purchase stats if (!($userBalance = BalanceUserTable::getInstance()->getByUserIdAndPeriodId($this->getIdSender()))) { $userBalance = new BalanceUser(); $userBalance->setPeriod(Period::getCurrentPeriod()); $userBalance->setIdUser($this->getIdSender()); } // Save U_User purchase stats $userBalance->setSellPurchaseCnt($userBalance->getSellPurchaseCnt() + 1); $userBalance->setAmount($userBalance->getAmount() + $this->getAmount()); // save data $userBalance->save(); $userBalance = null; // BalanceUser p_user: update sell stats // Receiver: P_User balance if (!($userBalance = BalanceUserTable::getInstance()->getByUserIdAndPeriodId($this->getIdReceiver()))) { $userBalance = new BalanceUser(); $userBalance->setPeriod(Period::getCurrentPeriod()); $userBalance->setIdUser($this->getIdReceiver()); } // Transaction $this->setReceiverBalanceBefore($userBalance->getAmount()); // p_user $userBalance->setSellPurchaseCnt($userBalance->getSellPurchaseCnt() + 1); $userBalance->setAmount($userBalance->getAmount() + $this->getAmount()); $userBalance->setPayable($userBalance->getPayable() + $this->getAmount() - $r2r_price); // transaction $this->setReceiverBalanceAfter($userBalance->getAmount()); // save data $userBalance->save(); $userBalance = null; // Save transaction $this->save(); return $this; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->period = Period::getCurrentPeriod(); $this->stats_nopub = ContentTable::getInstance()->getUserStatsNoPublished($this->getUser()->getId()); // $this->stats_pub = ContentTable::getInstance()->getUserStatsPublished($this->getUser()->getId()); $this->stats_pub = $this->getUser()->getGuardUser()->getSoldStatsForPeriod($this->period); }
public function getNotPublishedArticle() { if ($this->getUtype() != 'puser') { return false; } $list = ContentTable::getInstance()->getNopublishedList($this->getId()); }
/** * Executes rate action * * @param sfWebRequest $request */ public function executeRate(sfWebRequest $request) { if ($request->isXmlHttpRequest()) { $result = array("success" => 0); $iArticleId = $request->getParameter('article_id'); $sRateType = $request->getParameter('rate_type'); $iRating = (int) $request->getParameter('rating'); // checking input data $this->forward404Unless($iRating >= 1 && $iRating <= 5 || ($sRateType == 'content' || $sRateType != 'translate' || $sRateType == 'r2rcontent' || $sRateType != 'r2rtranslate')); $this->forward404Unless($oArticle = ContentTable::getInstance()->findOneById($iArticleId)); // updating rating if ($sRateType == 'content') { $oArticle->setUserContentRating($this->getUser()->getGuardUser()->getId(), $iRating); $result['success'] = 1; echo json_encode($result); exit; } if ($sRateType == 'translate') { $oArticle->setUserTranslateRating($this->getUser()->getGuardUser()->getId(), $iRating); $result['success'] = 1; echo json_encode($result); exit; } if ($sRateType == 'r2rcontent') { $oArticle->setR2rContRate($iRating); $oArticle->save(); $result['success'] = 1; echo json_encode($result); exit; } if ($sRateType == 'r2rtranslate') { $oArticle->setR2rTransRate($iRating); $oArticle->save(); $result['success'] = 1; echo json_encode($result); exit; } } else { $this->redirect($request->getReferer()); } }