226 lines
7.2 KiB
PHP
226 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Traits\SantTemp\Attributes;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Models\Vihar;
|
|
use App\Models\SantTemp;
|
|
use App\Models\Chaturmas;
|
|
use App\Constant\Constant;
|
|
use App\Traits\ActionButtons;
|
|
|
|
trait SantTempAttributes
|
|
{
|
|
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/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');
|
|
}
|
|
|
|
/**
|
|
*/
|
|
public function getSantViewChaturmasActionAttribute()
|
|
{
|
|
if (!empty($this->chaturmas)) {
|
|
if ($this->chaturmas()->count() > 0) {
|
|
return $this->chaturmasPendingListButton(route('admin.sant.chaturmas.index', $this->sant_id), "View Chaturmas");
|
|
} else {
|
|
return $this->chaturmasListButton(route('admin.sant.chaturmas.index', $this->sant_id), "View Chaturmas");
|
|
}
|
|
} else {
|
|
return $this->chaturmasListButton(route('admin.sant.chaturmas.index', $this->sant_id), "View Chaturmas");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getSantViharListActionAttribute(): string
|
|
{
|
|
$route = route('admin.sant.vihar.index', $this->sant_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-warning label-inline">' . __('label.in_review') . '</span>';
|
|
} else if ($this->verification_status == 3) {
|
|
return '<span class="label label-lg label-light-info label-inline">' . __('label.sent_back') . '</span>';
|
|
} else if ($this->verification_status == 4) {
|
|
return '<span class="label label-lg label-light-warning label-inline">' . __('label.in_review') . '</span>';
|
|
} else if ($this->verification_status == 5) {
|
|
return '<span class="label label-lg label-light-info label-inline">' . __('label.sent_back') . '</span>';
|
|
} else if ($this->verification_status == 6) {
|
|
return '<span class="label label-lg label-light-danger label-inline">' . __('label.rejected') . '</span>';
|
|
} else {
|
|
return '-';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getSantCheckboxActionAttribute(): string
|
|
{
|
|
return $this->santCheckboxAction($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 =$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()
|
|
{
|
|
return loggedInUser()->followings->contains($this->attributes['id']);
|
|
}
|
|
|
|
/**
|
|
* Returns sant profile owner.
|
|
*/
|
|
public function getIsOwnerAttribute()
|
|
{
|
|
$sant = SantTemp::where([
|
|
'sant_id' => $this->id
|
|
])->value('created_by');
|
|
|
|
if ($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->sant_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->sant_id)
|
|
->count();
|
|
|
|
if (!empty($count)) {
|
|
return $count;
|
|
} else {
|
|
return Constant::STATUS_ZERO;
|
|
}
|
|
}
|
|
}
|