コード例 #1
0
ファイル: Statistics.php プロジェクト: PovilasLT/maze
 public static function replies()
 {
     $value = Cache::remember('statistics_replies', 5, function () {
         return Reply::count();
     });
     return $value;
 }
コード例 #2
0
ファイル: CleanReplies.php プロジェクト: PovilasLT/maze
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     foreach (Reply::all() as $reply) {
         if (!$reply->topic) {
             $reply->delete();
         }
     }
 }
コード例 #3
0
ファイル: DeleteReply.php プロジェクト: PovilasLT/maze
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $user = Auth::user();
     $reply = Reply::findOrFail($this->route('id'));
     $this->reply = $reply;
     if ($user && ($reply->user_id == $user->id && !$reply->topic->is_blocked || $user->can('manage_posts'))) {
         return true;
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: UpdateReply.php プロジェクト: PovilasLT/maze
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::check()) {
         $user = Auth::user();
         $reply = Reply::findOrFail($this->route('id'));
         if ($reply->user_id == $user->id || $user->can('manage_posts')) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #5
0
ファイル: RepliesController.php プロジェクト: PovilasLT/maze
 public function markAnswer(AnswerReply $request, $id)
 {
     //Pažymim atsakymą.
     $reply = Reply::findOrFail($id);
     $reply->is_answer = 1;
     $reply->user->increment('karma_count', 5);
     $reply->save();
     //Užrakinam temą.
     $topic = Topic::findOrFail($reply->topic_id);
     $topic->is_blocked = 1;
     $topic->is_answered = 1;
     $topic->save();
     flash()->success('Pranešimas pažymėtas kaip atsakymas!');
     return redirect()->route('topic.show', [$topic->slug]);
 }
コード例 #6
0
ファイル: SearchController.php プロジェクト: PovilasLT/maze
 public function results(Request $request)
 {
     $type = $request->input('type');
     $query = $request->input('query');
     if ($type == 'user') {
         $results = User::where('username', 'LIKE', '%' . $query . '%')->paginate(20);
     } elseif ($type == 'reply') {
         $results = Reply::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20);
     } elseif ($type == 'topic') {
         $results = Topic::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20);
     } elseif ($type == 'status') {
         $results = Status::where('body_original', 'LIKE', '%' . $query . '%')->paginate(20);
     }
     return view('search.results', compact('type', 'query', 'results'));
 }
コード例 #7
0
ファイル: AnswerReply.php プロジェクト: PovilasLT/maze
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::check()) {
         //if user owns the topic or if user is admin
         $reply = Reply::findOrFail($this->route('id'));
         $topic = $reply->topic;
         $this->reply = $reply;
         if ($topic->user_id == Auth::user()->id || Auth::user()->can('manage_topics')) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #8
0
ファイル: VotesController.php プロジェクト: PovilasLT/maze
 public function vote(VoteRequest $request, $vote, $type, $id)
 {
     $user = Auth::user();
     if ($type == 'tema') {
         $type = 'Topic';
         $_votable = Topic::findOrFail($id);
     } else {
         $type = 'Reply';
         $_votable = Reply::findOrFail($id);
     }
     $_vote = Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->first();
     //Ištrinam visus balsus, jei netyčia susibugintų.
     if ($_vote) {
         Vote::where('votable_type', $type)->where('votable_id', $id)->where('user_id', $user->id)->delete();
         if ($_vote->is != $vote) {
             $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]);
             //cancel old vote and give new vote
             if ($vote == 'upvote') {
                 event(new UpVoted($_votable, $created_vote, $_votable->user, true));
             } else {
                 event(new DownVoted($_votable, $created_vote, $_votable->user, true));
             }
         } else {
             //cancel current vote
             if ($vote == 'upvote') {
                 event(new DownVoted($_votable, $_vote, $_votable->user, false));
             } else {
                 event(new UpVoted($_votable, $_vote, $_votable->user, false));
             }
         }
     } else {
         $created_vote = Vote::create(['user_id' => $user->id, 'votable_type' => $type, 'votable_id' => $id, 'is' => $vote]);
         //just vote
         if ($vote == 'upvote') {
             event(new UpVoted($_votable, $created_vote, $_votable->user, false));
         } else {
             event(new DownVoted($_votable, $created_vote, $_votable->user, false));
         }
     }
     return response('success', 200);
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Topic::where('vote_count', '<', '0')->update(['vote_count' => 0]);
     Reply::where('vote_count', '<', '0')->update(['vote_count' => 0]);
 }