Example #1
0
 public function getParent()
 {
     if ($this->getParentId() != 0) {
         return CategoryPeer::retrieveByPk($this->getParentId());
     }
     return false;
 }
Example #2
0
 public function executeView(sfWebRequest $request)
 {
     $category = CategoryPeer::retrieveByName($request->getParameter('category_name'));
     $this->forward404Unless($category);
     if ($category->getParentId() != 0) {
         $this->parentCategory = CategoryPeer::retrieveByPk($category->getParentId());
     } else {
         $this->subCategorys = CategoryPeer::getAllSub($category->getId());
     }
     $c = new Criteria();
     if (isset($this->subCategorys)) {
         $subCategoryIds = array();
         foreach ($this->subCategorys[$category->getId()] as $sub) {
             $subCategoryIds[] = $sub->getId();
         }
         $subCategoryIds[] = $category->getId();
         $c->add(ElementPeer::CATEGORY_ID, $subCategoryIds, Criteria::IN);
     } else {
         $c->add(ElementPeer::CATEGORY_ID, $category->getId());
     }
     $this->pager = new sfPropelPager('Element', 10);
     $this->pager->setPeerMethod('doSelectJoinAll');
     $this->pager->setCriteria($c);
     $this->pager->setPage($this->getRequestParameter('page'), 1);
     $this->pager->init();
     $this->elements = $this->pager->getResults();
     $this->category = $category;
 }
Example #3
0
 static function getForExpertCategoryUserId($user_id)
 {
     $c = new Criteria();
     $c->add(ExpertCategoryPeer::USER_ID, $user_id);
     $c->addJoin(ExpertCategoryPeer::CATEGORY_ID, CategoryPeer::ID);
     return CategoryPeer::doSelect($c);
 }
Example #4
0
 public function executeAddArticleAndSave(sfWebRequest $request)
 {
     $article = new Article();
     $article->setTitle(__METHOD__ . '()');
     $category = CategoryPeer::retrieveByPK($request->getParameter('category_id'));
     $category->addArticle($article);
     $category->save();
     return sfView::NONE;
 }
Example #5
0
 /**
  * The component to display a single forum (i.e. the threads in it)
  */
 public function executeShowForum()
 {
     $this->category = CategoryPeer::retrieveByPK($this->forumID);
     if ($this->category == NULL) {
         $this->category = ForumPeer::retrieveByPK($this->forumID);
     }
     $c = ThreadPeer::getCriteriaForCategory($this->forumID);
     $pager = new sfPropelPager('Thread', 10);
     $pager->setCriteria($c);
     $pager->setPage($this->getRequestParameter('page', 1));
     $pager->init();
     $raykuPager = new RaykuPagerRenderer($pager);
     $raykuPager->setBaseUrl('@view_page?forum_id=' . $this->category->getId());
     $this->raykuPager = $raykuPager;
 }
Example #6
0
 public function executeCategory($request)
 {
     $category = CategoryPeer::retrieveByPk($request->getParameter('category[id]'));
     $this->form = new CategoryForm($category);
     if ($request->getParameter('global')) {
         $this->form->getValidatorSchema()->getPostValidator()->setOption('throw_global_error', true);
     }
     if ($request->isMethod(sfRequest::POST)) {
         $this->form->bind($request->getParameter('category'));
         if ($this->form->isValid()) {
             $this->form->save();
             $this->redirect('unique/ok');
         }
     }
 }
 /**
  * Selects a collection of CategoryHasProduct objects pre-filled with all related objects except Product.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of CategoryHasProduct objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptProduct(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     CategoryHasProductPeer::addSelectColumns($criteria);
     $startcol2 = CategoryHasProductPeer::NUM_COLUMNS - CategoryHasProductPeer::NUM_LAZY_LOAD_COLUMNS;
     CategoryPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (CategoryPeer::NUM_COLUMNS - CategoryPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(CategoryHasProductPeer::CATEGORY_ID, CategoryPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseCategoryHasProductPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = CategoryHasProductPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = CategoryHasProductPeer::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 {
             $cls = CategoryHasProductPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             CategoryHasProductPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Category rows
         $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CategoryPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = CategoryPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CategoryPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (CategoryHasProduct) to the collection in $obj2 (Category)
             $obj2->addCategoryHasProduct($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #8
0
 protected function addSortCriteria($criteria)
 {
     if (array(null, null) == ($sort = $this->getSort())) {
         return;
     }
     $column = CategoryPeer::translateFieldName($sort[0], BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
     if ('asc' == $sort[1]) {
         $criteria->addAscendingOrderByColumn($column);
     } else {
         $criteria->addDescendingOrderByColumn($column);
     }
 }
 /**
  * Selects a collection of Product objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return array           Array of Product objects.
  * @throws PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(ProductPeer::DATABASE_NAME);
     }
     ProductPeer::addSelectColumns($criteria);
     $startcol2 = ProductPeer::NUM_HYDRATE_COLUMNS;
     CategoryPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + CategoryPeer::NUM_HYDRATE_COLUMNS;
     $criteria->addJoin(ProductPeer::CATEGORY_ID, CategoryPeer::ENTITY_ID, $join_behavior);
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = ProductPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = ProductPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://www.propelorm.org/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = ProductPeer::getOMClass();
             $obj1 = new $cls();
             $obj1->hydrate($row);
             ProductPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Category rows
         $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CategoryPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = CategoryPeer::getOMClass();
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CategoryPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (Product) to the collection in $obj2 (Category)
             $obj2->addProduct($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #10
0
    public function executeExpertReplyThread()
    {
        $connection = RaykuCommon::getDatabaseConnection();
        $c = new Criteria();
        $c->add(ForumPeer::TYPE, 0);
        $this->publicforums = ForumPeer::doSelect($c);
        $this->allcategories = CategoryPeer::doSelect($c = new Criteria());
        $this->forum = $this->getRequestParameter('forum_id');
        $this->thread = ThreadPeer::retrieveByPK($this->getRequestParameter('thread_id'));
        $c = new Criteria();
        $c->add(PostPeer::THREAD_ID, $this->thread->getId());
        $this->post = PostPeer::doSelectOne($c);
        $user = $this->getUser()->getRaykuUser();
        if ($this->getRequestParameter('post_edit_content') != '') {
            $threadId = $this->getRequestParameter('thread_id');
            $_thread = ThreadPeer::retrieveByPK($threadId);
            $_thread->setTitle($this->getRequestParameter('post_edit_title'));
            $_thread->save();
            $v = new Criteria();
            $v->add(PostPeer::THREAD_ID, $threadId);
            $v->addAscendingOrderByColumn(PostPeer::ID);
            $post = PostPeer::doSelectOne($v);
            $post->setContent($this->getRequestParameter('post_edit_content'));
            $post->save();
            return $this->redirect('@view_thread?thread_id=' . $threadId);
        }
        if ($this->getRequestParameter('post_body') != '') {
            if ($this->getRequestParameter('final_id') != '') {
                $_quick_reply = '';
                $_post_id = $this->getRequestParameter('final_id');
                $_Post = PostPeer::retrieveByPK($_post_id);
                $_User = UserPeer::retrieveByPK($_Post->getPosterId());
                $_quick_reply .= "<div style='margin-left:20px'><em><strong>Quote from " . $_User->getUsername() . "</strong></em><br><br>";
                $_explode_post = explode("*^-", $_Post->getContent());
                if (count($_explode_post) > 1) {
                    $_quick_reply .= $_explode_post[1];
                } else {
                    $_quick_reply .= $_Post->getContent();
                }
                $_quick_reply .= "</div>";
                $_post_body_msg = $this->getRequestParameter('post_body');
                $_quick_reply .= $_post_body_msg;
                $user->makeNewPost($this->getRequestParameter('thread_id'), $_quick_reply);
                ///////////////////updating the ip of the user
                $post_id = mysql_fetch_row(mysql_query("SELECT max(id) from post limit 0,1", $connection));
                mysql_query("update post set \tuser_ip='" . $_SERVER['REMOTE_ADDR'] . "' where id=" . $post_id[0] . "", $connection);
                ///////////////////updating the ip of the user
            } else {
                $user->makeNewPost($this->getRequestParameter('thread_id'), $this->getRequestParameter('post_body'));
                ///////////////////updating the ip of the user
                $post_id = mysql_fetch_row(mysql_query("SELECT max(id) from post limit 0,1", $connection));
                mysql_query("update post set \tuser_ip='" . $_SERVER['REMOTE_ADDR'] . "' where id=" . $post_id[0] . "", $connection);
                ///////////////////updating the ip of the user
            }
            if ($this->getUser()->getRaykuUser()->getType() == '5') {
                $c = new Criteria();
                $c->add(ThreadPeer::ID, $this->getRequestParameter('thread_id'));
                $thread = ThreadPeer::doSelectOne($c);
                $c = new Criteria();
                $c->add(UserPeer::ID, $thread->getPosterId());
                $user = UserPeer::doSelectOne($c);
                if ($thread->getNotifyPm() == '1') {
                    $subject = 'Expert Response for your Question';
                    $body = 'Hi there, <br><br>
							A Rayku expert, "' . $this->getUser()->getRaykuUser()->getName() . '" has just responsed to your question, "' . $thread->getTitle() . '" on the question boards. Take a look!<br><br>
							Rayku Administration';
                    //Grab the user object
                    $currentuser = UserPeer::retrieveByPK($this->getUser()->getRaykuUserId());
                    //Send the message
                    $currentuser->sendMessage($user->getId(), $subject, $body);
                }
                if ($thread->getNotifyEmail() == '1') {
                    $this->mail = new sfMail();
                    //Set the to, from, and subject headers
                    $this->mail->addAddress($user->getEmail());
                    $this->mail->setFrom('Expert <' . $this->getUser()->getRaykuUser()->getEmail() . '>');
                    $this->mail->setSubject('Expert Response to your Question');
                    $this->mail->setBody('Hi there,<br>
							A Rayku expert, "' . $this->getUser()->getRaykuUser()->getName() . '", has just responded to your question (below) on the question boards. Take a look!<br><br>
							' . $thread->getTitle() . '');
                    $this->mail->send();
                }
            }
            return $this->redirect('@view_thread?thread_id=' . $this->thread->getId());
        }
    }
Example #11
0
 public function execute($request)
 {
     $connection = RaykuCommon::getDatabaseConnection();
     $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id'];
     $currentUser = $this->getUser()->getRaykuUser();
     $userId = $currentUser->getId();
     $this->userId = $currentUser->getId();
     $time = time();
     if (empty($_SESSION["course_id"])) {
         $_SESSION["course_id"] = '1';
     }
     $this->cat = $this->getRequestParameter('category');
     $this->course_id = $this->getRequestParameter('course');
     if (empty($this->course_id)) {
         if (!empty($_SESSION['course_id'])) {
             $this->course_id = $_SESSION['course_id'];
         } else {
             $this->course_id = 1;
         }
     } else {
         $_SESSION['course_id'] = $this->course_id;
     }
     if (empty($this->cat)) {
         if (!empty($_SESSION['subject'])) {
             $this->cat = $_SESSION['subject'];
         } else {
             $this->cat = 1;
         }
     } else {
         $_SESSION['subject'] = $this->cat;
     }
     $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id'];
     $c = new Criteria();
     $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN);
     if ($this->cat == 5) {
         $experts = ExpertCategoryPeer::doSelect($c);
     } else {
         $c->add(ExpertCategoryPeer::CATEGORY_ID, $this->cat);
         $experts = ExpertCategoryPeer::doSelect($c);
     }
     $queryPoints = mysql_query("select * from user where id = " . $userId, $connection) or die("Error In rate" . mysql_error());
     if (mysql_num_rows($queryPoints) > 0) {
         $rowPoints = mysql_fetch_assoc($queryPoints);
         $_points = $rowPoints['points'];
     }
     $newUser = array();
     $i = 0;
     $eachExpertOnlyOnce = array();
     foreach ($experts as $exp) {
         if ($userId != $exp->getUserId()) {
             if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) {
                 continue;
             }
             $eachExpertOnlyOnce[] = $exp->getUserId();
             /* Testing - Student match with Tutors */
             $_queryCourse = '';
             $tutorsq = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "", $connection) or die("Er-1-->" . mysql_error());
             $tutors = mysql_fetch_array($tutorsq);
             $tutor = '';
             $tutor = explode("-", $tutors['course_id']);
             if (in_array($_SESSION["course_id"], $tutor)) {
                 $_queryCourse = mysql_query("select * from tutor_profile where category = 1 and user_id = " . $exp->getUserId() . "", $connection) or die("Er-1-->" . mysql_error());
                 //echo "select * from tutor_profile where category = 1 and user_id = ".$exp->getUserId()."";
             }
             if (@mysql_num_rows($_queryCourse) > 0) {
                 $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) {
                     if ($_points == '' || $_points == '0.00') {
                         $emptyRCquery = mysql_query("select * from user_rate where userid = " . $exp->getUserId() . " and (rate = 0.00 || rate = 0) ", $connection) or die("Error In rate" . mysql_error());
                         if (mysql_num_rows($emptyRCquery) > 0) {
                             $dv = new Criteria();
                             $dv->add(UserPeer::ID, $exp->getUserId());
                             $_thisUser = UserPeer::doSelectOne($dv);
                             $rankUsersFinal[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt());
                             $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt());
                             $i++;
                         }
                     } else {
                         $dv = new Criteria();
                         $dv->add(UserPeer::ID, $exp->getUserId());
                         $_thisUser = UserPeer::doSelectOne($dv);
                         $rankUsersFinal[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt());
                         $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt());
                         $i++;
                     }
                 }
             }
         }
     }
     asort($newUser);
     arsort($newUser);
     asort($rankUsersFinal);
     arsort($rankUsersFinal);
     $this->rankCheckUsers = $rankUsersFinal;
     ////if no online expert available redirecting to the board page
     // // ant-edit remove for now
     $onlineusers = array();
     $offlineusers = array();
     $newOnlineUser = array();
     $newOfflineUser = array();
     $j = 0;
     $k = 0;
     // $facebookTutors = BotServiceProvider::createFor("http://facebook.rayku.com/tutor")->getContent();
     // $onlineTutorsByNotificationBot = BotServiceProvider::createFor("http://notification-bot.rayku.com/tutor")->getContent();
     foreach ($newUser as $new) {
         $a = new Criteria();
         $a->add(UserPeer::ID, $new['userid']);
         $users_online = UserPeer::doSelectOne($a);
         $onlinecheck = '';
         if ($users_online->isOnline()) {
             $onlinecheck = "online";
         }
         // ant-edit remove for now
         if (empty($onlinecheck)) {
             $userGtalk = $users_online->getUserGtalk();
             if ($userGtalk) {
                 $onlinecheck = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $userGtalk->getGtalkid())->getContent();
                 // echo 'hello '  . $onlinecheck     ;
             }
         }
         // if (empty($onlinecheck) || ($onlinecheck != "online")) {
         //     $userFb = UserFbPeer::retrieveByUserId($new['userid']);
         //     if ($userFb) {
         //         $fb_username = $userFb->getFbUsername();
         //         $Users = json_decode($facebookTutors, true);
         //         foreach ($Users as $key => $user) {
         //             if ($user['username'] == $fb_username) {
         //                 $onlinecheck = 'online';
         //                 break;
         //             }
         //         }
         //     }
         // }
         // if (empty($onlinecheck) || ($onlinecheck != "online")) {
         //     $_Users = json_decode($onlineTutorsByNotificationBot, true);
         //     foreach ($_Users as $key => $_user) {
         //         if ($_user['email'] == $users_online->getEmail()) {
         //             $onlinecheck = 'online';
         //             break;
         //         }
         //     }
         // }
         if ($onlinecheck == "online") {
             $onlineusers[$j] = $new['userid'];
             $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']);
             $j++;
         } elseif ($users_online->isOnline()) {
             $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']);
             $onlineusers[$j] = $new['userid'];
             $j++;
         } else {
             $newOfflineUser[$k] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']);
             $offlineusers[$k] = $new['userid'];
             $k++;
         }
     }
     $this->newOnlineUser = $newOnlineUser;
     $this->newOfflineUser = $newOfflineUser;
     $this->_checkOnlineUsers = $onlineusers;
     if (count($onlineusers) < 1) {
         $this->redirect('/forum/newthread/' . $_SESSION['subject'] . '?exp_online = 1');
     }
     $onoff = isset($_COOKIE["onoff"]) ? $_COOKIE["onoff"] : null;
     if ($onoff == 1) {
         if (!empty($_COOKIE["school"])) {
             $cookieSchool = array();
             $m = 0;
             foreach ($newOnlineUser as $new) {
                 $b = new Criteria();
                 $b->add(UserPeer::ID, $new['userid']);
                 $schoolusers = UserPeer::doSelectOne($b);
                 $mail = explode("@", $schoolusers->getEmail());
                 $newMail = explode(".", $mail[1]);
                 if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) {
                     $cookieSchool[$m] = $new;
                     $m++;
                 }
             }
             $this->expert_cats = $cookieSchool;
         } else {
             $this->expert_cats = $newOnlineUser;
         }
     } else {
         if ($onoff == 2) {
             if (!empty($_COOKIE["school"])) {
                 $cookieSchool = array();
                 $m = 0;
                 foreach ($newOfflineUser as $new) {
                     $b = new Criteria();
                     $b->add(UserPeer::ID, $new['userid']);
                     $schoolusers = UserPeer::doSelectOne($b);
                     $mail = explode("@", $schoolusers->getEmail());
                     $newMail = explode(".", $mail[1]);
                     if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) {
                         $cookieSchool[$m] = $new;
                         $m++;
                     }
                 }
                 $this->expert_cats = $cookieSchool;
             } else {
                 $this->expert_cats = $newOfflineUser;
             }
         } else {
             if (!empty($_COOKIE["school"])) {
                 $cookieSchool = array();
                 $m = 0;
                 foreach ($newUser as $new) {
                     $b = new Criteria();
                     $b->add(UserPeer::ID, $new['userid']);
                     $schoolusers = UserPeer::doSelectOne($b);
                     $mail = explode("@", $schoolusers->getEmail());
                     $newMail = explode(".", $mail[1]);
                     if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) {
                         $cookieSchool[$m] = $new;
                         $m++;
                     }
                 }
                 $this->expert_cats = $cookieSchool;
             } else {
                 $this->expert_cats = $newUser;
             }
         }
     }
     $this->tutorsCount = count($this->expert_cats);
     $c = new Criteria();
     $c->add(CategoryPeer::ID, $this->cat);
     $this->e = CategoryPeer::doSelectOne($c);
 }
Example #12
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(CategoryPeer::ID, $pks, Criteria::IN);
         $objs = CategoryPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #13
0
$c = new Criteria();
$c->add(AttachmentPeer::NAME, $name);
$attachments = AttachmentPeer::doSelect($c);
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
$b->test()->ok($attachments[0]->getArticleId(), 'the attachment is tied to an article');
$b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database');
// sfValidatorPropelUnique
// create a category with a unique name
$b->get('/unique/category')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'category')->end()->with('response')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo')))->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->matches('/ok/')->end();
// create another category with the same name
// we must have an error
$b->get('/unique/category')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'category')->end()->with('response')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo')))->with('form')->begin()->hasErrors(1)->hasGlobalError(false)->isError('name', 'invalid')->end()->with('response')->begin()->checkElement('td[colspan="2"] .error_list li', 0)->checkElement('.error_list li', 'An object with the same "name" already exist.')->checkElement('.error_list li', 1)->end();
// same thing but with a global error
$b->get('/unique/category')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'category')->end()->with('response')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo'), 'global' => 1))->with('form')->begin()->hasErrors(1)->hasGlobalError('invalid')->isError('name', false)->end()->with('response')->begin()->checkElement('td[colspan="2"] .error_list li', 'An object with the same "name" already exist.')->checkElement('td[colspan="2"] .error_list li', 1)->end();
// updating the same category again with the same name is allowed
$b->get('/unique/category?category[id]=' . CategoryPeer::getByName('foo')->getId())->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'category')->end()->with('response')->isStatusCode(200)->click('submit')->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->matches('/ok/')->end();
// create an article with a unique title-category_id
$b->get('/unique/article')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'article')->end()->with('response')->isStatusCode(200)->click('submit', array('article' => array('title' => 'foo', 'category_id' => 1)))->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->matches('/ok/')->end();
// create another article with the same title but a different category_id
$b->get('/unique/article')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'article')->end()->with('response')->isStatusCode(200)->click('submit', array('article' => array('title' => 'foo', 'category_id' => 2)))->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->matches('/ok/')->end();
// create another article with the same title and category_id as the first one
// we must have an error
$b->get('/unique/article')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'article')->end()->with('response')->isStatusCode(200)->click('submit', array('article' => array('title' => 'foo', 'category_id' => 1)))->with('response')->checkElement('.error_list li', 'An object with the same "title, category_id" already exist.');
// update the category from the article form
$b->get('/unique/edit')->with('request')->begin()->isParameter('module', 'unique')->isParameter('action', 'edit')->end()->with('response')->begin()->isStatusCode(200)->checkElement('input[value="foo title"]')->checkElement('#article_category_id option[selected="selected"]', 1)->checkElement('input[value="Category 1"]')->end()->click('submit', array('article' => array('title' => 'foo bar', 'category' => array('name' => 'Category foo'))))->with('response')->begin()->isRedirected()->followRedirect()->end()->with('response')->begin()->checkElement('input[value="foo bar"]')->checkElement('#article_category_id option[selected="selected"]', 1)->checkElement('input[value="Category foo"]')->end();
// sfValidatorPropelChoice
// submit a form with an impossible choice validator
$b->get('/choice/article')->with('request')->begin()->isParameter('module', 'choice')->isParameter('action', 'article')->end()->with('response')->begin()->isStatusCode(200)->end()->click('submit', array('article' => array('title' => 'foobar', 'category_id' => 1, 'author_article_list' => array(1)), 'impossible_validator' => 1))->with('form')->begin()->hasErrors(1)->isError('category_id', 'invalid')->end();
// sfValidatorPropelChoice (multiple == true)
// submit a form with an impossible choice validator
$b->get('/choice/article')->with('request')->begin()->isParameter('module', 'choice')->isParameter('action', 'article')->end()->with('response')->begin()->isStatusCode(200)->end()->click('submit', array('article' => array('title' => 'foobar', 'category_id' => 1, 'author_article_list' => array(1)), 'impossible_validator_many' => 1))->with('form')->begin()->hasErrors(1)->isError('author_article_list', 'invalid')->end();
Example #14
0
AttachmentPeer::doDeleteAll();
$b->test()->ok(!file_exists($uploadedFile), 'uploaded file is deleted');
// file upload in embedded form
$b->getAndCheck('attachment', 'embedded')->with('response')->begin()->checkElement('input[name="article[attachment][article_id]"]', false)->checkElement('input[type="file"][name="article[attachment][file]"]')->end()->setField('article[title]', 'Test Article')->setField('article[attachment][name]', $name)->setField('article[attachment][file]', $fileToUpload)->click('submit')->with('form')->hasErrors(false)->isRedirected()->followRedirect()->with('response')->contains('ok');
$b->test()->ok(file_exists($uploadedFile), 'file is uploaded');
$b->test()->is(file_get_contents($uploadedFile), file_get_contents($fileToUpload), 'file is correctly uploaded');
$c = new Criteria();
$c->add(AttachmentPeer::NAME, $name);
$attachments = AttachmentPeer::doSelect($c);
$b->test()->is(count($attachments), 1, 'the attachment has been saved in the database');
$b->test()->ok($attachments[0]->getArticleId(), 'the attachment is tied to an article');
$b->test()->is($attachments[0]->getFile(), 'uploaded.yml', 'the attachment filename has been saved in the database');
// sfValidatorPropelUnique
// create a category with a unique name
$b->get('/unique/category')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo')))->isRedirected()->followRedirect()->responseContains('ok');
// create another category with the same name
// we must have an error
$b->get('/unique/category')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo')))->with('form')->begin()->hasErrors(1)->hasGlobalError(false)->isError('name', 'invalid')->end()->checkResponseElement('td[colspan="2"] .error_list li', 0)->checkResponseElement('.error_list li', 'An object with the same "name" already exist.')->checkResponseElement('.error_list li', 1);
// same thing but with a global error
$b->get('/unique/category')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit', array('category' => array('name' => 'foo'), 'global' => 1))->with('form')->begin()->hasErrors(1)->hasGlobalError('invalid')->isError('name', false)->end()->checkResponseElement('td[colspan="2"] .error_list li', 'An object with the same "name" already exist.')->checkResponseElement('td[colspan="2"] .error_list li', 1);
// updating the same category again with the same name is allowed
$b->get('/unique/category?category[id]=' . CategoryPeer::getByName('foo')->getId())->isRequestParameter('module', 'unique')->isRequestParameter('action', 'category')->isStatusCode(200)->click('submit')->isRedirected()->followRedirect()->responseContains('ok');
// create an article with a unique title-category_id
$b->get('/unique/article')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'article')->isStatusCode(200)->click('submit', array('article' => array('title' => 'foo', 'category_id' => 1)))->isRedirected()->followRedirect()->responseContains('ok');
// create another article with the same title but a different category_id
$b->get('/unique/article')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'article')->isStatusCode(200)->click('submit', array('article' => array('title' => 'foo', 'category_id' => 2)))->isRedirected()->followRedirect()->responseContains('ok');
// create another article with the same title and category_id as the first one
// we must have an error
$b->get('/unique/article')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'article')->isStatusCode(200)->click('submit', array('article' => array('title' => 'foo', 'category_id' => 1)))->checkResponseElement('.error_list li', 'An object with the same "title, category_id" already exist.');
// update the category from the article form
$b->get('/unique/edit')->isRequestParameter('module', 'unique')->isRequestParameter('action', 'edit')->isStatusCode(200)->checkResponseElement('input[value="foo title"]')->checkResponseElement('#article_category_id option[selected="selected"]', 1)->checkResponseElement('input[value="Category 1"]')->click('submit', array('article' => array('title' => 'foo bar', 'category' => array('name' => 'Category foo'))))->isRedirected()->followRedirect()->checkResponseElement('input[value="foo bar"]')->checkResponseElement('#article_category_id option[selected="selected"]', 1)->checkResponseElement('input[value="Category foo"]');
Example #15
0
 public function getCategory(PropelPDO $con = null)
 {
     if ($this->aCategory === null && $this->category_id !== null) {
         $c = new Criteria(CategoryPeer::DATABASE_NAME);
         $c->add(CategoryPeer::ID, $this->category_id);
         $this->aCategory = CategoryPeer::doSelectOne($c, $con);
     }
     return $this->aCategory;
 }
Example #16
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'frontend';
$fixtures = 'fixtures/fixtures.yml';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestFunctional(new sfBrowser(), null, array('propel' => 'sfTesterPropel'));
ArticlePeer::doDeleteAll();
$c = CategoryPeer::doSelectOne(new Criteria());
$hash = spl_object_hash($c);
$b->get('/pooling/addArticleButDontSave/category_id/' . $c->getId())->with('propel')->check('Article', null, 0)->get('/pooling/addArticleAndSave/category_id/' . $c->getId())->with('propel')->check('Article', null, 1);
Example #17
0
 public function executeProductCategoriesList()
 {
     $this->setLayout(false);
     $c = new Criteria();
     $this->categories = CategoryPeer::doSelect($c);
     $prodNum = array();
     foreach ($this->categories as $cat) {
         $id = $cat->getId();
         $products = Document::getChildrenOf($cat, "Product", false);
         // count ACTIVE childrens
         $cnt = 0;
         foreach ($products as $product) {
             if ($product->getPublicationStatus() == UtilsHelper::STATUS_ACTIVE) {
                 $cnt++;
             }
         }
         $prodNum[$id] = $cnt;
     }
     $this->prodNum = $prodNum;
     $this->currentId = $this->getRequestParameter("Category_id");
 }
Example #18
0
 public static function doSelectJoinAllExceptBook(Criteria $c, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     ArticlePeer::addSelectColumns($c);
     $startcol2 = ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS;
     CategoryPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + (CategoryPeer::NUM_COLUMNS - CategoryPeer::NUM_LAZY_LOAD_COLUMNS);
     $c->addJoin(array(ArticlePeer::CATEGORY_ID), array(CategoryPeer::ID), $join_behavior);
     $stmt = BasePeer::doSelect($c, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = ArticlePeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = ArticlePeer::getInstanceFromPool($key1))) {
         } else {
             $omClass = ArticlePeer::getOMClass();
             $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             ArticlePeer::addInstanceToPool($obj1, $key1);
         }
         $key2 = CategoryPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = CategoryPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $omClass = CategoryPeer::getOMClass();
                 $cls = substr('.' . $omClass, strrpos('.' . $omClass, '.') + 1);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 CategoryPeer::addInstanceToPool($obj2, $key2);
             }
             $obj2->addArticle($obj1);
         }
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
Example #19
0
 public static function doSelectJoinAllExceptBook(Criteria $c, $con = null)
 {
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     ArticlePeer::addSelectColumns($c);
     $startcol2 = ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS + 1;
     CategoryPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + CategoryPeer::NUM_COLUMNS;
     $c->addJoin(ArticlePeer::CATEGORY_ID, CategoryPeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $omClass = ArticlePeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj1 = new $cls();
         $obj1->hydrate($rs);
         $omClass = CategoryPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj2 = new $cls();
         $obj2->hydrate($rs, $startcol2);
         $newObject = true;
         for ($j = 0, $resCount = count($results); $j < $resCount; $j++) {
             $temp_obj1 = $results[$j];
             $temp_obj2 = $temp_obj1->getCategory();
             if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj2->addArticle($obj1);
                 break;
             }
         }
         if ($newObject) {
             $obj2->initArticles();
             $obj2->addArticle($obj1);
         }
         $results[] = $obj1;
     }
     return $results;
 }
Example #20
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 = CategoryPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setName($arr[$keys[1]]);
     }
 }
$finder = sfPropelFinder::from('Category')->
  select(array('Id','Name'), sfModelFinder::SIMPLE);
$category = $finder->findOne();
$t->is_deeply(array_keys($category), array(0, 1), 'The row returned by findOne() called after select(array, sfModelFinder::SIMPLE) is an array with numeric keys');
$t->is($category[0], $category1->getId(), 'The row returned by findOne() called after select(array, sfModelFinder::SIMPLE) is an array where the values are the requested column values');
$t->is($category[1], $category1->getName(), 'The row returned by findOne() called after select(array, sfModelFinder::SIMPLE) is an array where the values are the requested column values');

/*********************************************/
/* sfPropelFinder::select() and withColumn() */
/*********************************************/

$t->diag('sfPropelFinder::select() and withColumn()');

ArticlePeer::doDeleteAll();
CategoryPeer::doDeleteAll();
$category1 = new Category();
$category1->setName('cat1');
$category1->save();
$category2 = new Category();
$category2->setName('cat2');
$category2->save();
$article1 = new Article();
$article1->setTitle('art1');
$article1->setCategory($category1);
$article1->save();
$article2 = new Article();
$article2->setTitle('art2');
$article2->setCategory($category2);
$article2->save();
$article3 = new Article();
Example #22
0
 /**
  * Get the associated Category object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     Category The associated Category object.
  * @throws     PropelException
  */
 public function getCategory(PropelPDO $con = null)
 {
     if ($this->aCategory === null && $this->category_id !== null) {
         $this->aCategory = CategoryPeer::retrieveByPk($this->category_id);
         /* 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->aCategory->addArticles($this);
         		 */
     }
     return $this->aCategory;
 }
Example #23
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 = CategoryPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setParentId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setHeader($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setName($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setDescription($arr[$keys[4]]);
     }
 }
Example #24
0
    ?>
            <?php 
    if ($pager->haveToPaginate()) {
        ?>
              <?php 
        echo __('(page %%page%%/%%nb_pages%%)', array('%%page%%' => $pager->getPage(), '%%nb_pages%%' => $pager->getLastPage()), 'sf_admin');
        ?>
            <?php 
    }
    ?>
          </th>
        </tr>
      </tfoot>
      <tbody>
		<?php 
    $categorys = CategoryPeer::getAllSub();
    ?>
        <?php 
    foreach ($pager->getResults() as $i => $Category) {
        $odd = fmod(++$i, 2) ? 'odd' : 'even';
        ?>
          <tr class="sf_admin_row <?php 
        echo $odd;
        ?>
">
            <?php 
        include_partial('category/list_td_stacked', array('Category' => $Category));
        ?>
			<?php 
        include_partial('category/list_td_actions', array('Category' => $Category, 'helper' => $helper));
        ?>
Example #25
0
 /**
  * all members database
  */
 public function execute($request)
 {
     RaykuCommon::getDatabaseConnection();
     $logedUserId = $_SESSION['symfony/user/sfUser/attributes']['symfony/user/sfUser/attributes']['user_id'];
     $currentUser = $this->getUser()->getRaykuUser();
     $userId = $currentUser->getId();
     $this->userId = $currentUser->getId();
     /* Clearing Cookies 
     
               if($_COOKIE['onoff'] != 1) {
     
               for($u=$_COOKIE['cookcount'];$u>=1;$u--) {
     
               $cookname =  'tutor_'.$u;
     
               setcookie($cookname,'', time()-3600, "/");
     
               }
     
               setcookie("tutorcount",'', time()-3600, "/");
               setcookie("cookcount",'', time()-3600, "/");
     
               }
     
               /* Clearing Cookies */
     $time = time();
     if (!empty($_POST['hidden'])) {
         $count = count($_POST['checkbox']);
         /* Clearing Cookies */
         for ($u = $_COOKIE['cookcount']; $u >= 1; $u--) {
             $cookname = 'tutor_' . $u;
             $this->getResponse()->setCookie($cookname, '', time() - 3600, '/', sfConfig::get('app_cookies_domain'));
         }
         $this->getResponse()->setCookie("tutorcount", '', time() - 3600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("cookcount", '', time() - 3600, '/', sfConfig::get('app_cookies_domain'));
         /* Clearing Cookies */
         if ($count == 4) {
             $close = 46000;
             $_SESSION['connected_tutors'] = 4;
         }
         if ($count == 3) {
             $close = 46000;
             $_SESSION['connected_tutors'] = 3;
         } else {
             if ($count == 2) {
                 $close = 61000;
                 $_SESSION['connected_tutors'] = 2;
             } else {
                 if ($count == 1) {
                     $close = 61000;
                     $_SESSION['connected_tutors'] = 1;
                 } else {
                     $close = 61000;
                     $_SESSION['connected_tutors'] = 1;
                 }
             }
         }
         $j = 0;
         for ($i = 0; $i < $count; $i++) {
             mysql_query("INSERT INTO `user_expert` (`user_id`, `checked_id`, `category_id`, `question`, `exe_order`, `time`, status, close) VALUES ('" . $userId . "', '" . $_POST['checkbox'][$i] . "', '5', 'To be discussed','" . ++$j . "', '" . $time . "', 1, " . $close . ") ") or die(mysql_error());
         }
         /* Notify same tutor again */
         $l = 0;
         $source = 'tutorlist';
         mysql_query("DELETE FROM `student_questions` WHERE user_id=" . $userId . "");
         for ($i = 0; $i < $count; $i++) {
             mysql_query("INSERT INTO `student_questions` (`user_id`, `checked_id`, `category_id`, `question`, `exe_order`, `time`, status, close, source) VALUES ('" . $userId . "', '" . $_POST['checkbox'][$i] . "', '5', 'To be discussed','" . ++$l . "', '" . $time . "', 1, " . $close . ", '" . $source . "') ") or die(mysql_error());
         }
         setcookie("asker_que", $_SESSION['question'], time() + 600, "/", sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("redirection", 1, time() + 600, '/', sfConfig::get('app_cookies_domain'));
         $this->getResponse()->setCookie("forumsub", 1, time() + 600, '/', sfConfig::get('app_cookies_domain'));
         $this->redirect('expertmanager/connect');
     }
     $this->cat = $this->getRequestParameter('category');
     $this->course_id = $this->getRequestParameter('course');
     if (empty($this->course_id)) {
         $this->course_id = 1;
     }
     if (empty($this->cat)) {
         $this->cat = 1;
     }
     $queryPoints = mysql_query("select * from user where id=" . $userId) or die("Error In rate" . mysql_error());
     if (mysql_num_rows($queryPoints) > 0) {
         $rowPoints = mysql_fetch_assoc($queryPoints);
         $_points = $rowPoints['points'];
     }
     $c = new Criteria();
     $c->addJoin(ExpertCategoryPeer::USER_ID, UserTutorPeer::USERID, Criteria::INNER_JOIN);
     if ($this->cat == 5) {
         $experts = ExpertCategoryPeer::doSelect($c);
     } else {
         $c->add(ExpertCategoryPeer::CATEGORY_ID, $this->cat);
         $experts = ExpertCategoryPeer::doSelect($c);
     }
     $newUser = array();
     $i = 0;
     $eachExpertOnlyOnce = array();
     foreach ($experts as $exp) {
         if (in_array($exp->getUserId(), $eachExpertOnlyOnce)) {
             continue;
         }
         $eachExpertOnlyOnce[] = $exp->getUserId();
         $_queryCourse = mysql_query("select * from expert_course where user_id =" . $exp->getUserId() . " and category_id = 1 and course_id = " . $this->course_id . " ") or die("Er-1-->" . mysql_error());
         if (mysql_num_rows($_queryCourse) > 0) {
             $query = mysql_query("select * from user_score where user_id=" . $exp->getUserId()) or die(mysql_error());
             $score = mysql_fetch_assoc($query);
             if ($score['score'] != 0) {
                 if (false) {
                     //$_points == '' || $_points == '0.00'     Temporary hack
                     $emptyRCquery = mysql_query("select * from user_rate where userid=" . $exp->getUserId() . " and (rate = 0.00 || rate = 0) ") or die("Error In rate" . mysql_error());
                     if (mysql_num_rows($emptyRCquery) > 0) {
                         $dv = new Criteria();
                         $dv->add(UserPeer::ID, $exp->getUserId());
                         $_thisUser = UserPeer::doSelectOne($dv);
                         $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt());
                         $i++;
                     }
                 } else {
                     $dv = new Criteria();
                     $dv->add(UserPeer::ID, $exp->getUserId());
                     $_thisUser = UserPeer::doSelectOne($dv);
                     $newUser[$i] = array("score" => $score['score'], "userid" => $exp->getUserId(), "category" => $this->cat, "createdat" => $_thisUser->getCreatedAt());
                     $i++;
                 }
             }
         }
     }
     asort($newUser);
     arsort($newUser);
     $this->rankCheckUsers = $newUser;
     ////if no online expert available redirecting to the board page
     $onlineusers = array();
     $offlineusers = array();
     $newOnlineUser = array();
     $newOfflineUser = array();
     $j = 0;
     $k = 0;
     $facebookResponse = BotServiceProvider::createFor(sfConfig::get('app_facebook_url') . "/tutor")->getContent();
     $facebookUsers = json_decode($facebookResponse, true);
     $botResponse = BotServiceProvider::createFor(sfConfig::get('app_notification_bot_url') . "/tutor")->getContent();
     $botUsers = json_decode($botResponse, true);
     foreach ($newUser as $new) {
         $a = new Criteria();
         $a->add(UserPeer::ID, $new['userid']);
         $users_online = UserPeer::doSelectOne($a);
         $onlinecheck = '';
         if ($users_online->isOnline()) {
             $onlinecheck = "online";
         }
         if (empty($onlinecheck)) {
             $userGtalk = $users_online->getUserGtalk();
             if ($userGtalk) {
                 $onlinecheck = BotServiceProvider::createFor(sfConfig::get('app_rayku_url') . ':' . sfConfig::get('app_g_chat_port') . '/status/' . $userGtalk->getGtalkid())->getContent();
             }
         }
         if ((empty($onlinecheck) || $onlinecheck != "online") && is_array($facebookUsers)) {
             $fb_query = mysql_query("select * from user_fb where userid=" . $new['userid']) or die(mysql_error());
             if (mysql_num_rows($fb_query) > 0) {
                 $fbRow = mysql_fetch_assoc($fb_query);
                 $fb_username = $fbRow['fb_username'];
                 foreach ($facebookUsers as $key => $user) {
                     if ($user['username'] == $fb_username) {
                         $onlinecheck = 'online';
                         break;
                     }
                 }
             }
         }
         if ((empty($onlinecheck) || $onlinecheck != "online") && is_array($botUsers)) {
             foreach ($botUsers as $key => $_user) {
                 if ($_user['email'] == $users_online->getEmail()) {
                     $onlinecheck = 'online';
                     break;
                 }
             }
         }
         if ($onlinecheck == "online") {
             $onlineusers[$j] = $new['userid'];
             $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']);
             $j++;
         } elseif ($users_online->isOnline()) {
             $newOnlineUser[$j] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']);
             $onlineusers[$j] = $new['userid'];
             $j++;
         } else {
             $newOfflineUser[$k] = array("score" => $new['score'], "userid" => $new['userid'], "category" => $new['category'], "createdat" => $new['createdat']);
             $offlineusers[$k] = $new['userid'];
             $k++;
         }
     }
     $this->newOnlineUser = $newOnlineUser;
     $this->newOfflineUser = $newOfflineUser;
     $this->_checkOnlineUsers = $onlineusers;
     /////////////////////////////////////////////////////
     if (isset($_COOKIE["onoff"]) && $_COOKIE["onoff"] == 1) {
         if (!empty($_COOKIE["school"])) {
             $cookieSchool = array();
             $m = 0;
             foreach ($newOnlineUser as $new) {
                 $b = new Criteria();
                 $b->add(UserPeer::ID, $new['userid']);
                 $schoolusers = UserPeer::doSelectOne($b);
                 $mail = explode("@", $schoolusers->getEmail());
                 $newMail = explode(".", $mail[1]);
                 if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) {
                     $cookieSchool[$m] = $new;
                     $m++;
                 }
             }
             $this->expert_cats = $cookieSchool;
         } else {
             $this->expert_cats = $newOnlineUser;
         }
     } else {
         if (isset($_COOKIE["onoff"]) && $_COOKIE["onoff"] == 2) {
             if (!empty($_COOKIE["school"])) {
                 $cookieSchool = array();
                 $m = 0;
                 foreach ($newOfflineUser as $new) {
                     $b = new Criteria();
                     $b->add(UserPeer::ID, $new['userid']);
                     $schoolusers = UserPeer::doSelectOne($b);
                     $mail = explode("@", $schoolusers->getEmail());
                     $newMail = explode(".", $mail[1]);
                     if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) {
                         $cookieSchool[$m] = $new;
                         $m++;
                     }
                 }
                 $this->expert_cats = $cookieSchool;
             } else {
                 $this->expert_cats = $newOfflineUser;
             }
         } else {
             if (!empty($_COOKIE["school"])) {
                 $cookieSchool = array();
                 $m = 0;
                 foreach ($newUser as $new) {
                     $b = new Criteria();
                     $b->add(UserPeer::ID, $new['userid']);
                     $schoolusers = UserPeer::doSelectOne($b);
                     $mail = explode("@", $schoolusers->getEmail());
                     $newMail = explode(".", $mail[1]);
                     if ($newMail[0] == $_COOKIE["school"] || $newMail[1] == $_COOKIE["school"]) {
                         $cookieSchool[$m] = $new;
                         $m++;
                     }
                 }
                 $this->expert_cats = $cookieSchool;
             } else {
                 $this->expert_cats = $newUser;
             }
         }
     }
     $this->tutorsCount = count($this->expert_cats);
     $c = new Criteria();
     $c->add(CategoryPeer::ID, $this->cat);
     $this->e = CategoryPeer::doSelectOne($c);
 }
Example #26
0
 public function executeIndex(sfWebRequest $request)
 {
     $this->parentCategory = CategoryPeer::getAllParent();
     $this->subCategory = CategoryPeer::getAllSub();
 }
Example #27
0
    ?>
		<?php 
    include_partial('category/form_field', array('name' => $name, 'attributes' => $field->getConfig('attributes', array()), 'label' => $field->getConfig('label'), 'help' => $field->getConfig('help'), 'form' => $form, 'field' => $field, 'class' => 'sf_admin_form_row sf_admin_' . strtolower($field->getType()) . ' sf_admin_form_field_' . $name));
    ?>
	<?php 
}
?>
	
	<div class="sf_admin_form_row sf_admin_text sf_admin_form_field_parent_id">
		<div>
			<label for="category_parent_id">Родительская категория</label>
			<div class="content">
				<select name="category[parent_id]" id="category_parent_id" size="1" onChange="add_preference_control()">
					<option value="0"> нет родительской категории</option>
					<?php 
foreach (CategoryPeer::getAllParent() as $key => $parent) {
    ?>
						<?php 
    if ($Category->getId() != $parent->getId()) {
        ?>
							<option value="<?php 
        echo $parent->getId();
        ?>
" <?php 
        echo $Category->getParentId() == $parent->getId() ? 'selected' : '';
        ?>
> &mdash; <?php 
        echo $parent->getHeader();
        ?>
</option>
						<?php 
 /**
  * Test xxxNestedSet::getDescendantsTwice()
  */
 public function testPeerGetDescendantsTwice()
 {
     $nodesWithoutPool = array();
     $nodesWithPool = array();
     CategoryPeer::clearInstancePool();
     $cat = CategoryPeer::retrieveRoot(1);
     $children = $cat->getDescendants();
     foreach ($children as $child) {
         $nodesWithoutPool[] = $child->getTitle();
     }
     $cat = CategoryPeer::retrieveRoot(1);
     $children = $cat->getDescendants();
     foreach ($children as $child) {
         $nodesWithPool[] = $child->getTitle();
     }
     $this->assertEquals($nodesWithoutPool, $nodesWithPool, 'Retrieved nodes must be the same with and without InstancePooling');
 }
Example #29
0
  with('response')->isStatusCode(200)->
  click('submit', array('category' => array('name' => 'foo'), 'global' => 1))->
  with('form')->begin()->
    hasErrors(1)->
    hasGlobalError('invalid')->
    isError('name', false)->
  end()->
  with('response')->begin()->
    checkElement('td[colspan="2"] .error_list li', 'An object with the same "name" already exist.')->
    checkElement('td[colspan="2"] .error_list li', 1)->
  end()
;

// updating the same category again with the same name is allowed
$b->
  get('/unique/category?category[id]='.CategoryPeer::getByName('foo')->getId())->
  with('request')->begin()->
    isParameter('module', 'unique')->
    isParameter('action', 'category')->
  end()->
  with('response')->isStatusCode(200)->
  click('submit')->
  with('response')->begin()->
    isRedirected()->
    followRedirect()->
  end()->
  with('response')->begin()->
    matches('/ok/')->
  end()
;
Example #30
0
 public function getCategory($con = null)
 {
     if ($this->aCategory === null && $this->category_id !== null) {
         include_once 'lib/model/om/BaseCategoryPeer.php';
         $this->aCategory = CategoryPeer::retrieveByPK($this->category_id, $con);
     }
     return $this->aCategory;
 }