public function getFollow($user_id) { $user_follow = $this->getIdUserFollow($user_id); $follow = DB::table("users")->whereNotIn("users.id", $user_follow)->select("users.id as user_id", "users.last_name as user_lastname", "users.first_name as user_firstname", "users.avatar as avatar")->orderByRaw('RAND()')->take(12)->get(); if (count($follow) < 3) { $total = count($follow); } else { $total = 3; } for ($i = 0; $i < $total; $i++) { $follow[$i]->image = []; $follow[$i]->image = ImageFacade::getPhotoOfUser($follow[$i]->user_id); } return $follow; }
public function addComment($data) { if ($data) { $user_image_id = (int) ImageFacade::findIdUserOfImage($data['image_id']); if ($user_image_id !== (int) $data['user_id']) { $notiCreate = ['user_from_id' => $data['user_id'], 'user_to_id' => $user_image_id, 'kind' => 'comment', 'seen' => 0]; $noti = NoticationFacade::createNotication($notiCreate); } if (isset($noti)) { $data['noti_id'] = $noti['id']; } else { $data['noti_id'] = null; } $comment = CommentFacade::addComment($data); return $comment; } }
protected function getAllNotifiInfor($noti) { foreach ($noti as $key => $value) { if ($value->kind === "like") { $image_like = ImageFacade::getPhotoById($value->image_like_id)[0]; unset($value->comment_id, $value->follow_id, $value->image_comment_id); $value->image_url = $image_like->url . "/" . $image_like->resize_2; } elseif ($value->kind === "comment") { $image_comment = ImageFacade::getPhotoById($value->image_comment_id)[0]; unset($value->like_id, $value->follow_id, $value->image_like_id); $value->image_url = $image_comment->url . "/" . $image_comment->resize_2; } elseif ($value->kind === "follow") { unset($value->like_id, $value->comment_id, $value->image_like_id, $value->image_comment_id); } } return $noti; }
/** * add Like */ public function addLike($data) { if ($data) { $user_id_image = (int) ImageFacade::findIdUserOfImage($data['image_id']); if ($user_id_image !== (int) $data['user_id']) { $notiInfor = ['user_from_id' => $data['user_id'], 'user_to_id' => $user_id_image, 'kind' => "like", 'seen' => 0]; $noti = NoticationFacade::createNotication($notiInfor); } if (isset($noti)) { $data['noti_id'] = $noti['id']; } else { $data['noti_id'] = null; } $like = LikeFacade::addLike($data); return $like; } return false; }
public function findIdUserOfImage($image) { return ImageFacade::findIdUserOfImage($image); }
protected function getUserIdOfImage($image_id) { return ImageFacade::findIdUserOfImage($image_id); }