public function search($input) { $query = SubResourceDetail::query(); $columns = Schema::getColumnListing('subResourceDetails'); $attributes = array(); foreach ($columns as $attribute) { if (isset($input[$attribute]) and !empty($input[$attribute])) { $query->where($attribute, $input[$attribute]); $attributes[$attribute] = $input[$attribute]; } else { $attributes[$attribute] = null; } } return [$query->get(), $attributes]; }
/** * Store a newly created SubResourceDetailLike in storage. * POST /subResourceDetailLikes * * @param Request $request * * @return Response */ public function store(Request $request) { if (sizeof(SubResourceDetailLike::$rules) > 0) { $this->validateRequestOrFail($request, SubResourceDetailLike::$rules); } $input = $request->all(); $subResourceDetailLikes = $this->subResourceDetailLikeRepository->create($input); $post = SubResourceDetail::find($input['postId']); if ($post) { $post->likes = $post->likes + 1; $post->update(); } else { return response()->json("Invalid iWomen Post Id!", 400); } return response()->json($post->likes); }
/** * Display a listing of the SubResourceDetail. * GET|HEAD /subResourceDetails * * @return Response */ public function index(Request $request) { $offset = $request->page ? $request->page : 1; $limit = $request->limit ? $request->limit : 12; $isAllow = $request->isAllow ? $request->isAllow : ''; $offset = ($offset - 1) * $limit; if ($request->resource_id) { if ($isAllow && $isAllow != '') { $subResourceDetails = SubResourceDetail::with('author')->where('isAllow', $isAllow)->where('resource_id', $request->resource_id)->orderBy('posted_date', 'desc')->offset($offset)->limit($limit)->get(); } else { $subResourceDetails = SubResourceDetail::with('author')->where('resource_id', $request->resource_id)->orderBy('posted_date', 'desc')->offset($offset)->limit($limit)->get(); } } else { if ($isAllow && $isAllow != '') { $subResourceDetails = SubResourceDetail::with('author')->where('isAllow', $isAllow)->orderBy('posted_date', 'desc')->offset($offset)->limit($limit)->get(); } else { $subResourceDetails = SubResourceDetail::with('author')->orderBy('posted_date', 'desc')->offset($offset)->limit($limit)->get(); } } return response()->json($subResourceDetails); }
public function share($id, Request $request) { $post_type = $request->input('postType'); switch ($post_type) { case 'Post': $post = Post::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; case 'iWomenPost': $post = IwomenPost::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; case 'Resources': $post = Resources::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; case 'SubResourceDetail': $post = SubResourceDetail::find($id); if ($post) { $post->share_count = $post->share_count + 1; $post->update(); return response()->json($post->share_count); } break; default: # code... break; } return response()->json("Successfully shared your post!"); }
/** * Store a newly created Comment in storage. * POST /comments * * @param Request $request * * @return Response */ public function store(Request $request) { if (sizeof(Comment::$rules) > 0) { $validator = $this->validateRequestOrFail($request, Comment::$rules); if ($validator) { return $validator; } } $input = $request->all(); $input['objectId'] = str_random(10); $comments = $this->commentRepository->create($input); if (isset($input['postType']) && $input['postType'] == 'iWomenPost') { $post = IwomenPost::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } else { if (isset($input['postType']) && $input['postType'] == 'Post') { $post = Post::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } else { if (isset($input['postType']) && $input['postType'] == 'SubResourceDetail') { $post = SubResourceDetail::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } else { if (isset($input['postType']) && $input['postType'] == 'Resources') { $post = Resources::where('objectId', $input['postId'])->first(); if ($post) { $post->comment_count = $post->comment_count + 1; $post->update(); } } } } } if (isset($input['postType']) && $input['postType'] == 'Post' || isset($input['postType']) && $input['postType'] == 'SubResourceDetail' || isset($input['postType']) && $input['postType'] == 'Resources') { if (isset($post) && $post) { $device_list = []; $gcm = Gcm::where('user_id', $post->userId)->first(); if ($gcm) { $device_list[] = PushNotification::Device($gcm->reg_id); $message['title'] = 'New Comment'; $message['message'] = $comments->comment_contents; $devices = PushNotification::DeviceCollection($device_list); $message = PushNotification::Message(json_encode($message), array()); $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message); } } } $comments['comment_count'] = $post->comment_count; return $this->sendResponse($comments->toArray(), "Comment saved successfully"); }
public function import() { /* $dataJson = $this->readJson('TlgProfile.json'); foreach ($dataJson['results'] as $key => $data) { $data['tlg_group_logo'] = isset($data['tlg_group_logo']) ? $data['tlg_group_logo']['url'] : ''; $data['tlg_leader_img'] = isset($data['tlg_leader_img']) ? $data['tlg_leader_img']['url'] : ''; $data['tlg_member_ph'] = isset($data['tlg_member_ph']) ? json_encode($data['tlg_member_ph']) : ''; TlgProfile::create($data); } $dataJson = $this->readJson('Post.json'); foreach ($dataJson['results'] as $key => $data) { $data['image'] = isset($data['image']) ? $data['image']['url'] : ''; $data['postUploadedDate'] = isset($data['postUploadedDate']) ? $data['postUploadedDate']['iso'] : ''; $data['userId'] = isset($data['userId']) ? $data['userId']['objectId'] : ''; Post::create($data); }*/ $dataJson = $this->readJson('IwomenPost.json'); foreach ($dataJson['results'] as $key => $data) { $data['image'] = isset($data['image']) ? $data['image']['url'] : ''; $data['postUploadedDate'] = isset($data['postUploadedDate']) ? $data['postUploadedDate']['iso'] : ''; $data['userId'] = isset($data['userId']) ? $data['userId']['objectId'] : ''; $data['authorId'] = isset($data['authorId']) ? $data['authorId']['objectId'] : ''; $data['postUploadPersonImg'] = isset($data['postUploadPersonImg']) ? $data['postUploadPersonImg']['url'] : ''; $data['audioFile'] = isset($data['audioFile']) ? $data['audioFile']['url'] : ''; IwomenPost::create($data); } $dataJson = $this->readJson('Resources.json'); foreach ($dataJson['results'] as $key => $data) { $data['resource_icon_img'] = isset($data['resource_icon_img']) ? $data['resource_icon_img']['url'] : ''; Resources::create($data); } $dataJson = $this->readJson('Author.json'); foreach ($dataJson['results'] as $key => $data) { $data['authorImg'] = isset($data['authorImg']) ? $data['authorImg']['url'] : ''; Author::create($data); } /* $dataJson = $this->readJson('Comment.json'); foreach ($dataJson['results'] as $key => $data) { $data['comment_created_time'] = isset($data['comment_created_time']) ? $data['comment_created_time']['iso'] : ''; $data['postId'] = isset($data['postId']) ? $data['postId']['objectId'] : ''; $data['userId'] = isset($data['userId']) ? $data['userId']['objectId'] : ''; Comment::create($data); }*/ $dataJson = $this->readJson('SubResourceDetail.json'); foreach ($dataJson['results'] as $key => $data) { $data['author_id'] = isset($data['author_id']) ? $data['author_id']['objectId'] : ''; $data['posted_date'] = isset($data['posted_date']) ? $data['posted_date']['iso'] : ''; $data['resource_id'] = isset($data['resource_id']) ? $data['resource_id']['objectId'] : ''; SubResourceDetail::create($data); } /* $dataJson = $this->readJson('SisterDownloadApp.json'); foreach ($dataJson['results'] as $key => $data) { $data['app_img'] = isset($data['app_img']) ? $data['app_img']['url'] : ''; SisterDownloadApp::create($data); } $dataJson = $this->readJson('StickerStore.json'); foreach ($dataJson['results'] as $key => $data) { $data['stickerImg'] = isset($data['stickerImg']) ? $data['stickerImg']['url'] : ''; StickerStore::create($data); } $dataJson = $this->readJson('User.json'); foreach ($dataJson['results'] as $key => $data) { $data['password'] = isset($data['bcryptPassword']) ? $data['bcryptPassword'] : ''; $data['user_profile_img'] = isset($data['user_profile_img']) ? $data['user_profile_img']['url'] : ''; $data['profileimage'] = isset($data['profileimage']) ? $data['profileimage']['url'] : ''; User::create($data); }*/ return response()->json('success'); }