@@ -7,115 +7,115 @@ |
||
| 7 | 7 | |
| 8 | 8 | trait Likeable |
| 9 | 9 | { |
| 10 | - use LikeableTrait; |
|
| 10 | + use LikeableTrait; |
|
| 11 | 11 | |
| 12 | - public function like($type = 'like', $userId = null) |
|
| 13 | - { |
|
| 14 | - if(is_null($userId)) { |
|
| 15 | - $userId = $this->loggedInUserId(); |
|
| 16 | - } |
|
| 12 | + public function like($type = 'like', $userId = null) |
|
| 13 | + { |
|
| 14 | + if(is_null($userId)) { |
|
| 15 | + $userId = $this->loggedInUserId(); |
|
| 16 | + } |
|
| 17 | 17 | |
| 18 | - if($userId) { |
|
| 19 | - $like = $this->likes() |
|
| 20 | - ->where('user_id', '=', $userId) |
|
| 21 | - ->typelike($type) |
|
| 22 | - ->first(); |
|
| 18 | + if($userId) { |
|
| 19 | + $like = $this->likes() |
|
| 20 | + ->where('user_id', '=', $userId) |
|
| 21 | + ->typelike($type) |
|
| 22 | + ->first(); |
|
| 23 | 23 | |
| 24 | - if($like) return; |
|
| 24 | + if($like) return; |
|
| 25 | 25 | |
| 26 | - $like = new Like(); |
|
| 27 | - $like->user_id = $userId; |
|
| 28 | - $like->type = $type; |
|
| 29 | - $this->likes() |
|
| 30 | - ->typelike($type) |
|
| 31 | - ->save($like); |
|
| 32 | - } |
|
| 26 | + $like = new Like(); |
|
| 27 | + $like->user_id = $userId; |
|
| 28 | + $like->type = $type; |
|
| 29 | + $this->likes() |
|
| 30 | + ->typelike($type) |
|
| 31 | + ->save($like); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - $this->incrementLikeCount($type); |
|
| 35 | - } |
|
| 34 | + $this->incrementLikeCount($type); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function unlike($type = 'like', $userId = null) |
|
| 38 | - { |
|
| 39 | - if(is_null($userId)) { |
|
| 40 | - $userId = $this->loggedInUserId(); |
|
| 41 | - } |
|
| 37 | + public function unlike($type = 'like', $userId = null) |
|
| 38 | + { |
|
| 39 | + if(is_null($userId)) { |
|
| 40 | + $userId = $this->loggedInUserId(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if($userId) { |
|
| 44 | - $like = $this->likes() |
|
| 45 | - ->where('user_id', '=', $userId) |
|
| 46 | - ->typelike($type) |
|
| 47 | - ->first(); |
|
| 43 | + if($userId) { |
|
| 44 | + $like = $this->likes() |
|
| 45 | + ->where('user_id', '=', $userId) |
|
| 46 | + ->typelike($type) |
|
| 47 | + ->first(); |
|
| 48 | 48 | |
| 49 | - if(!$like) { return; } |
|
| 49 | + if(!$like) { return; } |
|
| 50 | 50 | |
| 51 | - $like->delete(); |
|
| 52 | - } |
|
| 51 | + $like->delete(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - $this->decrementLikeCount($type); |
|
| 55 | - } |
|
| 54 | + $this->decrementLikeCount($type); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function wasLiked($type = 'like', $userId = null) { |
|
| 58 | - if(is_null($userId)) { |
|
| 59 | - $userId = $this->loggedInUserId(); |
|
| 60 | - } |
|
| 57 | + public function wasLiked($type = 'like', $userId = null) { |
|
| 58 | + if(is_null($userId)) { |
|
| 59 | + $userId = $this->loggedInUserId(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return (bool) $this->likes() |
|
| 63 | - ->where('user_id', '=', $userId) |
|
| 64 | - ->typelike($type) |
|
| 65 | - ->count(); |
|
| 66 | - } |
|
| 62 | + return (bool) $this->likes() |
|
| 63 | + ->where('user_id', '=', $userId) |
|
| 64 | + ->typelike($type) |
|
| 65 | + ->count(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - private function incrementLikeCount($type ='like') |
|
| 69 | - { |
|
| 70 | - $counter = $this->likeCounter() |
|
| 71 | - ->typelike($type) |
|
| 72 | - ->first(); |
|
| 68 | + private function incrementLikeCount($type ='like') |
|
| 69 | + { |
|
| 70 | + $counter = $this->likeCounter() |
|
| 71 | + ->typelike($type) |
|
| 72 | + ->first(); |
|
| 73 | 73 | |
| 74 | - if($counter) { |
|
| 75 | - $counter->count++; |
|
| 76 | - $counter->save(); |
|
| 77 | - } else { |
|
| 78 | - $counter = new LikeCounter; |
|
| 79 | - $counter->type = $type; |
|
| 80 | - $counter->count = 1; |
|
| 81 | - $this->likeCounter() |
|
| 82 | - ->typelike($type) |
|
| 83 | - ->save($counter); |
|
| 84 | - } |
|
| 85 | - } |
|
| 74 | + if($counter) { |
|
| 75 | + $counter->count++; |
|
| 76 | + $counter->save(); |
|
| 77 | + } else { |
|
| 78 | + $counter = new LikeCounter; |
|
| 79 | + $counter->type = $type; |
|
| 80 | + $counter->count = 1; |
|
| 81 | + $this->likeCounter() |
|
| 82 | + ->typelike($type) |
|
| 83 | + ->save($counter); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Private. Decrement the total like count stored in the counter |
|
| 89 | - */ |
|
| 90 | - private function decrementLikeCount($type ='like') |
|
| 91 | - { |
|
| 92 | - $counter = $this->likeCounter() |
|
| 93 | - ->typelike($type) |
|
| 94 | - ->first(); |
|
| 87 | + /** |
|
| 88 | + * Private. Decrement the total like count stored in the counter |
|
| 89 | + */ |
|
| 90 | + private function decrementLikeCount($type ='like') |
|
| 91 | + { |
|
| 92 | + $counter = $this->likeCounter() |
|
| 93 | + ->typelike($type) |
|
| 94 | + ->first(); |
|
| 95 | 95 | |
| 96 | - if($counter) { |
|
| 97 | - $counter->count--; |
|
| 98 | - if($counter->count) { |
|
| 99 | - $counter->type = $type; |
|
| 100 | - $counter->save(); |
|
| 101 | - } else { |
|
| 102 | - $counter->delete(); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 96 | + if($counter) { |
|
| 97 | + $counter->count--; |
|
| 98 | + if($counter->count) { |
|
| 99 | + $counter->type = $type; |
|
| 100 | + $counter->save(); |
|
| 101 | + } else { |
|
| 102 | + $counter->delete(); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function likes($type = 'like') |
|
| 108 | - { |
|
| 109 | - return $this->morphMany(Like::class, 'likable'); |
|
| 110 | - } |
|
| 107 | + public function likes($type = 'like') |
|
| 108 | + { |
|
| 109 | + return $this->morphMany(Like::class, 'likable'); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - public function getLikes($type = 'like') |
|
| 113 | - { |
|
| 114 | - return $this->likes()->typelike($type)->get(); |
|
| 115 | - } |
|
| 112 | + public function getLikes($type = 'like') |
|
| 113 | + { |
|
| 114 | + return $this->likes()->typelike($type)->get(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function likeCounter() |
|
| 118 | - { |
|
| 119 | - return $this->morphOne(LikeCounter::class, 'likable'); |
|
| 120 | - } |
|
| 117 | + public function likeCounter() |
|
| 118 | + { |
|
| 119 | + return $this->morphOne(LikeCounter::class, 'likable'); |
|
| 120 | + } |
|
| 121 | 121 | } |
| 122 | 122 | \ No newline at end of file |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | class UserPresenter extends Presenter |
| 8 | 8 | { |
| 9 | - use ImagePresentorPresentable; |
|
| 9 | + use ImagePresentorPresentable; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Render user's name. |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | * @param $onlyPrice |
| 99 | 99 | * @return string |
| 100 | 100 | */ |
| 101 | - /* public function renderPriceWithSale($onlyPrice = false) |
|
| 101 | + /* public function renderPriceWithSale($onlyPrice = false) |
|
| 102 | 102 | { |
| 103 | 103 | $price = $this->reformatPrice($this->model->price - $this->getPriceAmountSale()); |
| 104 | 104 | // $price = $this->getPriceAmountSale(); |
@@ -46,11 +46,11 @@ |
||
| 46 | 46 | */ |
| 47 | 47 | public function getSidebarCollection() |
| 48 | 48 | { |
| 49 | - return self::getModel() |
|
| 50 | - ->where('show_in_sidebar', 1) |
|
| 51 | - ->active() |
|
| 52 | - ->ranked() |
|
| 53 | - ->get(); |
|
| 49 | + return self::getModel() |
|
| 50 | + ->where('show_in_sidebar', 1) |
|
| 51 | + ->active() |
|
| 52 | + ->ranked() |
|
| 53 | + ->get(); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | return self::getModel() |
| 25 | 25 | ->create([ |
| 26 | - 'email' => $data['email'], |
|
| 27 | - 'token' => str_random(30), |
|
| 26 | + 'email' => $data['email'], |
|
| 27 | + 'token' => str_random(30), |
|
| 28 | 28 | ]); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | $model = $this->getByEmail($email); |
| 34 | 34 | |
| 35 | - return (bool) $model; |
|
| 35 | + return (bool) $model; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -47,13 +47,13 @@ |
||
| 47 | 47 | public function getPopularPublic($count = 4) |
| 48 | 48 | { |
| 49 | 49 | // todo: popular featured posts. |
| 50 | - return $this->getModel() |
|
| 51 | - ->published() |
|
| 52 | - ->active() |
|
| 53 | - ->orderBy('view_count', self::DESC) |
|
| 54 | - ->orderBy('id', self::DESC) |
|
| 55 | - ->take($count) |
|
| 56 | - ->get(); |
|
| 50 | + return $this->getModel() |
|
| 51 | + ->published() |
|
| 52 | + ->active() |
|
| 53 | + ->orderBy('view_count', self::DESC) |
|
| 54 | + ->orderBy('id', self::DESC) |
|
| 55 | + ->take($count) |
|
| 56 | + ->get(); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |