Ejemplo n.º 1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $topic = Topic::find($id);
     $topic->increment('views');
     $posts = $topic->posts;
     return View::make('topic')->with('topic', $topic)->with('posts', $posts);
 }
Ejemplo n.º 2
0
 public function beforeSave($options = array())
 {
     //parent::beforeSave($options);
     //print_r($this->data);
     $loggedInUser = AuthComponent::user();
     $found = false;
     $userId = $loggedInUser['user_id'];
     $this->data['Post']['post_by'] = $userId;
     $this->data['Post']['post_date'] = (new DateTime())->format('Y-m-d');
     //format('Y-m-d H:i:s')
     if (!empty($this->data['Topic']['topic_subject'])) {
         $str = $this->data['Topic']['topic_subject'];
         $num = $this->data['Post']['post_cat'];
         $subject = new Topic();
         $found = $subject->find('first', array('conditions' => array('Topic.topic_subject LIKE' => $str, 'Topic.topic_cat =' => $num)));
         if (!$found) {
             $subject->create();
             //create topic
             $subject->save(array('topic_subject' => $this->data['Topic']['topic_subject'], 'topic_date' => (new DateTime())->format('Y-m-d'), 'topic_cat' => $this->data['Post']['post_cat'], 'topic_by' => $userId));
             //see also save associated model method cakephp
             $this->data['Post']['post_topic'] = $this->Topic->getLastInsertId();
             return true;
         }
         $this->data['Post']['post_topic'] = $found['Topic']['topic_id'];
         return true;
     }
     //nothing
     return true;
 }
Ejemplo n.º 3
0
 public function show($id = null)
 {
     $data = [];
     $data['topic'] = Topic::find($id);
     $data['answers'] = $data['topic']->answers()->orderBy('created_at', 'desc')->get();
     return View::make('forum::topic_show', $data);
 }
Ejemplo n.º 4
0
 public function topicDetail()
 {
     $topic_id = Input::get('topic_id');
     $topic = Topic::find($topic_id);
     if (!isset($topic)) {
         return Response::view('errors.missing');
     }
     //预载入
     $gifts = Gift::where('topic_id', $topic->id)->with(['giftPosters' => function ($query) {
         $query->orderBy('created_at', 'asc');
     }])->get();
     $number = 1;
     foreach ($gifts as $gift) {
         $gift->img = $gift->giftPosters[0]->url;
         $gift->number = $number++;
     }
     // $gifts = Gift::where('topic_id', '=', $topic->id)->get();
     // if(isset($gifts))
     // {	$number = 1;
     // 	foreach($gifts as $gift)
     // 	{
     // 		$url = GiftPoster::where('gift_id','=',$gift->id)->first()->url;
     // 		// $gift->img = StaticController::imageWH($url);
     // 		$gift->img = $url;
     // 		$gift->number = $number++;
     // 	}
     // }
     $gifts = $this->isGiftLike($gifts);
     $type = $this->isTopicLike($topic_id);
     return View::make('pc.subject')->with(array('topic' => $topic, 'gifts' => $gifts, 'type' => $type));
 }
Ejemplo n.º 5
0
 public function getTopicCommentMore()
 {
     $topic_id = Input::get('topic_id');
     $topic = Topic::find($topic_id);
     $comments = $topic->hasManyTopicComments;
     return View::make('话题评论内容')->with('comments', $comments)->with('links', $this->link());
 }
Ejemplo n.º 6
0
 public static function getDayTopViewPosts($start = 0, $limit = 10)
 {
     Counter::checkAll(Topic::ENTITY_TYPE);
     $query = Topic::find()->join("user")->join("group")->join("rating")->join("counter");
     $query = $query->order("desc", "[Counter.dayCount]")->where("[Counter.dayCount]>0");
     $results = $query->range($start, $limit);
     return $results;
 }
Ejemplo n.º 7
0
 function test_find()
 {
     $name = "Writing";
     $test_topic = new Topic($name);
     $test_topic->save();
     $name2 = "Interview";
     $test_topic2 = new Topic($name2);
     $test_topic2->save();
     $result = Topic::find($test_topic->getId());
     $this->assertEquals($test_topic, $result);
 }
Ejemplo n.º 8
0
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Favorite::isUserFavoritedTopic(Auth::user(), $topic)) {
         Auth::user()->favoriteTopics()->detach($topic->id);
     } else {
         Auth::user()->favoriteTopics()->attach($topic->id);
         Notification::notify('topic_favorite', Auth::user(), $topic->user, $topic);
     }
     Flash::success(lang('Operation succeeded.'));
     return Redirect::route('topics.show', $topic->id);
 }
Ejemplo n.º 9
0
 /**
  * addMessage-funktio lähettää User mallille käskyn lisätä uusi viesti parametrina saatuun keskusteluun,jos viesti on tyhjä lähetetään virheilmoitus
  */
 public static function addMessage($id)
 {
     $params = $_POST;
     if ($params['content'] != null && !ctype_space($params['content'])) {
         $message = Message::createMessage($id, $params['content']);
         $messages = Message::all($id);
         $topic = Topic::find($id);
         View::make('keskustelu.html', array('topic' => $topic, 'messages' => $messages));
     }
     $messages = Message::all($id);
     $topic = Topic::find($id);
     View::make('keskustelu.html', array('topic' => $topic, 'messages' => $messages, 'error' => 'Viestisi oli tyhjä'));
 }
Ejemplo n.º 10
0
 public function createOrDelete($id)
 {
     $topic = Topic::find($id);
     if (Attention::isUserAttentedTopic(Auth::user(), $topic)) {
         $message = lang('Successfully remove attention.');
         Auth::user()->attentTopics()->detach($topic->id);
     } else {
         $message = lang('Successfully_attention');
         Auth::user()->attentTopics()->attach($topic->id);
         Notification::notify('topic_attent', Auth::user(), $topic->user, $topic);
     }
     Flash::success($message);
     return Redirect::route('topics.show', $topic->id);
 }
Ejemplo n.º 11
0
 /**
  * TODO: how to define active posts?
  *
  * Now the method count all posts in a given category
  * @param null $categoryId
  * @return mixed
  */
 public function getActivePostsCount($categoryId = null)
 {
     $query = Topic::find()->join("group");
     if ($categoryId !== null) {
         $this->id = $categoryId;
         $subs = $this->children();
         $where = "[Group.categoryId] IN (?";
         $args = [$categoryId];
         for ($i = 0, $count = count($subs); $i < $count; $i++) {
             $where .= ',?';
             $args[] = $subs[$i]->id;
         }
         $where .= ')';
         $query = $query->where($where, $args);
     }
     return $query->count();
 }
Ejemplo n.º 12
0
 /**
  * View group detail
  * @param $groupId
  */
 public function actionDetail($groupId)
 {
     $group = Group::get($groupId);
     RAssert::not_null($group);
     $group->category = Category::get($group->categoryId);
     $group->groupCreator = User::get($group->creator);
     $counter = $group->increaseCounter();
     // get latest 20 posts in the group
     $posts = Topic::find("groupId", $groupId)->join("user")->order_desc("createdTime")->range(0, 20);
     $data = ['group' => $group, 'counter' => $counter->totalCount, 'latestPosts' => $posts];
     $isLogin = Rays::isLogin();
     $data['hasJoined'] = $isLogin && GroupUser::isUserInGroup(Rays::user()->id, $group->id);
     $data['isManager'] = $isLogin && $group->creator == Rays::user()->id;
     $this->setHeaderTitle($group->name);
     $this->addCss("/public/css/post.css");
     $this->render('detail', $data, false);
 }
Ejemplo n.º 13
0
 public function forumIdWrite($id)
 {
     $json = Input::get('json');
     $data = json_decode($json);
     $writer = Student::where('auth', '=', $data->auth)->first();
     $sn = Topic::max('sn') + 1;
     $body = base64_decode($data->body);
     $topics = Topic::find($id);
     $topics->sn = $sn;
     $topics->save();
     $commit = new Commit();
     $commit->stu_id = $writer->id;
     $commit->topic_id = $id;
     $commit->body = $body;
     $commit->day = date("Y/m/d");
     $commit->save();
     return "suc";
 }
Ejemplo n.º 14
0
 public static function getUserPlusTopics($userId, $start = 0, $limit = 0)
 {
     $ratings = Rating::find(["entityType", Topic::ENTITY_TYPE, "userId", $userId, "valueType", self::VALUE_TYPE, "value", self::VALUE, "tag", self::TAG])->all();
     if ($ratings == null || empty($ratings)) {
         return array();
     }
     $query = Topic::find()->join("user")->join("group")->order_desc("id");
     if ($ratings != null && !empty($ratings)) {
         $where = "[id] in (";
         $args = array();
         for ($count = count($ratings), $i = 0; $i < $count; $i++) {
             $where .= "?" . ($i < $count - 1 ? "," : "");
             $args[] = $ratings[$i]->entityId;
         }
         unset($ratings);
         $where .= ")";
         $query = $query->where($where, $args);
     }
     return $start != 0 || $limit != 0 ? $query->range($start, $limit) : $query->all();
 }
Ejemplo n.º 15
0
 public static function getUserLikePosts($userId, $start = 0, $limit = 0)
 {
     $likes = RatingLike::find(["entityType", Topic::ENTITY_TYPE, "userId", $userId])->all();
     $query = Topic::find()->order_desc("id");
     if (!empty($likes)) {
         $args = [];
         $where = "[id] in (";
         for ($i = 0, $count = count($likes); $i < $count; $i++) {
             $args[] = $likes[$i]->entityId;
             $where .= '?' . ($i < $count - 1) ? "," : "";
         }
         unset($likes);
         $where .= ")";
         $query = $query->where($where, $args);
     }
     if ($start != 0 || $limit != 0) {
         return $query->range($start, $limit);
     } else {
         return $query->all();
     }
 }
Ejemplo n.º 16
0
 public function topicCollection()
 {
     if (!Sentry::check()) {
         return Response::json(array('errCode' => 10, 'message' => '请登录'));
     }
     $topic_id = Input::get('topic_id');
     /* 2015-09-16 hyy 改 start */
     $topic_focus = TopicFocus::where('user_id', Sentry::getUser()->id)->where('topic_id', $topic_id)->first();
     if (isset($topic_focus)) {
         try {
             DB::transaction(function () use($topic_focus, $topic_id) {
                 $topic = Topic::find($topic_id);
                 $topic->focus_num = $topic->focus_num - 1;
                 $topic->save();
                 $topic_focus->delete();
             });
         } catch (\Exception $e) {
             return Response::json(array('errCode' => 11, 'message' => '操作失败'));
         }
         /* 2015-09-16 hyy 改 end */
         return Response::json(array('errCode' => 0, 'message' => '取消收藏成功!'));
     } else {
         try {
             DB::transaction(function () use($topic_id) {
                 $topic_focus = new TopicFocus();
                 $topic_focus->user_id = Sentry::getUser()->id;
                 $topic_focus->topic_id = $topic_id;
                 $topic_focus->save();
                 $topic = Topic::find($topic_id);
                 $topic->focus_num = $topic->focus_num + 1;
                 $topic->save();
             });
         } catch (\Exception $e) {
             return Response::json(array('errCode' => 11, 'message' => '操作失败'));
         }
         return Response::json(array('errCode' => 0, 'message' => '收藏成功!'));
     }
 }
Ejemplo n.º 17
0
 public function downvote($id)
 {
     $topic = Topic::find($id);
     App::make('Phphub\\Vote\\Voter')->topicDownVote($topic);
     return Redirect::route('topics.show', $topic->id);
 }
Ejemplo n.º 18
0
 /**
  * Topics administration
  */
 public function actionAdmin()
 {
     $this->layout = 'admin';
     $data = array();
     // delete request
     if (Rays::app()->request()->isPostRequest()) {
         if (isset($_POST['checked_topics'])) {
             $checkedTopics = $_POST['checked_topics'];
             foreach ($checkedTopics as $item) {
                 if (!is_numeric($item)) {
                     return;
                 } else {
                     $topic = new Topic();
                     $topic->id = $item;
                     $topic->delete();
                 }
             }
         }
     }
     $curPage = $this->getPage("page");
     $pageSize = $this->getPageSize("pagesize");
     $count = Topic::find()->count();
     $data['count'] = $count;
     $query = Topic::find()->join("user")->join("group")->join("rating")->join("counter");
     $orderBy = Rays::getParam("orderBy", "id");
     $order = Rays::getParam("order", "desc");
     switch ($orderBy) {
         case "id":
             $query = $query->order($order, "[Topic.id]");
             break;
         case "likes":
             $query = $query->order($order, "[RatingStatistic.value]");
             break;
         case "views":
             $query = $query->order($order, "[Counter.totalCount]");
             break;
         case "createTime":
             $query = $query->order($order, "[Topic.id]");
             break;
         default:
             $query = $query->order_desc("id");
     }
     $posts = $query->range(($curPage - 1) * $pageSize, $pageSize);
     $data['topics'] = $posts;
     $pager = new RPager('page', $count, $pageSize, RHtml::siteUrl("post/admin?orderBy={$orderBy}&&order={$order}"), $curPage);
     $pager = $pager->showPager();
     $data['pager'] = $pager;
     $this->render('admin', $data, false);
 }
Ejemplo n.º 19
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     // delete
     $topic = Topic::find($id);
     $topic->delete();
     // redirect
     Session::flash('message', 'Successfully deleted the topic!');
     return Redirect::to('topics');
 }
Ejemplo n.º 20
0
    $promptr_name = $_POST['promptr_name'];
    $topic_id = $_POST['topic_id'];
    $new_promptr = new Promptr($promptr_name, $topic_id);
    $new_promptr->save();
    return $app['twig']->render('promptrs.html.twig', array('promptrs' => Promptr::getAll(), 'topic' => $topic_id, 'topic_picked' => true));
    // flag for included template
});
$app->get("/topic/{id}", function ($id) use($app) {
    $topic = Topic::find($id);
    $promptrs = $topic->getPromptrs();
    $allT = Topic::getAll();
    return $app['twig']->render("topic.html.twig", array('topic' => $topic, 'promptrs' => $promptrs, 'all_topics' => $allT));
});
// PROMPTR.HTML.TWIG
//delete question from NEW PROMPTR route -- then displays promptr page
$app->get("promptr/{id}", function ($id) use($app) {
    $promptr = Promptr::find($id);
    $questions = $promptr->getQuestions();
    return $app['twig']->render("promptr.html.twig", array('promptr' => $promptr, 'questions' => $questions));
});
//delete question route
$app->delete("/promptr/{id}/delete_question/{qId}", function ($id, $qId) use($app) {
    $question_id = $qId;
    $promptr = Promptr::find($id);
    $topic = Topic::find($promptr->getTopicId());
    $question = Question::findById($question_id);
    $question->delete();
    $questions = $promptr->getQuestions();
    return $app['twig']->render("promptr.html.twig", array('promptr' => $promptr, 'questions' => $questions, 'topic' => $topic));
});
return $app;
Ejemplo n.º 21
0
 public function delete($id)
 {
     $topic = Topic::find($id);
     $topic->delete();
     Flash::success(lang('Operation succeeded.'));
     return Redirect::route('topics.index');
 }
Ejemplo n.º 22
0
 public function search()
 {
     fallback($_GET['query'], "");
     $config = Config::current();
     if ($config->clean_urls and substr_count($_SERVER['REQUEST_URI'], "?") and !substr_count($_SERVER['REQUEST_URI'], "%2F")) {
         # Searches with / and clean URLs = server 404
         redirect("search/" . urlencode($_GET['query']) . "/");
     }
     if (empty($_GET['query'])) {
         return Flash::warning(__("Please enter a search term."));
     }
     list($where, $params) = keywords($_GET['query'], "name LIKE :query OR url LIKE :query", "forums");
     $forums = Forum::find(array("placeholders" => true, "where" => $where, "params" => $params));
     list($where, $params) = keywords($_GET['query'], "title LIKE :query OR description LIKE :query OR url LIKE :query", "topics");
     $topics = Topic::find(array("placeholders" => true, "where" => $where, "params" => $params));
     list($where, $params) = keywords($_GET['query'], "body LIKE :query", "messages");
     $messages = Message::find(array("placeholders" => true, "where" => $where, "params" => $params));
     $this->display("discuss/search", array("forums" => new Paginator($forums, 25, "forums_page"), "topics" => new Paginator($topics, 25, "topics_pave"), "messages" => new Paginator($messages, 25, "messages_page"), "search" => $_GET['query']), fix(_f("Search results for \"%s\"", $_GET['query'])));
 }
Ejemplo n.º 23
0
 /**
  * Delete le topic et les posts associées
  *
  */
 public function deleteTopic($slug, $id)
 {
     $user = Auth::user();
     $topic = Topic::find($id);
     if ($user->group->is_modo == true) {
         $posts = $topic->posts();
         $posts->delete();
         $topic->delete();
         return Redirect::route('forum_display', ['slug' => $topic->forum->slug, 'id' => $topic->forum->id])->with('message', 'Topic sucessfully deleted');
     } else {
         return Redirect::route('forum_topic', ['slug' => $topic->slug, 'id' => $topic->id])->with('message', 'You haven\'t access to this functionality');
     }
 }
Ejemplo n.º 24
0
 public function topic()
 {
     $topic_id = Input::get('topic_id');
     $topic = Topic::find($topic_id);
     if (!isset($topic)) {
         if (Request::wantsJson()) {
             return Response::json(array('errCode' => 1, 'message' => 该专题不存在));
         } else {
             return Response::view('errors.missing');
         }
     }
     $gifts = Gift::where('topic_id', '=', $topic->id)->get();
     if (isset($gifts)) {
         $number = 1;
         foreach ($gifts as $gift) {
             $url = GiftPoster::where('gift_id', '=', $gift->id)->first()->url;
             $gift->img = StaticController::imageWH($url);
             $gift->number = $number++;
         }
     }
     $gifts = $this->isGiftLike($gifts);
     $type = $this->isTopicLike($topic_id);
     if (Request::wantsJson()) {
         return Response::json(array('errCode' => 0, 'message' => '返回专题页数据', 'topic' => $topic, 'gifts' => $gifts, 'type' => $type));
     }
     return View::make('index/goodsList')->with(array('topic' => $topic, 'gifts' => $gifts, 'type' => $type));
 }
Ejemplo n.º 25
0
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
    return View::make('index')->with("topics", Topic::all());
});
Route::get('topics/{id}', function ($id) {
    $oTopic = Topic::find($id);
    return View::make('topic')->with('topic', $oTopic);
});
Route::get('posts/{id}', function ($id) {
    $oPost = Post::find($id);
    return View::make('post')->with('post', $oPost);
});
Route::get('users/new', function () {
    return View::make('newUserForm');
});
Route::get('users/{id}/edit', function ($id) {
    $oUser = User::find($id);
    return View::make('editUserForm')->with('user', $oUser);
});
Route::put('users/{id}', function ($id) {
    $aRules = array('firstname' => 'required', 'lastname' => 'required', 'email' => 'required|email|unique:users,email,' . $id);
Ejemplo n.º 26
0
$app->get("/promptr/{id}/question", function ($id) use($app) {
    $promptr = Promptr::find($id);
    $trending_index = $promptr->getTrending();
    $promptr->updateTrending(++$trending_index);
    Question::deleteTempQuestions();
    $shuffle = $_GET['shuffle'];
    $questions = $promptr->getQuestions();
    if ($shuffle == "true") {
        shuffle($questions);
    }
    foreach ($questions as $question) {
        $question->saveTempQuestion();
    }
    if ($questions == []) {
        return $app['twig']->render("promptr.html.twig", array('promptr' => $promptr, 'questions' => $questions, 'topic' => Topic::find($promptr->getTopicId())));
    } else {
        $temp_questions = Question::getTempQuestions();
        $first_question = $temp_questions[0];
        return $app['twig']->render('question.html.twig', array('question' => $first_question, 'promptr' => $promptr));
    }
});
// QUESTION.HTML.TWIG -- needs fixed -- if a question has been deleted, id # is skipped and
// end_flag = true. Need to somehow loop through just the questions in promptr->getQuestions
// the following pages of promptr run -- adding more answers
$app->post("/promptr/{id}/question/{quid}", function ($id, $quid) use($app) {
    $promptr = Promptr::find($id);
    $end_flag = false;
    $answer_field = $_POST['answer'];
    $new_answer = new Answer($answer_field, $quid);
    $new_answer->save();
Ejemplo n.º 27
0
 /**
  * User home page
  */
 public function actionHome()
 {
     $this->layout = 'user';
     $user = Rays::user();
     $data = array('user' => $user);
     $defaultSize = 10;
     $friends = Friend::find("uid", $user->id)->all();
     foreach ($friends as $friend) {
         $ids[] = $friend->fid;
     }
     $ids[] = $user->id;
     $query = Topic::find()->join("user")->join("group")->join("rating")->in("User.id", $ids)->order_desc("id");
     // ajax request
     // load more posts
     if (Rays::isAjax()) {
         $lastLoadedTime = @$_POST['lastLoadedTime'];
         $lastLoadedTime = $lastLoadedTime != '' ? $lastLoadedTime : null;
         $topics = $query->where("[createdTime] < ?", $lastLoadedTime)->range(0, $defaultSize);
         $result = array();
         if (count($topics) > 0) {
             $result['content'] = $this->renderPartial('_posts_list', array('topics' => $topics), true);
             $result['lastLoadTime'] = $topics[count($topics) - 1]->createdTime;
             echo json_encode($result);
         } else {
             echo json_encode(['content' => '']);
         }
         exit;
     }
     $data['topics'] = $query->range(0, $defaultSize);
     $this->setHeaderTitle($user->name);
     $this->addCss('/public/css/post.css');
     $this->render('home', $data, false);
 }
Ejemplo n.º 28
0
 public function deleteTopic()
 {
     if (!Auth::check()) {
         return Response::json(array('errCode' => 1, 'message' => '请登录!'));
     }
     $user_id = Auth::user()->id;
     $topic_id = Input::get('topic_id');
     $topic = Topic::find($topic_id);
     if ($topic != null) {
         if ($topic->user_id != $user_id) {
             return Response::json(array('errCode' => 2, 'message' => '不可删除他人的话题!'));
         }
         if ($topic->delete()) {
             return Response::json(array('errCode' => 0, 'message' => '相话题删除成功!'));
         }
         return Response::json(array('errCode' => 3, 'message' => '话题删除失败!'));
     }
     return Response::json(array('errCode' => 4, 'message' => '话题不存在!'));
 }
Ejemplo n.º 29
0
 public static function deleteGroup(Group $group)
 {
     Rating::where("[entityId] = ? AND [entityType] = ?", [$group->id, Group::ENTITY_TYPE])->delete();
     RatingStatistic::where("[entityId] = ? AND [entityType] = ?", [$group->id, Group::ENTITY_TYPE])->delete();
     Counter::where("[entityId] = ? AND [entityTypeId] = ?", [$group->id, Group::ENTITY_TYPE])->delete();
     $topics = Topic::find("groupId", $group->id)->all();
     foreach ($topics as $topic) {
         $topic->delete();
     }
     GroupUser::where("[groupId] = ?", $group->id)->delete();
     $group->delete();
 }