public function getTopic() { if (!$this->topic) { $topicManager = new TopicManager($this->db); $this->topic = $topicManager->findById($this->id_topic); } return $this->topic; }
function OnLoadPageData() { $authentication_manager = $this->GetAuthenticationManager(); $authentication_manager->ReadUserById(array($this->user->GetId())); $this->user = $authentication_manager->GetFirst(); if (!is_null($this->user)) { $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection()); $this->a_messages = $topic_manager->ReadMessagesByUser($this->user->GetId()); unset($topic_manager); } else { http_response_code(404); } }
public function OnPostback() { # If there's no id, ensure no match object is created. Page will then display a "match not found" message. # There's a separate page for adding matches, even for admins. if (!$this->editor->GetDataObjectId()) { return; } # Get the submitted match $this->match = $this->editor->GetDataObject(); # Because this is a new request, we need to reverify whether this is the match owner before letting anything happen. # Can't trust that info from a postback so MUST go to the database to check it. $this->match_manager->ReadByMatchId(array($this->editor->GetDataObjectId())); $check_match = $this->match_manager->GetFirst(); $this->b_user_is_match_owner = ($check_match instanceof Match and AuthenticationManager::GetUser()->GetId() == $check_match->GetAddedBy()->GetId()); # Don't wan't to edit tournaments on this page, so even as admin make sure we're not trying to save one. # Can't change the match type, so find out what that is from the db too. $this->b_is_tournament = $check_match->GetMatchType() == MatchType::TOURNAMENT; # Check whether cancel was clicked if ($this->editor->CancelClicked()) { # If so, get the match's short URL and redirect $this->match_manager->ExpandMatchUrl($this->match); $this->Redirect($this->match->GetNavigateUrl()); } # save data if valid if ($this->IsValid() and !$this->b_is_tournament) { # Save player of match $this->match_manager->SaveHighlights($this->match); $this->match_manager->ExpandMatchUrl($this->match); # Add comment if provided if (trim($this->match->GetNewComment())) { require_once 'forums/topic-manager.class.php'; require_once 'forums/review-item.class.php'; require_once 'forums/subscription-manager.class.php'; $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection()); $item_to_comment_on = new ReviewItem($this->GetSettings()); $item_to_comment_on->SetType(ContentType::STOOLBALL_MATCH); $item_to_comment_on->SetId($this->match->GetId()); $item_to_comment_on->SetNavigateUrl("https://" . $this->GetSettings()->GetDomain() . $this->match->GetNavigateUrl()); $message = $topic_manager->SaveComment($item_to_comment_on, $this->match->GetNewComment()); # send subscription emails $subs_manager = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection()); $subs_manager->SendCommentsSubscriptions($item_to_comment_on, $message); unset($subs_manager); } # Match may have been updated so send an email $this->match_manager->NotifyMatchModerator($this->match->GetId()); # Show user the match, so they can see update was applied $this->Redirect($this->match->GetNavigateUrl()); } }
public function testGetSubProtocolsBubbles() { $subs = array('hello', 'world'); $app = $this->getMock('Ratchet\\Wamp\\Stub\\WsWampServerInterface'); $app->expects($this->once())->method('getSubProtocols')->will($this->returnValue($subs)); $mngr = new TopicManager($app); $this->assertEquals($subs, $mngr->getSubProtocols()); }
<?php $topicManager = new TopicManager($db); $topic = $topicManager->findById($_GET['id']); $userManager = new UserManager($db); $userTopic = $userManager->findById($topic->getIdAuthor()); try { $test = $topicManager->addVue($topic->getId()); $link = $userManager->deletLink($_SESSION['id'], $topic->getId()); } catch (Exception $e) { $errors = $e->getMessage(); echo $errors; } require "views/forum/topic.phtml";
<?php if (isset($_GET['id'])) { if (isset($_SESSION['id'])) { $manager = new TopicManager($db); $topic = $manager->findById(intval($_GET['id'])); if (is_string($topic)) { header('Location: index.php?page=error_404'); exit; } else { require 'views/create_post.phtml'; } } else { header('Location: index.php?page=login'); exit; } } else { header('Location: index.php?page=error_404'); exit; }
<?php if (isset($_GET['page'])) { $action = $_GET['page']; if ($action == 'addTopic') { if (isset($_POST['title'], $_POST['content'])) { $manager = new SCategoryManager($db); $sCategory = $manager->findById($_GET['id']); $idSCategory = $sCategory->getId(); if (isset($idSCategory)) { $managerTopic = new TopicManager($db); $idAuthor = $_SESSION['id']; try { $retour = $managerTopic->create($_POST['title'], $idAuthor, $sCategory); } catch (Exception $e) { $errors = $e->getMessage(); } $managerPost = new PostManager($db); $lastTopic = $managerTopic->getLast(); $lastTopicIdSCategory = $lastTopic->getIdSCategory(); $manager = new SCategoryManager($db); $sCategory = $manager->findById($lastTopicIdSCategory); try { $retour = $managerPost->create($_POST['content'], $idAuthor, $lastTopic, $sCategory); } catch (Exception $e) { $errors = $e->getMessage(); } $managerUser = new UserManager($db); try { $retour = $managerUser->addTopicUser($lastTopic); header('Location: index.php?page=XtopicX&id=' . $lastTopic->getId() . '');
public function create($idTopic, $content) { $post = new Post(); $set = $post->setContent($content); if ($set === true) { $manager = new TopicManager($this->db); $topic = $manager->findById($idTopic); $set = $post->setIdTopic($topic); if ($set === true) { if (isset($_SESSION['id'])) { $manager = new UserManager($this->db); $user = $manager->getCurrent(); $set = $post->setIdAuthor($user); if ($set === true) { $idAuthor = intval($user->getId()); $idTopic = intval($post->getIdTopic()); $content = mysqli_real_escape_string($this->db, $post->getContent()); $query = "INSERT INTO post (id_author, id_topic, content) VALUES (" . $idAuthor . ", " . $idTopic . ", '" . $content . "')"; $result = mysqli_query($this->db, $query); if ($result) { $id = mysqli_insert_id($this->db); if ($id) { return $this->findById($id); } else { return "Erreur serveur."; } } else { return mysqli_error(); } } else { return $set; } } else { return "Utilisateur déconnecté."; } } else { return $set; } } else { return $set; } }
<?php $manager = new PostManager($db); $postCount = count($manager->getList($_GET['id'])); if (isset($_GET['id'])) { $postPerPage = 10; $manager = new TopicManager($db); $topic = $manager->findById($_GET['id']); if (isset($_GET['p'])) { $pN = intval($_GET['p']); } else { $pN = 1; } $p = $pN - 1; $min = $p * $postPerPage; $max = $min + $postPerPage; require 'views/topic.phtml'; } else { require 'views/home.phtml'; } ?> <?php /* $i = 0; while (isset($listTopic[$i])) { $topic = $listTopic[$i]; require('views/topic.phtml'); $i++; }*/
<?php $topicManager = new TopicManager($db); $listTopic = $topicManager->GetByIdSousRubrique($_GET['id']); $i = 0; while (isset($listTopic[$i])) { $topic = $listTopic[$i]; $userManager = new UserManager($db); $author = $userManager->findById($topic->getIdAuthor()); if (is_object($author)) { require 'views/topics.phtml'; } else { var_dump('Topic "' . $topic->getTitle() . '": ' . $author); } $i++; }
$post = $PostManager->create($idTopic, $content); if (is_string($post)) { var_dump($post); exit; $errors[] = $post; } else { header('Location: ?page=create_topic&id=1'); exit; } } } else { header('Location : ?page=error_404'); } } if (isset($_GET['action']) && $_GET['action'] == 'edit') { $manager = new TopicManager($db); $topic = $manager->findById($_GET['id']); if ($topic->getId() == $currentUser->getId()) { if (isset($_POST['title'])) { $id = intval($_GET['id']); $title = $_POST['title']; $topic = $manager->editTitle($title, $id); if (is_string($topic)) { $errors[] = $topic; } else { header('Location: index.php?page=topic&id=' . $_GET['id'] . ''); } } } } ?>
<?php $topicManager = new TopicManager($db); $topics = $topicManager->getList($_GET['id']); $userManager = new UserManager($db); $postManager = new PostManager($db); $i = 0; $c = count($topics); while ($i < $c) { $topic = $topics[$i]; $link = $userManager->findLink($_SESSION['id'], $topic->getId()); $userTopic = $userManager->findById($topic->getIdAuthor()); $lastPost = $postManager->getLastByTopic($topic->getId()); if ($lastPost == TRUE) { $userLastPost = $userManager->findById($lastPost->getIdAuthor()); $posts = $postManager->getList($topic->getId()); $Nrep = count($posts) - 1; } require 'views/forum/topics.phtml'; $i++; }
<?php $manager = new TopicManager($db); $topicList = $manager->getByIdSousRubrique($sousRubrique->getId()); if (!empty($topicList)) { $topic = $topicList[0]; if (is_object($topic)) { $manager = new PostManager($db); $postCount = count($manager->getList($topic->getId())); $postList = $manager->getList($topic->getId(), $postCount - 1, $postCount); $lastPage = ceil($postCount / 10); if (!empty($postList)) { for ($k = 0; $k < count($postList); $k++) { if (isset($postList[$k])) { $lastPost = $postList[$k]; if (is_string($lastPost)) { require 'views/no_last_post.phtml'; } else { $author = $manager->getAuthor($lastPost); $date = date('d M à H:i', strtotime($lastPost->getDate())); require 'views/last_post.phtml'; } } } } else { require 'views/no_last_post.phtml'; } } else { require 'views/no_last_post.phtml'; } } else {
function SavePostedComments(TopicManager $topic_manager) { /* @var $message ForumMessage */ if (trim($_POST['message']) and !$this->IsRefresh()) { $message = $topic_manager->SaveComment($this->review_item, $_POST['message']); # send subscription emails require_once 'forums/subscription-manager.class.php'; $o_subs = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection()); $o_subs->SendCommentsSubscriptions($this->review_item, $message); # add subscription if appropriate if (isset($_POST['subscribe'])) { $o_subs->SaveSubscription($this->review_item->GetId(), $this->review_item->GetType(), AuthenticationManager::GetUser()->GetId()); } } }
function OnLoadPageData() { /* @var $o_match Match */ /* @var $o_team Team */ # new data manager $match_manager = new MatchManager($this->GetSettings(), $this->GetDataConnection()); # create repeater control, and save any posted data $this->repeater = new DataEditRepeater($this, 'CreateEditControl'); $this->repeater->SetCssClass('matchResults'); $this->repeater->SetPersistedParameters(array('team', 'season', "tournament")); $this->repeater->SetButtonText('Save all results'); $this->repeater->SetShowButtonsAtTop(true); if ($this->IsPostback() and !$this->IsRefresh() and $this->IsValid()) { require_once 'forums/topic-manager.class.php'; require_once 'forums/review-item.class.php'; require_once 'forums/subscription-manager.class.php'; $topic_manager = new TopicManager($this->GetSettings(), $this->GetDataConnection()); foreach ($this->repeater->GetDataObjects() as $o_current_match) { /* @var $o_current_match Match */ $match_manager->SaveResult($o_current_match); $match_manager->ExpandMatchUrl($o_current_match); $match_manager->NotifyMatchModerator($o_current_match->GetId()); if (trim($o_current_match->GetNewComment())) { $item_to_comment_on = new ReviewItem($this->GetSettings()); $item_to_comment_on->SetType(ContentType::STOOLBALL_MATCH); $item_to_comment_on->SetId($o_current_match->GetId()); $item_to_comment_on->SetNavigateUrl("https://" . $this->GetSettings()->GetDomain() . $o_current_match->GetNavigateUrl()); $message = $topic_manager->SaveComment($item_to_comment_on, $o_current_match->GetNewComment()); # send subscription emails - new object each time to reset list of who's already recieved an email $subs_manager = new SubscriptionManager($this->GetSettings(), $this->GetDataConnection()); $subs_manager->SendCommentsSubscriptions($item_to_comment_on, $message); unset($subs_manager); } } $this->b_saved = true; } # get matches if (!is_null($this->i_team_id)) { $a_season_times = Season::SeasonDates(); $match_manager->FilterByTeam(array($this->i_team_id)); $match_manager->FilterByDateStart($a_season_times[0]); $match_manager->FilterByDateEnd($a_season_times[1]); $match_manager->ReadMatchSummaries(); } else { if (!is_null($this->i_season_id)) { $match_manager->ReadBySeasonId(array($this->i_season_id), true); } else { if (!is_null($this->tournament_id)) { $match_manager->FilterByTournament($this->tournament_id); $this->a_matches = $match_manager->ReadMatchSummaries(); } } } $this->a_matches = $match_manager->GetItems(); # Make sure we have some matches if (count($this->a_matches)) { # If it's matches for a team, get the team if (!is_null($this->i_team_id)) { # Should only need to look at the first match, because the team must be a # part of that match in order for the match to be in this list $o_match =& $this->a_matches[0]; $o_team = $o_match->GetHomeTeam(); if ($o_team instanceof Team and $o_team->GetId() == $this->i_team_id) { $this->team = $o_team; } else { foreach ($o_match->GetAwayTeams() as $o_team) { if ($o_team->GetId() == $this->i_team_id) { $this->team = $o_team; break; } } } if (!is_object($this->team)) { $this->Redirect(); } # Now that we have short URL data, if data has just been saved for team, redirect back to team if ($this->b_saved) { $this->Redirect($this->team->GetNavigateUrl()); } } else { if (!is_null($this->i_season_id)) { # get details of the season require_once 'stoolball/competition-manager.class.php'; $o_comp_manager = new CompetitionManager($this->GetSettings(), $this->GetDataConnection()); $o_comp_manager->ReadById(null, array($this->i_season_id)); $o_competition = $o_comp_manager->GetFirst(); unset($o_comp_manager); if ($o_competition instanceof Competition) { $this->season = $o_competition->GetWorkingSeason(); } if (!$this->season instanceof Season) { $this->Redirect(); } # Now that we have short URL data, if data has just been saved for season, redirect back to season if ($this->b_saved) { $this->Redirect($this->season->GetNavigateUrl()); } } else { if (!is_null($this->tournament_id)) { $match_manager->ReadByMatchId(array($this->tournament_id)); $this->tournament = $match_manager->GetFirst(); if (!is_null($this->tournament)) { # If the tournament has just been saved, now we have its URL so redirect to the thanks page if ($this->b_saved) { $this->Redirect($this->tournament->GetNavigateUrl()); } } } } } } else { $this->Redirect(); } unset($match_manager); }
<?php $sCategoryManager = new SCategoryManager($db); $sCategorys = $sCategoryManager->getList($category->getId()); $topicManager = new TopicManager($db); $postManager = new PostManager($db); $a = 0; $b = count($sCategorys); while ($a < $b) { $sCategory = $sCategorys[$a]; $topic = $topicManager->getList($sCategory->getId()); $nTopic = count($topic); $post = $postManager->getListSCat($sCategory->getId()); $nPost = count($post); if ($nPost !== 0) { $lastPost = $postManager->getLastBySCat($sCategory->getId()); $userLastPost = $userManager->findById($lastPost->getIdAuthor()); } require 'views/forum/sCategorys.phtml'; $a++; }