api code global jain
This commit is contained in:
155
app/Models/Traits/Sangh/Attributes/SanghAttributes.php
Normal file
155
app/Models/Traits/Sangh/Attributes/SanghAttributes.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
8
app/Models/Traits/Sangh/Methods/SanghMethods.php
Normal file
8
app/Models/Traits/Sangh/Methods/SanghMethods.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits\Sangh\Methods;
|
||||
|
||||
trait SanghMethods
|
||||
{
|
||||
//
|
||||
}
|
||||
91
app/Models/Traits/Sangh/Relationships/SanghRelationships.php
Normal file
91
app/Models/Traits/Sangh/Relationships/SanghRelationships.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits\Sangh\Relationships;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Sant;
|
||||
use App\Models\User;
|
||||
use App\Models\Sangh;
|
||||
use App\Models\Vihar;
|
||||
use App\Models\Dharma;
|
||||
use App\Models\Sampraday;
|
||||
use App\Constant\Constant;
|
||||
use App\Models\SantFollower;
|
||||
use App\Models\SantRelation;
|
||||
use App\Models\KarmaPointsTransaction;
|
||||
|
||||
/**
|
||||
* Trait SanghRelationships
|
||||
*
|
||||
*/
|
||||
trait SanghRelationships
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function dharma()
|
||||
{
|
||||
return $this->belongsTo(Dharma::class, 'dharma_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function sampraday()
|
||||
{
|
||||
return $this->belongsTo(Sampraday::class, 'sampraday_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sant followers.
|
||||
*/
|
||||
public function followers()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'sangh_followers', 'sangh_id', 'user_id')->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sant followings.
|
||||
*/
|
||||
public function followings()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'sangh_followers', 'user_id', 'sangh_id')->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sant followings.
|
||||
*/
|
||||
public function sanghMembers()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'sangh_members', 'sangh_id', 'user_id')->withTimestamps()->withPivot('core_committee', 'role', 'status', 'is_owner');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function createdBy()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function updatedBy()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'updated_by', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* add points for for registration.
|
||||
*/
|
||||
public function addPoints()
|
||||
{
|
||||
return $this->morphMany(KarmaPointsTransaction::class, 'pointable');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
$this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
8
app/Models/Traits/Sangh/Scopes/SanghScope.php
Normal file
8
app/Models/Traits/Sangh/Scopes/SanghScope.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits\Sangh\Scopes;
|
||||
|
||||
trait SanghScope
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user