Files
Global-Jain/app/Models/Traits/Sant/Attributes/SantAttributes.php
2025-11-05 10:37:10 +05:30

257 lines
7.6 KiB
PHP

<?php
namespace App\Models\Traits\Sant\Attributes;
use Carbon\Carbon;
use App\Models\Sant;
use App\Models\Vihar;
use App\Models\SantTemp;
use App\Models\Chaturmas;
use App\Constant\Constant;
use App\Traits\ActionButtons;
trait SantAttributes
{
use ActionButtons;
/**
* @return string
*/
public function getAvatarAttribute($value): string
{
// if (!empty($value)) {
// $imagePath = Constant::SANT_IMAGE_UPLOAD_PATH . '/' . $value;
// return getImage($value, Constant::SANT_IMAGE_UPLOAD_PATH, '');
// }
if (!empty($value)) {
// Return proper public storage URL
return asset('storage/app/public/images/sants/' . $value);
//return asset('storage/images/users/' . $value);
}
return asset('public/images/misc/sant.png'); // Need to set default image
}
/**
* @return string
*/
public function getSantEditActionAttribute(): string
{
return $this->editButton(route('admin.sant.edit', $this->id), 'Edit Sant');
}
/**
* @return string
*/
public function getSantViewChaturmasActionAttribute(): string
{
return $this->chaturmasListButton(route('admin.sant.chaturmas.index', $this->id), "View Chaturmas");
}
/**
* @return string
*/
public function getSantViharListActionAttribute(): string
{
$route = route('admin.sant.vihar.index', $this->id);
return '<a href="'. $route .'" class="btn btn-icon btn-light btn-hover-primary btn-sm btn-clean mr-3" title="View Vihar">
<i class="fa fa-archway"></i>
</a>';
}
/**
* @return string
*/
public function getSantStatusActionAttribute(): string
{
if ($this->status === 1) {
return '<span class="label label-lg label-light-danger label-inline">' . __('label.inactive') . '</span>';
} else {
return '<span class="label label-lg label-light-success label-inline">' . __('label.active') . '</span>';
}
}
/**
* @return string
*/
public function getVerificationStatusActionAttribute(): string
{
if ($this->verification_status === 1) {
return '<span class="label label-lg label-light-success label-inline">' . __('label.approved') . '</span>';
} else if ($this->verification_status === 2) {
return '<span class="label label-lg label-light-success label-inline">' . __('label.in_review') . '</span>';
} else if ($this->verification_status === 3) {
return '<span class="label label-lg label-light-success label-inline">' . __('label.sent_back') . '</span>';
// } else if ($this->status === 4) {
// return '<span class="label label-lg label-light-success label-inline">' . __('label.approved') . '</span>';
} else if ($this->verification_status === 5) {
return '<span class="label label-lg label-light-danger label-inline">' . __('label.rejected') . '</span>';
}
}
/**
* @return string
*/
public function getSantCheckboxActionAttribute(): string
{
return $this->checkboxAction($this);
}
/**
* @return string
*/
public function getSantActionButtonsAttribute(): string
{
$action = $this->sant_view_chaturmas_action;
$action .= $this->sant_vihar_list_action;
$action .= $this->sant_edit_action;
//$action .= $this->sant_edit_action;
// $action =$action.$this->sant_view_action;
// if (loggedInUser()->isSuperAdmin() || loggedInUser()->isAdmin()) {
// $action =$action.$this->sant_delete_action;
// }
return $action;
}
/**
* Returns age of model in year since birth.
*/
public function getAgeAttribute()
{
if (!empty($this->attributes['birth_date'])) {
return Carbon::parse($this->attributes['birth_date'])->age;
}
return Constant::STATUS_ZERO;
}
/**
* Returns age of model in year since dikha_date.
*/
public function getDikshaYearAttribute()
{
if (!empty($this->attributes['diksha_date'])) {
return Carbon::parse($this->attributes['diksha_date'])->age;
}
return Constant::STATUS_ZERO;
}
/**
* Returns age of model in year since dikha_date.
*/
public function getIsUserFollowingAttribute()
{
if (loggedInUser()) {
return loggedInUser()->followings->contains($this->attributes['id']);
}
}
/**
* Returns sant verification status.
*/
public function getIsApprovedAttribute()
{
$sant = Sant::where([
'id' => $this->id
])->value('verification_status');
//When sant is approved
if ($sant === Constant::STATUS_ONE) {
return Constant::STATUS_ONE;
//When not approved
} else {
return Constant::STATUS_ZERO;
}
}
/**
* Returns sant verification status.
*/
public function getIsInReviewAttribute()
{
$sant = SantTemp::where([
'sant_id' => $this->id
])->value('verification_status');
//When sant is in review
if ($sant === Constant::STATUS_FOUR) {
return Constant::STATUS_ONE;
} else {
return Constant::STATUS_ZERO;
}
}
/**
* Returns sant profile owner.
*/
public function getIsOwnerAttribute()
{
$sant = Sant::where([
'id' => $this->id
])->value('created_by');
if (loggedInUser() && $sant == loggedInUser()->id) {
return Constant::STATUS_ONE;
} else {
return Constant::STATUS_ZERO;
}
}
/**
* Get upcoming vihar counts
* @return int
*/
public function getUpcomingViharCountAttribute(): int
{
$counts = Vihar::where(function ($query) {
$query->where(function ($subQuery) {
$subQuery->where('start_date', '=', Carbon::now()->toDateString())
->where('start_time', '>=', Carbon::now()->subHour(2)->toTimeString());
})->orWhere(function ($subQuery) {
$subQuery->where('start_date', '>', Carbon::now()->toDateString())
->where('start_time', '>=', '00:00:00');
});
})->where('sant_id', $this->id)->count();
// $counts = Vihar::where(function ($subQuery) {
// $subQuery->where('start_date', '>=', Carbon::now()->toDateString())
// ->where('start_time', '>=', Carbon::now()->subHour(2)->toTimeString());
// })
// ->orWhere(function ($subQuery) {
// $subQuery->where('start_date', '>', Carbon::now()->toDateString())
// ->where('start_time', '>=', '00:00:00');
// })
// ->where('sant_id', $this->id)->count();
if (!empty($counts)) {
return $counts;
} else {
return Constant::STATUS_ZERO;
}
}
/**
* Get current year & next year chaturmas count
* @return int
*/
public function getCurrentChaturmasCountAttribute(): int
{
$count = Chaturmas::join('chaturmas_dates', 'chaturmas_dates.id', '=', 'chaturmas.chaturmas_date_id')
->select('chaturmas.*')
->with('chaturmasInfo')
->where('chaturmas_dates.year', '>=', Carbon::now()->format('Y'))
->where('sant_id', $this->id)
->count();
if (!empty($count)) {
return $count;
} else {
return Constant::STATUS_ZERO;
}
}
}