public function connect($userId, $questionId)
 {
     $question = StudentQuestionPeer::retrieveByPk($questionId);
     $session = new WhiteboardSession();
     $session->setStudentQuestion($question);
     $session->setType($this->getType($userId, $question));
     $session->setToken($this->generateToken($userId, $questionId));
     $session->setUserId($userId);
     $session->save();
     return $session;
 }
 /**
  * Selects a collection of WhiteboardSession objects pre-filled with all related objects except User.
  *
  * @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 WhiteboardSession objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptUser(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     // Set the correct dbName if it has not been overridden
     // $c->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     WhiteboardSessionPeer::addSelectColumns($c);
     $startcol2 = WhiteboardSessionPeer::NUM_COLUMNS - WhiteboardSessionPeer::NUM_LAZY_LOAD_COLUMNS;
     StudentQuestionPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (StudentQuestionPeer::NUM_COLUMNS - StudentQuestionPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(WhiteboardSessionPeer::QUESTION_ID), array(StudentQuestionPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = WhiteboardSessionPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = WhiteboardSessionPeer::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 = WhiteboardSessionPeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             WhiteboardSessionPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined StudentQuestion rows
         $key2 = StudentQuestionPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = StudentQuestionPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = StudentQuestionPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 StudentQuestionPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (WhiteboardSession) to the collection in $obj2 (StudentQuestion)
             $obj2->addWhiteboardSession($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #3
0
 public function execute($request)
 {
     RaykuCommon::getDatabaseConnection();
     $currentUser = $this->getUser()->getRaykuUser();
     $userId = $currentUser->getId();
     $time = time();
     $_SESSION["_modelbox"] = 0;
     @setcookie('_popupclose', '', time() - 300, '/', sfConfig::get('app_cookies_domain'));
     if (@$_SESSION['modelPopupOpen']) {
         unset($_SESSION['modelPopupOpen']);
         if ($_SESSION['popup_session']) {
             unset($_SESSION['popup_session']);
         }
     }
     $details = explode(",", $_REQUEST['details']);
     if (count($details) > 4) {
         $details[2] = base64_decode($details[2]);
         $peer = new StudentQuestionPeer();
         $studentQuestion = $peer->retrieveByPk($this->getRequestParameter('questionId'));
         $questionId = $this->getRequestParameter('questionId');
         $sessionService = new WhiteboardSessionService();
         $session = $sessionService->connect($userId, $questionId);
         mysql_query("delete from user_expert where user_id = " . $userId) or die(mysql_error());
         $this->getResponse()->setCookie('sessionToken', $session->getToken(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $expertId = $details[0];
         $raykuCharge = $this->getRaykuCharge($expertId);
         $this->getResponse()->setCookie("raykuCharge", $raykuCharge, time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         // redirect to rayku whiteboard
         $this->redirect(sfConfig::get('app_whiteboard_url') . '/');
     } else {
         $criteria = new Criteria();
         $criteria->add(WhiteboardSessionPeer::CHAT_ID, $details[1]);
         $tutorSession = WhiteboardSessionPeer::doSelectOne($criteria);
         $studentQuestion = $tutorSession->getStudentQuestion();
         $student = $studentQuestion->getStudent();
         $tutor = $studentQuestion->getTutor();
         $this->getResponse()->setCookie('ratingExpertId', $tutor->getId(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie('ratingUserId', $student->getId(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("askerpoints", $student->getPoints(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("loginname", $student->getUsername(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("check_nick", $student->getUsername(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("chatid", $tutorSession->getChatId(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $sessionService = new WhiteboardSessionService();
         $studentSession = $sessionService->connect($student->getId(), $studentQuestion->getId());
         $studentSession->setChatId($tutorSession->getChatId());
         $studentSession->save();
         $this->getResponse()->setCookie("sessionToken", $studentSession->getToken(), time() + 3600, '/', sfConfig::get('app_cookies_domain'));
         $_record_id = $details[0];
         $_queryRecord = mysql_query("select * from sendmessage where id = " . $_record_id . " ") or die(mysql_error());
         if (mysql_num_rows($_queryRecord)) {
             $row = mysql_fetch_array($_queryRecord);
             $raykuCharge = $this->getRaykuCharge($row['expert_id']);
             $this->getResponse()->setCookie("raykuCharge", $raykuCharge, time() + 3600, '/', sfConfig::get('app_cookies_domain'));
             $this->getResponse()->setCookie("newredirect", 1, time() + 100, '/', sfConfig::get('app_cookies_domain'));
             $this->getResponse()->setCookie("redirection", "", time() - 600, '/', sfConfig::get('app_cookies_domain'));
             $this->getResponse()->setCookie("forumsub", "", time() - 600, '/', sfConfig::get('app_cookies_domain'));
             if (!empty($userId)) {
                 mysql_query("insert into popup_close(user_id) values(" . $userId . ")") or die("error3" . mysql_error());
             }
             if (!empty($details[0])) {
                 mysql_query("delete from sendmessage where id = " . $details[0]) or die("error4" . mysql_error());
             }
             // redirect to rayku whiteboard
             $this->redirect(sfConfig::get('app_whiteboard_url') . '/');
         } else {
             $this->redirect('/dashboard');
         }
     }
 }
Example #4
0
 /**
  * Get the associated StudentQuestion object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     StudentQuestion The associated StudentQuestion object.
  * @throws     PropelException
  */
 public function getStudentQuestion(PropelPDO $con = null)
 {
     if ($this->aStudentQuestion === null && $this->question_id !== null) {
         $c = new Criteria(StudentQuestionPeer::DATABASE_NAME);
         $c->add(StudentQuestionPeer::ID, $this->question_id);
         $this->aStudentQuestion = StudentQuestionPeer::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->aStudentQuestion->addWhiteboardSessions($this);
         		 */
     }
     return $this->aStudentQuestion;
 }
Example #5
0
 /**
  * Returns the number of related StudentQuestion objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related StudentQuestion objects.
  * @throws     PropelException
  */
 public function countStudentQuestionsRelatedByTutorId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(UserPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collStudentQuestionsRelatedByTutorId === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(StudentQuestionPeer::CHECKED_ID, $this->id);
             $count = StudentQuestionPeer::doCount($criteria, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(StudentQuestionPeer::CHECKED_ID, $this->id);
             if (!isset($this->lastStudentQuestionRelatedByTutorIdCriteria) || !$this->lastStudentQuestionRelatedByTutorIdCriteria->equals($criteria)) {
                 $count = StudentQuestionPeer::doCount($criteria, $con);
             } else {
                 $count = count($this->collStudentQuestionsRelatedByTutorId);
             }
         } else {
             $count = count($this->collStudentQuestionsRelatedByTutorId);
         }
     }
     return $count;
 }
Example #6
0
 /**
  * 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(StudentQuestionPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(StudentQuestionPeer::DATABASE_NAME);
         $criteria->add(StudentQuestionPeer::ID, $pks, Criteria::IN);
         $objs = StudentQuestionPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #7
0
 public function execute($request)
 {
     $connection = RaykuCommon::getDatabaseConnection();
     if (@$_SESSION['modelPopupOpen']) {
         if (@$_SESSION['popup_session']) {
             $_now = time();
             $_remain_time = $_now - $_SESSION['popup_session'];
             if ($_remain_time < 20) {
                 return $this->renderText('redirect');
             }
         } else {
             return $this->renderText('redirect');
         }
     }
     /* @var $currentUser User */
     $currentUser = $this->getUser()->getRaykuUser();
     $userId = $currentUser->getId();
     $time = time() - 300;
     $query = mysql_query($s = "select * from user_expert where checked_id = " . $userId . " and exe_order = 1 and time >= " . $time . "", $connection) or die(mysql_error());
     if (mysql_num_rows($query) > 0) {
         $row = mysql_fetch_assoc($query);
         if ($row['category_id']) {
             $category = CategoryPeer::retrieveByPk($row['category_id']);
             $subject = $category->getName();
         }
         //School Selection
         $usr_school_query = mysql_query("select * from user_expert where user_id = " . $row['user_id'] . "", $connection);
         $usr_school = mysql_fetch_array($usr_school_query);
         $school = $usr_school['school'];
         $length = strlen(trim($row['question']));
         if ($length <= 200) {
             $question = $row['question'];
         } else {
             $question = substr(trim($row['question']), 0, 200);
         }
         $x = new Criteria();
         $x->add(UserPeer::ID, $row['checked_id']);
         $newloginId = UserPeer::doSelectOne($x);
         $raykuCharge = $currentUser->getRate();
         mysql_query("update user_expert set status = 0 where id = " . $row['id'] . " ", $connection) or die(mysql_error());
         //User Course Info
         $usr_course_query = mysql_query("select * from user_expert as u join courses as c on u.course_id = c.id where u.user_id = " . $row['user_id'] . "", $connection);
         $usr_course = mysql_fetch_array($usr_course_query);
         if (!empty($usr_course['year']) && !empty($usr_course['course_code'])) {
             $course_info = $usr_course['course_name'] . ' | ' . $usr_course['year'] . ' | ' . $usr_course['course_code'];
         } else {
             $course_info = $usr_course['course_name'];
         }
         $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
         $browser = "others";
         if (eregi("(Chrome/)", $HTTP_USER_AGENT) == true) {
             $browser = "chrome";
         }
         if (eregi("(Safari/)", $HTTP_USER_AGENT) == true) {
             $browser = "safari";
         }
         $_SESSION["_modelbox"] = @$_SESSION["_modelbox"] + 1;
         $criteria = new Criteria();
         $criteria->add(StudentQuestionPeer::USER_ID, $row['user_id']);
         $criteria->add(StudentQuestionPeer::CHECKED_ID, $row['checked_id']);
         $criteria->add(StudentQuestionPeer::TIME, $time, '>=');
         $studentQuestion = StudentQuestionPeer::doSelectOne($criteria);
         if (!$studentQuestion) {
             exit;
         }
         $studentQuestion->setStatus(0);
         $studentQuestion->save();
         @setcookie('_popupclose', 1, time() + 300, '/', sfConfig::get('app_cookies_domain'));
         echo join('-', array($studentQuestion->getTutor()->getId(), $studentQuestion->getStudent()->getId(), base64_encode($studentQuestion->getQuestion()), $school, $subject, $course_info, $row['id'], $newloginId->getName(), "expert", $raykuCharge, $row['close'], $browser, $_SESSION["_modelbox"], $studentQuestion->getId()));
     }
     exit(0);
 }
Example #8
0
 /**
  * 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 = StudentQuestionPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setStudentId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setTutorId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setCategoryId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setCourseId($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setQuestion($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setExeOrder($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setTime($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setCourseCode($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setYear($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setSchool($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setStatus($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setClose($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setCron($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setSource($arr[$keys[14]]);
     }
 }