/** * Action to display login page */ public function executeIndex() { $connection = RaykuCommon::getDatabaseConnection(); if ($this->getRequestParameter('username') == null) { $this->redirect("/dashboard"); } $c = new Criteria(); $c->add(UserPeer::USERNAME, $this->getRequestParameter('username')); $user = UserPeer::doSelectOne($c); $this->user = $user; $this->tutor_id = $user->getId(); $c = new Criteria(); $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN); $rankexperts = ExpertCategoryPeer::doSelect($c); $rankUsers = array(); $ji = 0; $eachExpertOnlyOnce = array(); $rankScore = array(); /** * @todo this loop parses all experts only to later use only one of them in template - fix this */ foreach ($rankexperts as $exp) { if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) { continue; } $eachExpertOnlyOnce[] = $exp->getUserId(); $query = mysql_query("select * from user_score where user_id=" . $exp->getUserId(), $connection) or die(mysql_error()); $score = mysql_fetch_assoc($query); if ($score['score'] != 0) { $dv = new Criteria(); $dv->add(UserPeer::ID, $exp->getUserId()); $_thisUser = UserPeer::doSelectOne($dv); $rankUsers[$ji] = array("score" => $score['score'], "userid" => $exp->getUserId(), "createdat" => $_thisUser->getCreatedAt()); $ji++; } } asort($rankUsers); arsort($rankUsers); $this->rankUsers = $rankUsers; ////////////////////////////// if (!empty($_GET['expert_id'])) { $_expert_id = !empty($_GET['expert_id']) ? $_GET['expert_id'] : 0; $userId = $this->getUser()->getRaykuUserId(); if ($_expert_id) { $query = mysql_query("select * from expert_subscribers where expert_id = " . $_expert_id . " and user_id =" . $userId, $connection) or die(mysql_error()); if (mysql_num_rows($query) == 0) { $_query = mysql_query("insert into expert_subscribers(expert_id, user_id) values(" . $_expert_id . ", " . $userId . ")", $connection) or die("Error--->" . mysql_error()); $queryScore = mysql_query("select * from user_score where user_id =" . $_expert_id, $connection) or die(mysql_error()); $rowScore = mysql_fetch_assoc($queryScore); $newScore = ''; $newScore = $rowScore['score'] + 10; mysql_query("update user_score set score = " . $newScore . " where user_id =" . $_expert_id, $connection) or die(mysql_error()); } } $this->redirect("/tutor/" . $user->getUsername()); } if ($this->getRequestParameter('content') != null) { $this->expertid = $this->getUser()->getRaykuUser()->getId(); $this->expertusr = $this->getUser()->getRaykuUser()->getUsername(); $this->content = $this->getRequestParameter('content'); $c = new Criteria(); $c->add(ExpertsPromoTextPeer::EXP_ID, $this->expertid); $expertstext = ExpertsPromoTextPeer::doSelectOne($c); if ($expertstext != null) { $expertstext->setContent($this->content); $expertstext->save(); } else { $promo = new ExpertsPromoText(); $promo->setExpId($this->expertid); $promo->setContent($this->content); $promo->save(); } } $this->expert = $user; $f = new Criteria(); $f->add(PostPeer::POSTER_ID, $user->getId()); $f->add(PostPeer::BEST_RESPONSE, '1'); $f->addDescendingOrderByColumn('ID'); $this->bestResponses = PostPeer::doSelect($f); $f->setLimit(6); $this->best_responses = PostPeer::doSelect($f); $expertId = $user->getId(); $userId = $this->getUser()->getRaykuUserId(); $this->currentUser = $this->getUser()->getRaykuUser(); // last n whiteboard sessions $cLastSessions = new Criteria(); if ($userId != $expertId) { $cPublicA = $cLastSessions->getNewCriterion(WhiteboardChatPeer::EXPERT_ID, $expertId); $cPublicB = $cLastSessions->getNewCriterion(WhiteboardChatPeer::IS_PUBLIC, true); $cPublicC = $cLastSessions->getNewCriterion(WhiteboardChatPeer::ASKER_ID, $userId); $cPublicB->addOr($cPublicC); $cPublicA->addAnd($cPublicB); } else { $cPublicA = $cLastSessions->getNewCriterion(WhiteboardChatPeer::EXPERT_ID, $userId); $cPublicB = $cLastSessions->getNewCriterion(WhiteboardChatPeer::ASKER_ID, $userId); $cPublicA->addOr($cPublicB); } $cLastSessions->add($cPublicA); $cLastSessions->add(WhiteboardChatPeer::STARTED_AT, null, Criteria::ISNOTNULL); $cLastSessions->addDescendingOrderByColumn(WhiteboardChatPeer::ID); $this->totalSessions = WhiteboardChatPeer::doSelect($cLastSessions); $cLastSessions->setLimit(3); $this->lastSessions = WhiteboardChatPeer::doSelect($cLastSessions); }
public function execute($request) { $connection = RaykuCommon::getDatabaseConnection(); $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id']; mysql_query("delete from popup_close where user_id=" . $logedUserId, $connection) or die(mysql_error()); if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach ($cookies as $cookie) { $parts = explode('=', $cookie); $name = trim($parts[0]); if ($name != "rayku_frontend" && $name != "ratingExpertId" && $name != "ratingUserId" && $name != "timer" && $name != "whiteboardChatId") { $this->getResponse()->setCookie($name, "", time() - 3600, '/', sfConfig::get('app_cookies_domain')); } } } if (!empty($_POST)) { if (empty($_POST["rating"])) { $this->redirect('/dashboard/rating'); } if (empty($_COOKIE['ratingExpertId']) && empty($_COOKIE['ratingUserId'])) { $this->redirect('/dashboard'); } else { if (!empty($_COOKIE['raykuCharge'])) { $rate = $_COOKIE['raykuCharge']; } else { $user = UserPeer::retrieveByPK($_COOKIE["ratingExpertId"]); if ($user) { $rate = $user->getRate(); } else { $rate = 0; } } $timer = explode(":", $_COOKIE["timer"]); $newTimer = ($timer[0] * 3600 + $timer[1] * 60) / 60; $raykuPercentage = $newTimer * $rate; $_chat_rating = $_POST["rating"]; $date = date('Y-m-d H:i:s'); $queryScore = mysql_query("select * from user_score where user_id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); $rowScore = mysql_fetch_assoc($queryScore); $queryAsker = mysql_query("select * from user where id=" . $_COOKIE["ratingUserId"], $connection) or die(mysql_error()); $rowAsker = mysql_fetch_assoc($queryAsker); $queryExpert = mysql_query("select * from user where id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); $rowExpert = mysql_fetch_assoc($queryExpert); $queryKinkarso = mysql_query("select * from user where id=124", $connection) or die(mysql_error()); $rowKinkarso = mysql_fetch_assoc($queryKinkarso); if ($_POST["rating"] == 1) { $check1RatingScore = $rowScore['score'] - 20; if ($check1RatingScore < 1) { $newRatingScore = "1"; } else { $newRatingScore = $rowScore['score'] - 20; } mysql_query("update user_score set score = " . $newRatingScore . " where user_id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); if ($rate != '0.00') { $kinkarsoPoints = $rowKinkarso["points"] + $raykuPercentage; mysql_query("update user set points = " . $kinkarsoPoints . " where id=124", $connection) or die(mysql_error()); } } elseif ($_POST["rating"] == 2) { $tiptutor = $_POST["tiptutor"]; $askerPoints = $rowAsker["points"] - $raykuPercentage; mysql_query("update user set points = " . $askerPoints . " where id=" . $_COOKIE["ratingUserId"], $connection) or die(mysql_error()); $expertPer = $raykuPercentage * 25 / 100; $kinkarsoPer = $raykuPercentage * 75 / 100; $expertPoints = $rowExpert["points"] + $expertPer + $tiptutor; $kinkarsoPoints = $rowKinkarso["points"] + $kinkarsoPer; mysql_query("update user set points = " . $expertPoints . " where id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); mysql_query("update user set points = " . $kinkarsoPoints . " where id=124", $connection) or die(mysql_error()); } elseif ($_POST["rating"] == 3) { $tiptutor = $_POST["tiptutor"]; $_Score = 0; if ($newTimer > 10) { $_Score = 10; } elseif ($newTimer <= 10 && $newTimer >= 2) { $_Score = 4; } if ($rate == '0.00') { $_Score = $_Score * 2; } $newRatingScore = $rowScore['score'] + $_Score; mysql_query("update user_score set score = " . $newRatingScore . " where user_id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); if ($rate != '0.00') { $askerPoints = $rowAsker["points"] - $raykuPercentage; mysql_query("update user set points = " . $askerPoints . " where id=" . $_COOKIE["ratingUserId"], $connection) or die(mysql_error()); $expertPer = $raykuPercentage * 50 / 100; $kinkarsoPer = $raykuPercentage * 50 / 100; $expertPoints = $rowExpert["points"] + $expertPer + $tiptutor; $kinkarsoPoints = $rowKinkarso["points"] + $kinkarsoPer; mysql_query("update user set points = " . $expertPoints . " where id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); mysql_query("update user set points = " . $kinkarsoPoints . " where id=124", $connection) or die(mysql_error()); } } elseif ($_POST["rating"] == 4) { $tiptutor = $_POST["tiptutor"]; $_Score = 0; if ($newTimer > 10) { $_Score = 18; } elseif ($newTimer <= 10 && $newTimer >= 2) { $_Score = 7; } if ($rate == '0.00') { $_Score = $_Score * 2; } $newRatingScore = $rowScore['score'] + $_Score; mysql_query("update user_score set score = " . $newRatingScore . " where user_id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); if ($rate != '0.00') { $askerPoints = $rowAsker["points"] - $raykuPercentage; mysql_query("update user set points = " . $askerPoints . " where id=" . $_COOKIE["ratingUserId"], $connection) or die(mysql_error()); $expertPer = $raykuPercentage * 75 / 100; //60; $kinkarsoPer = $raykuPercentage * 25 / 100; //40; $expertPoints = $rowExpert["points"] + $expertPer + $tiptutor; $kinkarsoPoints = $rowKinkarso["points"] + $kinkarsoPer; mysql_query("update user set points = " . $expertPoints . " where id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); mysql_query("update user set points = " . $kinkarsoPoints . " where id=124", $connection) or die(mysql_error()); } } elseif ($_POST["rating"] == 5) { $tiptutor = $_POST["tiptutor"]; $ratingScore = !empty($rowScore['score']) ? $rowScore['score'] : 0; if ($rate != '0.00') { $askerPoints = $rowAsker["points"] - $raykuPercentage; mysql_query("update user set points = " . $askerPoints . " where id=" . $_COOKIE["ratingUserId"], $connection) or die(mysql_error()); $expertPer = $raykuPercentage; // 5 stars: 100% RP $expertPoints = $rowExpert["points"] + $expertPer + $tiptutor; $kinkarsoPoints = $rowKinkarso["points"] + $kinkarsoPer; mysql_query("update user set points = " . $expertPoints . " where id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); mysql_query("update user set points = " . $kinkarsoPoints . " where id=124", $connection) or die(mysql_error()); } $_Score = 0; if ($newTimer > 10) { $_Score = 25; } elseif ($newTimer <= 10 && $newTimer >= 2) { $_Score = 10; } if ($rate == '0.00') { $_Score = $_Score * 2; } $newRatingScore = $rowScore['score'] + $_Score; mysql_query("update user_score set score = " . $newRatingScore . " where user_id=" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); } if (isset($_POST["checkbox"]) && !empty($_POST["checkbox"])) { if (!empty($_COOKIE["ratingExpertId"]) && !empty($_COOKIE["ratingUserId"])) { $query = mysql_query("select * from expert_subscribers where expert_id = " . $_COOKIE["ratingExpertId"] . " and user_id =" . $_COOKIE["ratingUserId"], $connection) or die(mysql_error()); if (mysql_num_rows($query) == 0) { mysql_query("insert into expert_subscribers(expert_id, user_id) values('" . $_COOKIE["ratingExpertId"] . "', '" . $_COOKIE["ratingUserId"] . "')", $connection) or die(mysql_error()); $queryScore = mysql_query("select * from user_score where user_id =" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); $rowScore = mysql_fetch_assoc($queryScore); $newScore = ''; $newScore = $rowScore['score'] + 10; mysql_query("update user_score set score = " . $newScore . " where user_id =" . $_COOKIE["ratingExpertId"], $connection) or die(mysql_error()); } } } if (!empty($_COOKIE["whiteboardChatId"]) && !empty($_COOKIE["whiteboardChatId"])) { $chatId = $_COOKIE["whiteboardChatId"]; $_SESSION["whiteboard_Chat_Id"] = $_COOKIE["whiteboardChatId"]; if (isset($_POST["chkIsPublic"]) && !empty($_POST["chkIsPublic"])) { $criteria = new Criteria(); $criteria->add(WhiteboardChatPeer::ID, $chatId); $chat = WhiteboardChatPeer::doSelectOne($criteria); if ($chat) { $chat->setIsPublic(true); $chat->save(); } } $_comments = !empty($_POST['content']) ? $_POST['content'] : ''; $_chat_query = mysql_query("select * from whiteboard_chat where id=" . $chatId . "", $connection) or "Error In Select" . mysql_error(); if (mysql_num_rows($_chat_query) > 0) { $_chat_row = mysql_fetch_assoc($_chat_query); mysql_query("update whiteboard_chat set timer = '" . $newTimer . "', rating = " . $_chat_rating . ", amount=" . $raykuPercentage . ", comments = '" . $_comments . "' where id=" . $chatId . " ", $connection) or die(mysql_error()); } } $this->getResponse()->setCookie("timer", "", time() - 3600, '/', sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("whiteboardChatId", "", time() - 3600, '/', sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("ratingExpertId", "", time() - 3600, '/', sfConfig::get('app_cookies_domain')); $this->getResponse()->setCookie("ratingUserId", "", time() - 3600, '/', sfConfig::get('app_cookies_domain')); $this->user = $this->getUser()->getRaykuUser(); $this->userPoints = $this->user->getPoints(); $this->userFirstCharge = $this->user->getFirstCharge(); if ($this->userPoints < 0 && empty($this->userFirstCharge)) { $datetime = strtotime($row->createdate); $mysqldate = date("m/d/y g:i A", $datetime); $this->user->setFirstCharge($mysqldate); } if ($_chat_rating == 1 || $_chat_rating == 2) { $this->redirect('/dashboard/moneyback'); } $this->redirect('/referrals?session=complete'); } } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = WhiteboardChatPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setIsPublic($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setExpertId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setAskerId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setExpertNickname($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setAskerNickname($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setQuestion($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setStartedAt($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setEndedAt($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setDirectory($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setCreatedAt($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { $this->setTimer($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { $this->setRating($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { $this->setAmount($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { $this->setComments($arr[$keys[14]]); } }
/** * Get the associated WhiteboardChat object * * @param PropelPDO Optional Connection object. * @return WhiteboardChat The associated WhiteboardChat object. * @throws PropelException */ public function getWhiteboardChat(PropelPDO $con = null) { if ($this->aWhiteboardChat === null && $this->whiteboard_chat_id !== null) { $c = new Criteria(WhiteboardChatPeer::DATABASE_NAME); $c->add(WhiteboardChatPeer::ID, $this->whiteboard_chat_id); $this->aWhiteboardChat = WhiteboardChatPeer::doSelectOne($c, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aWhiteboardChat->addWhiteboardTutorFeedbacks($this); */ } return $this->aWhiteboardChat; }
/** * Executes startChat action * */ public function executeStartChat() { $request = $this->getRequest(); if ($request->isMethod('post')) { // post params $chatId = $request->getPostParameter('chat_id'); $chatCriteria = new Criteria(); $chatCriteria->add(WhiteboardChatPeer::ID, $chatId); $chat = WhiteboardChatPeer::doSelectOne($chatCriteria); $chat->setStartedAt(time()); $chat->save(); } return $this->renderText(''); }
/** * Selects a collection of WhiteboardTutorFeedback objects pre-filled with all related objects. * * @param Criteria $c * @param PropelPDO $con * @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN * @return array Array of WhiteboardTutorFeedback objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectJoinAll(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $c = clone $c; // Set the correct dbName if it has not been overridden if ($c->getDbName() == Propel::getDefaultDB()) { $c->setDbName(self::DATABASE_NAME); } WhiteboardTutorFeedbackPeer::addSelectColumns($c); $startcol2 = WhiteboardTutorFeedbackPeer::NUM_COLUMNS - WhiteboardTutorFeedbackPeer::NUM_LAZY_LOAD_COLUMNS; WhiteboardChatPeer::addSelectColumns($c); $startcol3 = $startcol2 + (WhiteboardChatPeer::NUM_COLUMNS - WhiteboardChatPeer::NUM_LAZY_LOAD_COLUMNS); $c->addJoin(array(WhiteboardTutorFeedbackPeer::WHITEBOARD_CHAT_ID), array(WhiteboardChatPeer::ID), $join_behavior); $stmt = BasePeer::doSelect($c, $con); $results = array(); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $key1 = WhiteboardTutorFeedbackPeer::getPrimaryKeyHashFromRow($row, 0); if (null !== ($obj1 = WhiteboardTutorFeedbackPeer::getInstanceFromPool($key1))) { // We no longer rehydrate the object, since this can cause data loss. // See http://propel.phpdb.org/trac/ticket/509 // $obj1->hydrate($row, 0, true); // rehydrate } else { $omClass = WhiteboardTutorFeedbackPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj1 = new $cls(); $obj1->hydrate($row); WhiteboardTutorFeedbackPeer::addInstanceToPool($obj1, $key1); } // if obj1 already loaded // Add objects for joined WhiteboardChat rows $key2 = WhiteboardChatPeer::getPrimaryKeyHashFromRow($row, $startcol2); if ($key2 !== null) { $obj2 = WhiteboardChatPeer::getInstanceFromPool($key2); if (!$obj2) { $omClass = WhiteboardChatPeer::getOMClass(); $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1); $obj2 = new $cls(); $obj2->hydrate($row, $startcol2); WhiteboardChatPeer::addInstanceToPool($obj2, $key2); } // if obj2 loaded // Add the $obj1 (WhiteboardTutorFeedback) to the collection in $obj2 (WhiteboardChat) $obj2->addWhiteboardTutorFeedback($obj1); } // if joined row not null $results[] = $obj1; } $stmt->closeCursor(); return $results; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(WhiteboardChatPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(WhiteboardChatPeer::DATABASE_NAME); $criteria->add(WhiteboardChatPeer::ID, $pks, Criteria::IN); $objs = WhiteboardChatPeer::doSelect($criteria, $con); } return $objs; }