예제 #1
0
파일: PostPeer.php 프로젝트: rayku/rayku
 static function getForThreadIdAnd($thread_id, $post_id)
 {
     $c = new Criteria();
     $c->add(PostPeer::THREAD_ID, $thread_id);
     $c->add(PostPeer::ID, $post_id, Criteria::NOT_EQUAL);
     $c->add(PostPeer::BEST_RESPONSE, 0);
     $c->addAscendingOrderByColumn(PostPeer::UPDATED_AT);
     $c->addJoin(PostPeer::POSTER_ID, UserPeer::ID, Criteria::JOIN);
     return PostPeer::doSelect($c);
 }
예제 #2
0
 public function executeIndex()
 {
     $blog = $this->getUser()->getBlog();
     if (!$blog->getApproved()) {
         $this->blog = $blog;
         return 'NotApproved';
     }
     $c = new Criteria();
     $c->add(PostPeer::BLOG_ID, $this->getUser()->getId());
     $c->add(PostPeer::DELETED, false);
     $c->addDescendingOrderByColumn(PostPeer::CREATED_AT);
     $c->setLimit(10);
     $this->posts = PostPeer::doSelect($c);
 }
예제 #3
0
 public function executeIndex()
 {
     $name = $this->getRequestParameter('tag', '');
     $c = new Criteria();
     if ($name) {
         $c->add(TagPeer::NAME, $name);
         $tag = TagPeer::doSelectOne($c);
         $this->forward404Unless($tag);
         $c->clear();
         $c->addJoin(PostTagPeer::POST_ID, PostPeer::ID, Criteria::LEFT_JOIN);
         $c->add(PostTagPeer::TAG_ID, $tag->getId());
     }
     $c->addDescendingOrderByColumn(PostPeer::CREATED_AT);
     $c->setLimit(sfConfig::get('app_posts_in_feed', 10));
     $c->add(PostPeer::DELETED, false);
     $posts = PostPeer::doSelect($c);
     $this->feed = $this->createFeed($posts, $name);
     ReaderPeer::increment();
 }
예제 #4
0
 public function executeNewThread()
 {
     $this->User = $this->getUser()->getRaykuUser();
     if (!empty($_COOKIE['redirection'])) {
         $this->getResponse()->setCookie("redirection", "", time() - 600, '/', sfConfig::get('app_cookies_domain'));
     }
     $c = new Criteria();
     $c->add(ForumPeer::TYPE, 0);
     $this->publicforums = ForumPeer::doSelect($c);
     $this->category = CategoryPeer::retrieveByPK($this->getRequestParameter('forum_id'));
     if (!$this->category instanceof Category) {
         $this->category = ForumPeer::retrieveByPK($this->getRequestParameter('forum_id'));
     }
     $this->allcategories = CategoryPeer::doSelect($c = new Criteria());
     $user = $this->getUser()->getRaykuUser();
     if ($this->getRequestParameter('thread_title') != '') {
         $theard_title_len = strlen($this->getRequestParameter('thread_title'));
         $theard_body_len = strlen(strip_tags($this->getRequestParameter('post_body')));
         if ($theard_title_len >= 10 and $theard_body_len >= 10) {
             $school_grade = $this->getRequestParameter('school_grade');
             $tags = $this->getRequestParameter('tags');
             $arrayoftags = explode(',', $tags);
             foreach ($arrayoftags as $tag) {
                 if ($tag == 'I') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'a') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'about') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'an') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'are') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'as') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'at') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'be') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'by') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'com') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'de') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'en') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'for') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'from') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'how') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'in') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'is') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'it') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'la') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'of') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'on') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'or') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'that') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'the') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'this') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'to') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'was') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'what') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'when') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'where') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'who') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'will') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'with') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'und') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'the') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
                 if ($tag == 'www') {
                     $this->msg = $tag . ' is a stop word, please add the proper tag';
                     return sfView::SUCCESS;
                 }
             }
             $thread = $user->makeNewThread($this->getRequestParameter('forum_id'), $this->getRequestParameter('thread_title'), $this->getRequestParameter('post_body'), $this->getRequestParameter('forum_id'), $this->getRequestParameter('notify_email'), $this->getRequestParameter('notify_pm'), $this->getRequestParameter('tags'), $this->getRequestParameter('school_grade'), $this->getRequestParameter('stickie'));
             $l = new Criteria();
             $l->addDescendingOrderByColumn(PostPeer::ID);
             $l->setLimit(1);
             $latest = PostPeer::doSelect($l);
             $stickie = 0;
             if ($this->getRequestParameter('stickie') == 1) {
                 $stickie = 1;
             }
             ///////////////////updating the ip of the user
             $connection = RaykuCommon::getDatabaseConnection();
             mysql_query("update thread set user_ip='" . $_SERVER['REMOTE_ADDR'] . "', stickie = " . $stickie . " where id=" . $latest[0]->getThreadId() . "", $connection);
             ///////////////////updating the ip of the user
             return $this->redirect('@view_thread?thread_id=' . $latest[0]->getThreadId());
         } else {
             if ($theard_title_len < 10) {
                 $this->title_error = "Title should be more than 10 characters";
             }
             if ($theard_body_len < 10) {
                 $this->desc_error = "Description should be more than 10 characters";
             }
         }
     }
 }
예제 #5
0
 /**
  * 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);
 }
예제 #6
0
파일: BaseBlog.php 프로젝트: noose/Planeta
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this Blog has previously
  * been saved, it will retrieve related Posts from storage.
  * If this Blog is new, it will return
  * an empty collection or the current collection, the criteria
  * is ignored on a new object.
  *
  * @param      Connection $con
  * @param      Criteria $criteria
  * @throws     PropelException
  */
 public function getPosts($criteria = null, $con = null)
 {
     // include the Peer class
     include_once 'lib/model/om/BasePostPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collPosts === null) {
         if ($this->isNew()) {
             $this->collPosts = array();
         } else {
             $criteria->add(PostPeer::BLOG_ID, $this->getId());
             PostPeer::addSelectColumns($criteria);
             $this->collPosts = PostPeer::doSelect($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 the collection.
             $criteria->add(PostPeer::BLOG_ID, $this->getId());
             PostPeer::addSelectColumns($criteria);
             if (!isset($this->lastPostCriteria) || !$this->lastPostCriteria->equals($criteria)) {
                 $this->collPosts = PostPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastPostCriteria = $criteria;
     return $this->collPosts;
 }
예제 #7
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(PostPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PostPeer::DATABASE_NAME);
         $criteria->add(PostPeer::ID, $pks, Criteria::IN);
         $objs = PostPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
예제 #8
0
 public function getPosts($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BasePostPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collPosts === null) {
         if ($this->isNew()) {
             $this->collPosts = array();
         } else {
             $criteria->add(PostPeer::AUTHOR_ID, $this->getId());
             PostPeer::addSelectColumns($criteria);
             $this->collPosts = PostPeer::doSelect($criteria, $con);
         }
     } else {
         if (!$this->isNew()) {
             $criteria->add(PostPeer::AUTHOR_ID, $this->getId());
             PostPeer::addSelectColumns($criteria);
             if (!isset($this->lastPostCriteria) || !$this->lastPostCriteria->equals($criteria)) {
                 $this->collPosts = PostPeer::doSelect($criteria, $con);
             }
         }
     }
     $this->lastPostCriteria = $criteria;
     return $this->collPosts;
 }