Esempio n. 1
0
    public function postByUser($utype, $id)
    {
        if (Auth::check()) {
            $title = 'postByUser';
            $groups = array();
            $filter = Filter::where('post_type', '=', 'job')->where('from_user', '=', Auth::user()->id)->first();
            $skillfilter = Filter::where('from_user', '=', Auth::user()->id)->where('post_type', '=', 'skill')->first();
            if ($utype == 'ind') {
                $postuser = Induser::find($id);
                $jobPosts = Postjob::orderBy('id', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'job')->where('postjobs.individual_id', '=', $id)->where('postjobs.inactive', '=', 0)->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                $skillPosts = Postjob::orderBy('id', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'skill')->where('postjobs.individual_id', '=', $id)->where('postjobs.inactive', '=', 0)->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                $links = DB::select('select id from indusers
									where indusers.id in (
											select connections.user_id as id from connections
											where connections.connection_user_id=?
											 and connections.status=1
											union 
											select connections.connection_user_id as id from connections
											where connections.user_id=?
											 and connections.status=1
								)', [Auth::user()->induser_id, Auth::user()->induser_id]);
                $links = collect($links);
                $linksPending = DB::select('select id from indusers
											where indusers.id in (
													select connections.connection_user_id as id from connections
													where connections.user_id=?
													 and connections.status=0
											)', [Auth::user()->induser_id]);
                $linksPending = collect($linksPending);
                $linksApproval = DB::select('select id from indusers
											where indusers.id in (
													select connections.user_id as id from connections
													where connections.connection_user_id=?
													 and connections.status=0
											)', [Auth::user()->induser_id]);
                $linksApproval = collect($linksApproval);
                if (Auth::user()->identifier == 1) {
                    $share_links = Induser::whereRaw('indusers.id in (
												select connections.user_id as id from connections
												where connections.connection_user_id=?
												 and connections.status=1
												union 
												select connections.connection_user_id as id from connections
												where connections.user_id=?
												 and connections.status=1
									)', [Auth::user()->induser_id, Auth::user()->induser_id])->get(['id', 'fname'])->lists('fname', 'id');
                    $share_groups = Group::leftjoin('groups_users', 'groups_users.group_id', '=', 'groups.id')->where('groups.admin_id', '=', Auth::user()->induser_id)->orWhere('groups_users.user_id', '=', Auth::user()->induser_id)->groupBy('groups.id')->get(['groups.id as id', 'groups.group_name as name'])->lists('name', 'id');
                }
                $groups = Group::leftjoin('groups_users', 'groups_users.group_id', '=', 'groups.id')->where('groups.admin_id', '=', Auth::user()->induser_id)->orWhere('groups_users.user_id', '=', Auth::user()->induser_id)->groupBy('groups.id')->get(['groups.id as id'])->lists('id');
            } elseif ($utype == 'corp') {
                $postuser = Corpuser::find($id);
                $jobPosts = Postjob::orderBy('id', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'job')->where('postjobs.individual_id', '=', $id)->where('postjobs.inactive', '=', 0)->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
                $skillPosts = Postjob::orderBy('id', 'desc')->with('indUser', 'corpUser', 'postActivity', 'taggedUser', 'taggedGroup')->where('post_type', '=', 'skill')->where('postjobs.individual_id', '=', $id)->where('postjobs.inactive', '=', 0)->where('individual_id', '!=', Auth::user()->induser_id)->paginate(15);
            }
            $skills = Skills::lists('name', 'id');
            $share_links = "";
            $share_groups = "";
            $groups = "";
            if (Auth::user()->induser_id != null) {
                $following = DB::select('select id from corpusers 
										 where corpusers.id in (
											select follows.corporate_id as id from follows
											where follows.individual_id=?
									)', [Auth::user()->induser_id]);
                $following = collect($following);
            }
            if (Auth::user()->corpuser_id != null) {
                $following = DB::select('select id from indusers
										 where indusers.id in (
											select follows.individual_id as id from follows
											where follows.corporate_id=?
									)', [Auth::user()->corpuser_id]);
                $following = collect($following);
            }
            if (Auth::user()->identifier == 1) {
                $userSkills = Induser::where('id', '=', Auth::user()->induser_id)->first(['linked_skill']);
                $userSkills = array_map('trim', explode(',', $userSkills->linked_skill));
                unset($userSkills[count($userSkills) - 1]);
            }
            return view('pages.home', compact('jobPosts', 'share_links', 'share_groups', 'skillPosts', 'linksPending', 'linksApproval', 'title', 'links', 'groups', 'following', 'userSkills', 'skills', 'postuser', 'filter', 'skillfilter'));
            // return $userSkills;
        } else {
            return redirect('login');
        }
    }