Get users active tags, favored tags, user colleagues

1010 0 0 0

Last Updated : 2024-04-28 13:42:42

Goviq, to get user colleagues, or user active tags, favored tags, or system tags

Here is a full function to do this:


public function activeTags(Request $request) {
if (\Request::isMethod('post')) {
//Process data
$ElasticSearch = new ElasticSearch();
return $ElasticSearch->searchActiveTags($request) ;
} else {
//Show the form
$loggedInUserId = Auth::user()->id ;
$loggedInUser = UserModel::find($loggedInUserId);

$userFavoredTags = UserFavoredTagModel::where('user_id', $loggedInUserId)->pluck("tags")->first();
//##$tags = explode(",", $userFavoredTags);
$allTags = $userFavoredTags;

//Get his colleagues
//$colleagues = $this->getUserColleagues($loggedInUserId);
$colleaguesFavoredTags = '';
$colleaguesTagsForBills = '';
if($loggedInUser->company != 0)
{
$companyId = $loggedInUser->company ;
$colleagues = UserModel::with(['favoredTags','userTagsForBills'])->where("company",$companyId)->where("id","!=",$loggedInUserId)->get(['id','email']);

foreach($colleagues as $colleague){
if(isset($colleague->favoredTags->tags)){
$colleaguesFavoredTags .= ','.$colleague->favoredTags->tags;
}

foreach($colleague->userTagsForBills as $userTagsForBill){
if($userTagsForBill->tags != '') {
$colleaguesTagsForBills .= ','.$userTagsForBill->tags;
}
}
}

}
$allTags .= $colleaguesFavoredTags;
$allTags .= $colleaguesTagsForBills;

//Get Admin Tags for federal bills
$adminTagsForBills = '';
$adminTagsForFederalBills = FederalBillModel::get(['tags']);
foreach($adminTagsForFederalBills as $adminTagsForFederalBill) {
if($adminTagsForFederalBill->tags !='')
$adminTagsForBills .= ','.$adminTagsForFederalBill->tags ;
}

//get admin tags for provincial bills
$adminTagsForProvincialBills = ProvincialBillModel::get(['tags']);
foreach($adminTagsForProvincialBills as $adminTagsForProvincialBill) {
if($adminTagsForProvincialBill->tags !='')
$adminTagsForBills .= ','.$adminTagsForProvincialBill->tags ;
}

$allTags .= $adminTagsForBills;

$tags = explode(",", $allTags);
$tags = array_unique($tags);
return view('front.members.activetags.activetags', compact(['tags']));
}
}

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .