Beispiel #1
0
 /**
  * Create a new event instance.
  *
  * @return void
  */
 public function __construct(Reply $reply, Topic $topic, User $user)
 {
     $this->reply = $reply;
     $this->topic = $topic;
     $this->user = $user;
     $this->weight = Config::get('app.reply_gain_weight');
     $this->karma = 0;
     $this->notifiable = $reply;
     $user->increment('reply_count');
     $topic->increment('reply_count');
 }
Beispiel #2
0
 public static function topics()
 {
     $value = Cache::remember('statistics_topics', 5, function () {
         return Topic::count();
     });
     return $value;
 }
Beispiel #3
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $topic = Topic::findOrFail($this->input('topic_id'));
     if ($topic->is_blocked) {
         return false;
     } else {
         return true;
     }
 }
Beispiel #4
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     if (Auth::check() && Auth::user()->can('manage_topics')) {
         $this->topic = Topic::findOrFail($this->route('id'));
         return true;
     } else {
         return false;
     }
 }
Beispiel #5
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $this->topic = Topic::findOrFail($this->route('id'));
     //patikrinam ar useris turi teise redaguoti tema.
     if (Auth::check() && (Auth::user()->id == $this->topic->user_id && !$this->topic->is_blocked) || Auth::user()->can('manage_topics')) {
         return true;
     } else {
         return false;
     }
 }
Beispiel #6
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $user = Auth::user();
     $topic = Topic::findOrFail($this->route('id'));
     $this->topic = $topic;
     if ($user && ($topic->user_id == $user->id && !$this->topic->is_blocked || $user->can('manage_topics'))) {
         return true;
     } else {
         return false;
     }
 }
Beispiel #7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $topic = Topic::findOrFail($this->argument('topic_id'));
     $users = User::where('email_news', 1)->chunk(200, function ($users) use($topic) {
         $data = ['title' => $topic->title, 'body' => $topic->body];
         foreach ($users as $user) {
             Mail::queue('emails.news', $data, function ($message) use($user, $topic) {
                 $message->to($user->email)->subject('Maze Naujienos: ' . utf8_urldecode($topic->title));
             });
         }
     });
 }
Beispiel #8
0
 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]);
 }
Beispiel #9
0
 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'));
 }
Beispiel #10
0
 /**
  * Rodo skiltį.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(Request $request, $slug)
 {
     $sort = $request->input('rodyti');
     $node = Node::where('slug', $slug)->firstOrFail();
     if ($node->parent_node) {
         $topics = $node->topics()->withReplies();
         $expandable = $node->parent_node;
     } else {
         $nodes = Node::where('parent_node', $node->id)->lists('id')->all();
         $topics = Topic::whereIn('node_id', $nodes)->withReplies();
         $expandable = $node->id;
     }
     if ($sort == 'populiariausi' || !$sort) {
         $topics = $topics->pinnedLocal()->popular()->withReplies();
     } else {
         $topics->pinnedLocal()->latest()->withReplies();
     }
     $topics = $topics->paginate(20);
     return view('node.show', compact('node', 'topics', 'sort', 'expandable'));
 }
Beispiel #11
0
 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);
 }
Beispiel #12
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Decrementing topics.');
     Topic::decrement('weight', Config::get('app.topics_decay'));
 }
Beispiel #13
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($slug)
 {
     $topic = Topic::where('slug', $slug)->firstOrFail();
     if ($topic->node->parent_node) {
         $expandable = $topic->node->parent_node;
     } else {
         $expandable = $topic->node_id;
     }
     $node = $topic->node;
     if (Auth::check()) {
         $replies = $topic->replies()->lists('id');
         // dd(Auth::user()->notifications()->whereIn('object_id', $replies)->where('object_type', 'reply')->get());
         Auth::user()->notifications()->whereIn('object_id', $replies)->where('object_type', 'reply')->update(['read_at' => new \DateTime()]);
         //bust da cache
         Cache::forget(Auth::user()->id . '_notification_count');
     }
     //padidina view counteri.
     $topic->increment('view_count');
     return view('topic.show', compact('topic', 'expandable', 'node'));
 }
 /**
  * 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]);
 }
Beispiel #15
0
 public function getSlugAttribute($value)
 {
     if (!$value) {
         $value = $this->id . '-' . S::slugify($this->title);
         $nodes = Topic::where('slug', $value);
         if ($nodes->count() > 0) {
             $value = $this->id . '-' . $value;
             $this->slug = $value;
             $this->save();
             return $value;
         } else {
             $this->slug = $value;
             $this->save();
             return $value;
         }
     } else {
         return $value;
     }
 }