Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
cursbackend
/
app
/
Models
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
User.php
| Size :
6.78
KB
Copy
<?php namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Database\Eloquent\SoftDeletes; use Tymon\JWTAuth\Contracts\JWTSubject; use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; use Carbon\Carbon; use Auth; use Str; use App\Models\PartnerPrize; use App\Models\Role; class User extends Authenticatable implements JWTSubject { use Notifiable, SoftDeletes, HasSlug; const LANGUAGE_RO = 'ro'; const LANGUAGE_EN = 'en'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = ['first_name', 'email', 'password', 'last_name', 'language', 'instance_id', 'role_id', 'avatar', 'phone', 'working_days', 'promise_time', 'one_signal_player_id', 'private_objective_ids', 'not_set_promise_mail', 'mail_sequence_day', 'manager_master_goal_ids', 'private_master_goal_ids', 'registration_email', 'report_mail', 'next_day_assigment_mail', 'net_set_promise_mail']; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; public static function boot(){ parent::boot(); self::creating(function(User $user){ if (!$user->instance_id) { $user->instance_id = Auth::user()->instance_id; } }); self::created(function(User $user){ $partner_prizes = PartnerPrize::all(); foreach ($partner_prizes as $partner_prize) { $user->user_winning_periods()->create([ 'partner_prize_id' => $partner_prize->id, 'min_date' => Carbon::now()->toDateString(), 'max_date' => Carbon::now()->addDay($partner_prize->days_step)->toDateString() ]); } }); self::deleted(function(User $user){ $user->update(['last_name' => $user->last_name.' ('.__('general.deleted').')']); $user->tags()->sync([]); $user->master_goals()->sync([]); entityDelete($user->key_result_comments); entityDelete($user->promises); entityDelete($user->tasks); entityDelete($user->notification_logs); }); } public function getSlugOptions() : SlugOptions { return SlugOptions::create() ->generateSlugsFrom(['first_name', 'last_name']) ->saveSlugsTo('slug'); } /** * Get the route key for the model. * * @return string */ public function getRouteKeyName(){ return 'slug'; } public function getJWTIdentifier(){ return $this->getKey(); } public function getJWTCustomClaims(){ return []; } public function instance(){ return $this->belongsTo(Instance::class); } public function instance_notifications(){ return $this->hasMany(InstanceNotification::class); } public function role(){ return $this->belongsTo(Role::class); } public function tags(){ return $this->belongsToMany(Tag::class); } public function objectives(){ return $this->hasMany(Objective::class); } public function key_results(){ return $this->hasMany(KeyResult::class); } public function key_result_logs(){ return $this->hasMany(KeyResultLog::class); } public function promises(){ return $this->hasMany(Promise::class); } public function tasks(){ return $this->hasMany(Task::class); } public function notification_logs(){ return $this->hasMany(NotificationLog::class, 'responsible_id'); } public function key_result_comments(){ return $this->hasMany(KeyResultComment::class); } public function user_partner_prizes(){ return $this->hasMany(UserPartnerPrize::class); } public function user_winning_periods(){ return $this->hasMany(UserWinningPeriod::class); } public function master_goals(){ return $this->belongsToMany(MasterGoal::class); } public function isAdmin(){ return $this->role->id == Role::ROLE_ADMIN; } public function isManager(){ return $this->role->id == Role::ROLE_MANAGER; } public function isWorkDay(){ $isWorkDay = Str::contains($this->working_days, strtolower(Carbon::now()->englishDayOfWeek)); return $isWorkDay; } public function isWorkDayAndPromiseTime(){ $promiseTime = $this->promise_time ? new Carbon($this->promise_time) : null; return $this->isWorkDay() && $promiseTime > Carbon::now(); } public function getFullName(){ return $this->first_name.' '.$this->last_name; } public function todayPromise(){ return $this->promises()->where('is_set', 1)->whereBetween('created_at', [Carbon::today(), Carbon::today()->endOfDay()])->first(); } public function yesterdayPromise(){ return $this->promises()->orderBy('created_at', 'DESC')->where([['is_set', 1], ['created_at', '<', Carbon::now()->startOfDay()]])->first(); } public function yesterdayPromiseIsEvaluated(){ $yesterdayPromise = $this->yesterdayPromise(); return $yesterdayPromise ? $yesterdayPromise->resolved_at != null : false; } public function routeNotificationForOneSignal() { return $this->one_signal_player_id; } // From here: https://api.slack.com/messaging/webhooks you can generate webhook url for Slack public function routeNotificationForSlack($notification) { return 'https://hooks.slack.com/services/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'; } public function routeNotificationForTelegram() { return '-1001140789704'; // return $this->telegram_user_id; } // Create a telegram bot by accesing this page: https://t.me/botfather // Copy: // Use this token to access the HTTP API: // t.me/tbfdigitalbot // 1159543966:AAH8MMEnaZj4H4U28-7x9c4Oc9YPazmBeN0 // For end user // Type a name for the newbot // create a group and add as admin the bot // set group as public // make a get request https://api.telegram.org/bot1159543966:AAH8MMEnaZj4H4U28-7x9c4Oc9YPazmBeN0/sendMessage?chat_id=@tbfsystems&text=test - replace tbfsystems with your group // get id of the group // set group back to private public function sendPasswordResetNotification($token) { $this->notify(new \App\Notifications\MailResetPasswordNotification($token)); } }
Back