156 lines
4.5 KiB
PHP
156 lines
4.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Traits\Sangh\Attributes;
|
||
|
|
|
||
|
|
use App\Constant\Constant;
|
||
|
|
use App\Models\SanghMember;
|
||
|
|
use App\Traits\ActionButtons;
|
||
|
|
|
||
|
|
trait SanghAttributes
|
||
|
|
{
|
||
|
|
use ActionButtons;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getAvatarAttribute($value): string
|
||
|
|
{
|
||
|
|
// if (!empty($value)) {
|
||
|
|
// $imagePath = Constant::SANGH_IMAGE_UPLOAD_PATH . '/' . $value;
|
||
|
|
// return getImage($value, Constant::SANGH_IMAGE_UPLOAD_PATH, 'medium');
|
||
|
|
// }
|
||
|
|
|
||
|
|
if (!empty($value)) {
|
||
|
|
// Return proper public storage URL
|
||
|
|
return asset('storage/app/public/images/sanghs/' . $value);
|
||
|
|
|
||
|
|
//return asset('storage/images/users/' . $value);
|
||
|
|
}
|
||
|
|
return asset('public/images/misc/sangh.png'); // Need to set default image
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getBankQrCodeAttribute($value): string
|
||
|
|
{
|
||
|
|
if (!empty($value)) {
|
||
|
|
$imagePath = Constant::SANGH_IMAGE_UPLOAD_PATH . '/' . $value;
|
||
|
|
return getImage($value, Constant::SANGH_IMAGE_UPLOAD_PATH, 'medium');
|
||
|
|
}
|
||
|
|
return ""; // Need to set default image
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns age of model in year since dikha_date.
|
||
|
|
*/
|
||
|
|
public function getIsUserFollowingAttribute()
|
||
|
|
{
|
||
|
|
return loggedInUser()->sanghFollowings->contains($this->attributes['id']);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns age of model in year since dikha_date.
|
||
|
|
*/
|
||
|
|
public function getIsMemberAttribute()
|
||
|
|
{
|
||
|
|
// 0 => Not member, 1 Admin, 2 Member
|
||
|
|
$memberStatus = 0;
|
||
|
|
$sanghId = $this->attributes['id'];
|
||
|
|
$loggedInUserId = loggedInUser()->id;
|
||
|
|
$isMember = loggedInUser()->whereHas('sanghMembers', function($query) use ($sanghId, $loggedInUserId){
|
||
|
|
$query->where('sangh_members.core_committee', 0)->where('sangh_members.sangh_id', $sanghId)
|
||
|
|
->where('sangh_members.status', 1)
|
||
|
|
->where('sangh_members.user_id', $loggedInUserId);
|
||
|
|
})->with('sanghMembers')->first();
|
||
|
|
|
||
|
|
if ($isMember) {
|
||
|
|
$memberStatus = 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
$isAdmin = loggedInUser()->whereHas('sanghMembers', function($query) use ($sanghId, $loggedInUserId) {
|
||
|
|
$query->where('sangh_members.core_committee', 1)->where('sangh_members.sangh_id', $sanghId)
|
||
|
|
->where('sangh_members.status', 1)
|
||
|
|
->where('sangh_members.user_id', $loggedInUserId);
|
||
|
|
})->with('sanghMembers')->first();
|
||
|
|
|
||
|
|
if ($isAdmin) {
|
||
|
|
$memberStatus = 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $memberStatus;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns age of model in year since dikha_date.
|
||
|
|
*/
|
||
|
|
public function getIsRequestedAttribute()
|
||
|
|
{
|
||
|
|
return loggedInUser()->sanghMembers->contains($this->attributes['id']);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns request sent status.
|
||
|
|
*/
|
||
|
|
public function getSanghMemberStatusAttribute()
|
||
|
|
{
|
||
|
|
$addedByAdmin = SanghMember::where('user_id', loggedInUser()->id)
|
||
|
|
->where('sangh_id', $this->id)
|
||
|
|
->where('user_id', '!=', Constant::NULL)
|
||
|
|
->where('added_by', '!=', loggedInUser()->id)
|
||
|
|
->value('status');
|
||
|
|
|
||
|
|
$requestedToSangh = SanghMember::where('user_id', loggedInUser()->id)
|
||
|
|
->where('sangh_id', $this->id)
|
||
|
|
->where('user_id', '!=', Constant::NULL)
|
||
|
|
->where('added_by', loggedInUser()->id)
|
||
|
|
->value('status');
|
||
|
|
|
||
|
|
//When added by admin/core committee and status accepted
|
||
|
|
if ($addedByAdmin === Constant::STATUS_ONE || $requestedToSangh === Constant::STATUS_ONE) {
|
||
|
|
return Constant::STATUS_ONE;
|
||
|
|
|
||
|
|
//When logged in user requested by Sangh
|
||
|
|
} elseif ($addedByAdmin === Constant::STATUS_ZERO) {
|
||
|
|
return Constant::STATUS_TWO;
|
||
|
|
|
||
|
|
//When logged in user requested to Sangh
|
||
|
|
} elseif ($requestedToSangh === Constant::STATUS_ZERO) {
|
||
|
|
return Constant::STATUS_THREE;
|
||
|
|
|
||
|
|
//When no requests
|
||
|
|
} else {
|
||
|
|
return Constant::STATUS_ZERO;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getSanghStatusLabelAttribute()
|
||
|
|
{
|
||
|
|
return $this->requestStatusLabel($this->sangh_status);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getSanghCheckboxActionAttribute(): string
|
||
|
|
{
|
||
|
|
return $this->checkboxAction($this);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getViewButtonAttribute()
|
||
|
|
{
|
||
|
|
return $this->viewButton(route('admin.sanghs.show', $this->id),'View');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return mixed
|
||
|
|
*/
|
||
|
|
public function getActionButtonsAttribute()
|
||
|
|
{
|
||
|
|
return $this->view_button;
|
||
|
|
}
|
||
|
|
}
|