Skip to content

Commit

Permalink
gamification
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Nov 10, 2022
1 parent 4e45162 commit 971d813
Show file tree
Hide file tree
Showing 22 changed files with 461 additions and 23 deletions.
26 changes: 26 additions & 0 deletions app/Gamify/Badges/FirstContribution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Gamify\Badges;

use QCod\Gamify\BadgeType;

class FirstContribution extends BadgeType
{
/**
* Description for badge
*
* @var string
*/
protected $description = '';

/**
* Check is user qualifies for badge
*
* @param $user
* @return bool
*/
public function qualifier($user)
{
return $user->getPoints() >= 80;
}
}
35 changes: 35 additions & 0 deletions app/Gamify/Points/BlogCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class BlogCreated extends PointType
{
/**
* Number of points
*
* @var int
*/
public $points = 20;

/**
* Point constructor
*
* @param $subject
*/
public function __construct($subject)
{
$this->subject = $subject;
}

/**
* User who will be receive points
*
* @return mixed
*/
public function payee()
{
return $this->getSubject()->user;
}
}
35 changes: 35 additions & 0 deletions app/Gamify/Points/BookmarkCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class BookmarkCreated extends PointType
{
/**
* Number of points
*
* @var int
*/
public $points = 20;

/**
* Point constructor
*
* @param $subject
*/
public function __construct($subject)
{
$this->subject = $subject;
}

/**
* User who will be receive points
*
* @return mixed
*/
public function payee()
{
return $this->getSubject()->user;
}
}
35 changes: 35 additions & 0 deletions app/Gamify/Points/CommentCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class CommentCreated extends PointType
{
/**
* Number of points
*
* @var int
*/
public $points = 20;

/**
* Point constructor
*
* @param $subject
*/
public function __construct($subject)
{
$this->subject = $subject;
}

/**
* User who will be receive points
*
* @return mixed
*/
public function payee()
{
return $this->getSubject()->user;
}
}
35 changes: 35 additions & 0 deletions app/Gamify/Points/LikeCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class LikeCreated extends PointType
{
/**
* Number of points
*
* @var int
*/
public $points = 20;

/**
* Point constructor
*
* @param $subject
*/
public function __construct($subject)
{
$this->subject = $subject;
}

/**
* User who will be receive points
*
* @return mixed
*/
public function payee()
{
return $this->getSubject()->user;
}
}
35 changes: 35 additions & 0 deletions app/Gamify/Points/ReplyCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Gamify\Points;

use QCod\Gamify\PointType;

class ReplyCreated extends PointType
{
/**
* Number of points
*
* @var int
*/
public $points = 20;

/**
* Point constructor
*
* @param $subject
*/
public function __construct($subject)
{
$this->subject = $subject;
}

/**
* User who will be receive points
*
* @return mixed
*/
public function payee()
{
return $this->getSubject()->user;
}
}
24 changes: 13 additions & 11 deletions app/Http/Livewire/Blogs/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Livewire\Blogs;

use App\Events\BlogWasCreated;
use App\Gamify\Points\BlogCreated;
use App\Models\Blog;
use App\Models\Tag;
use Livewire\Component;
Expand All @@ -20,7 +21,7 @@ class Create extends Component
public $coverImage;
public $tags = [];
public $search;
public $searchTags=[];
public $searchTags = [];
protected $rules = [
'coverImage' => ['required', 'mimes:png,jpg,svg,gif', 'max:2048'],
'title' => ['required', 'max:200', 'min:20'],
Expand All @@ -30,9 +31,9 @@ class Create extends Component
public function render()
{
if ($this->search != NULL) {
$this->searchTags = Tag::query()->where('title', 'LIKE', '%'.$this->search.'%')->take(5)->get();
}else{
$this->searchTags=[];
$this->searchTags = Tag::query()->where('title', 'LIKE', '%' . $this->search . '%')->take(5)->get();
} else {
$this->searchTags = [];
}
return view('livewire.blogs.create');
}
Expand All @@ -45,14 +46,14 @@ public function updatedCoverImage()
}
public function submit()
{
$this->authorize('create',Blog::class);
$this->authorize('create', Blog::class);
$this->validate();
$blog = Blog::create([
'title' => $this->title,
'body' => $this->body,
'published'=>1,
'published' => 1,
'user_id' => auth()->id(),
'cover_image'=> $this->coverImage->store('/','images')
'cover_image' => $this->coverImage->store('/', 'images')
]);
$tagIds = [];
foreach ($this->tags as $tag) {
Expand All @@ -63,18 +64,19 @@ public function submit()
};
$blog->tags()->sync($tagIds);
BlogWasCreated::dispatch($blog);
return redirect()->to('/blogs/'.$blog->slug);
givePoint(new BlogCreated($blog));
return redirect()->to('/blogs/' . $blog->slug);
}
public function draft()
{
$this->authorize('create',Blog::class);
$this->authorize('create', Blog::class);
$this->validate();
$blog = Blog::create([
'title' => $this->title,
'body' => $this->body,
'published'=>0,
'published' => 0,
'user_id' => auth()->id(),
'cover_image'=> $this->coverImage->store('/','images')
'cover_image' => $this->coverImage->store('/', 'images')
]);
$tagIds = [];
foreach ($this->tags as $tag) {
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Livewire/Blogs/Manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Blogs;

use App\Gamify\Points\BlogCreated;
use App\Models\Blog;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function update()
public function delete()
{
$this->authorize('delete', $this->blog);
undoPoint(new BlogCreated($this->blog));
$this->blog->delete();
return redirect()->to('/blogs');
}
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Livewire/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Models\Comment as ModelsComment;
use App\Models\Reply as ModelsReply;
use App\Gamify\Points\CommentCreated;
use App\Gamify\Points\ReplyCreated;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
use Livewire\WithPagination;
Expand Down Expand Up @@ -48,11 +50,12 @@ public function showModal()
public function comment()
{
if ($this->canComment) {
ModelsComment::create([
$comment=ModelsComment::create([
'body' => $this->body,
'blog_id' => $this->blog_id,
'user_id' => auth()->id()
]);
givePoint(new CommentCreated($comment));
$this->reset('body');
$this->comments_count++;
$this->body = '';
Expand All @@ -74,11 +77,12 @@ public function update($comment_id)
}
public function reply($comment_id)
{
ModelsReply::create([
$reply=ModelsReply::create([
'body' => $this->body,
'comment_id' => $comment_id,
'user_id' => auth()->id()
]);
givePoint(new ReplyCreated($reply));
$this->reset('body');
// $this->emit('editorClose','destroyEditor');
}
Expand All @@ -90,6 +94,7 @@ public function delete($comment_id)
if ($comment->replies->count() > 0) {
dd("you can't delete it completely");
} else {
undoPoint(new CommentCreated($comment));
$comment->delete();
$this->comments_count--;
}
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Livewire/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire;

use App\Gamify\Points\ReplyCreated;
use App\Models\Reply as ModelsReply;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
Expand Down Expand Up @@ -41,15 +42,17 @@ public function delete($reply_id)

$reply = ModelsReply::find($reply_id);
$this->authorize('delete', $reply);
undoPoint(new ReplyCreated($reply));
$reply->delete();
}
public function reply()
{
ModelsReply::create([
$reply=ModelsReply::create([
'body' => $this->body,
'comment_id' => $this->comment_id,
'user_id' => auth()->id()
]);
givePoint(new ReplyCreated($reply));
$this->reset('body');
}

Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
use Illuminate\Support\Facades\Storage;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Support\Str;
use QCod\Gamify\Gamify;
use Spatie\Permission\Traits\HasRoles;
use RalphJSmit\Laravel\SEO\Support\HasSEO;
use RalphJSmit\Laravel\SEO\Support\SEOData;

class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable, HasRoles, HasSEO;
use HasApiTokens, HasFactory, Notifiable, HasRoles, HasSEO,Gamify;

/**
* The attributes that are mass assignable.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"laravel/tinker": "^2.7",
"league/commonmark": "^2.3",
"livewire/livewire": "^2.10",
"qcod/laravel-gamify": "^1.0",
"ralphjsmit/laravel-seo": "^1.2",
"saade/blade-iconsax": "^1.0",
"spatie/laravel-permission": "^5.5",
Expand Down
Loading

0 comments on commit 971d813

Please sign in to comment.