Sh3ll
OdayForums


Server : Apache
System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64
User : tradze ( 1001)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /home/tradze/www/test.tradze.com/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tradze/www/test.tradze.com/app/User.php18072019
<?php

namespace App;

use App\Modules\Schedules\Repositories\BookingRepository;
use App\Modules\Services\Models\ServiceDuration;
use App\Modules\Users\Models\UserServiceDuration;
use Bican\Roles\Models\Role;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Bican\Roles\Traits\HasRoleAndPermission;
use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
//use Laravel\Cashier\Billable;
use Cmgmyr\Messenger\Traits\Messagable;

//class User extends Authenticatable implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
class User extends Authenticatable implements HasRoleAndPermissionContract
{
//    use Billable;
    use HasRoleAndPermission;
    use Messagable;
    use SoftDeletes;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'braintree_id', 'paypal_email', 'card_brand', 'card_last_four', 'trial_ends_at','api_token', 'newsletter','nr_crt',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * Get the profile associated with the user.
     */
    public function profile()
    {
        return $this->hasOne('App\Modules\Users\Models\UserProfile');
    }

    /**
     * The address that belong to the user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function address()
    {
        return $this->hasMany('App\Modules\Users\Models\UserAddress');
    }

    /**
     * The billing address that belong to the user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function billingaddress()
    {
        return $this->hasMany('App\Modules\Users\Models\UserBillingAddress');
    }

    /**
     * Get the profile associated with the user.
     */
    public function workingdays()
    {
        return $this->hasMany('App\Modules\Users\Models\UserWorkingDay');
    }

    /**
     * Get the profile associated with the user.
     */
    public function daysoff()
    {
        return $this->hasMany('App\Modules\Users\Models\UserSchedule');
    }

    /**
     * Get user mobile devices
     */
    public function devices()
    {
        return $this->hasMany('App\Modules\Users\Models\UserDevice');
    }

    /**
     * The serviceTypes that belong to the user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function servicetypes()
    {
        return $this->belongsToMany('App\Modules\Services\Models\ServiceType','users_servicetype', 'user_id', 'servicetype_id');
    }

    /**
     * The serviceCommision that belong to the user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function servicesDurationCommisions()
    {
        return $this->hasMany('App\Modules\Users\Models\UserServiceDuration');
    }

    /**
     * The zone that belongs to the therapist
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function zones()
    {
        return $this->belongsToMany('App\Modules\Postcodes\Models\Zone', 'users_area_coverage', 'user_id', 'zone_id');
    }

    /**
     * The booking that belong to the user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function bookings()
    {
        return $this->hasMany('App\Modules\Schedules\Models\BookingOrder');
    }

    /**
     * The booking that belong to the therapist.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function therapistbookings()
    {
        return $this->hasMany('App\Modules\Schedules\Models\TherapistBooking','therapist_id')->with('booking');
    }

    /**
     * The basket session that belong to the therapist.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function sessionBlockedTherapists()
    {
        return $this->hasMany('App\Modules\Schedules\Models\BasketTherapist','therapist_id');
    }

    /**
     * The booking invoice of the therapists
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function thinvoices()
    {
        return $this->morphMany('App\Modules\Invoices\Models\Invoice','invoiceable');
    }

    /**
     * Get the profile associated with the user.
     */
    public function geoLocation()
    {
        return $this->hasOne('App\Modules\Users\Models\UserLocation');
    }

    /**
     * Get blocked date hours array
     * @param $date
     * @param int $duration
     * @return array
     */
    public function blockedHours($date,$duration=60)
    {
        $results = [];
        $hours = [];

        //the buffer between bookings
        $buffer = 30;

        //has been booked in date?
        $bookings = $this->therapistbookings()->where('date',$date)
                                              ->whereHas('booking',function($query){
                                                  return $query->where('is_active',1);
                                              })
                                              ->get();

        //is in session basket for this date?
        $sessionBasketBookings = $this->sessionBlockedTherapists()->where('date',$date)
                              ->get();


        //partial days-hours off
//        DB::enableQueryLog();
        $daysHoursOff = $this->daysoff()->whereRaw('DATE(date_start) = "'.$date.'"')->get();

        //stop script if there are no results
        if (!$bookings && !$sessionBasketBookings && !$daysHoursOff)
            return $results;

        //loop throught partial days-hours off
        $booking = session('booking');

        //if (isset($booking['selected_therapists']) && count($booking['selected_therapists']))
        {
            foreach ($daysHoursOff as $offbo) {

                $date_start = Carbon::createFromFormat('d F Y - h:i A', $offbo->date_start);
                $date_end = Carbon::createFromFormat('d F Y - h:i A', $offbo->date_end);

                //hour
                $hour = $date_start->format('H:i');
                $hourMin = explode(':', $date_start->format('H:i'));
                if ($hourMin[1] > 30)
                    $hour = ($hourMin[0] + 1) . ":00";
                elseif ($hourMin[1] > 0 && $hourMin[1] < 30)
                    $hour = $hourMin[0] . ":30";

                //duration
                $duration = $date_end->diffInMinutes($date_start);

                $rest = $duration % 30;
                if ($rest > 0 and $rest < 30)
                    $duration = $duration - $rest + 30;
                else
                    $duration = $duration - $rest + 60;

                //add to results array
                $results[$hour] = [
                    'hour' => $hour,
                    'duration' => $duration,
                ];
            }
        }
        //loop throw bookings
        foreach ($bookings as $bo){
            $hour = $bo['hour'];
            $hourMin = explode(':',$bo['hour']);
            if ($hourMin[1]>30)
                $hour = ($hourMin[0]+1).":00";
            elseif ($hourMin[1]>0 && $hourMin[1]<30)
                $hour = $hourMin[0].":30";

            $results[$hour] = [
                'hour'=> $hour,
                'duration' => $bo->duration,
            ];
        } //endforeach

        //loop through session basket bookings
        foreach ($sessionBasketBookings as $sbo){
            $shour = $sbo->hour;
            $shourMin = explode(':',$sbo->hour);
            if ($shourMin[1]>30)
                $shour = ($shourMin[0]+1).":00";
            elseif ($shourMin[1]>0 && $shourMin[1]<30)
                $shour = $shourMin[0].":30";
            $results[$shour] = [
                'hour'=> $shour,
                'duration' => $sbo->duration_min,
            ];
        } //endforeach

        //create blocked hours array
        foreach($results as $r){
            $min = Carbon::createFromFormat('H:i',$r['hour'])->format('H:i');
            $max = Carbon::createFromFormat('H:i',$r['hour'])->addMinutes($r['duration']+$buffer)->format('H:i');
            if ((strtotime($max) > strtotime("23:30")) || (strtotime($max) < strtotime("08:00")))
                $max="23:30";

            $start = (int)strtotime($min);
            $end = (int)strtotime($max);
            $hours[$min] = $min;

            while ($start !== $end)
            {
                $start = strtotime('+30 minutes',$start);
                $key = date('H:i', $start);
                $hours[$key] = $key;
            } //end while

        } //endforeach

        //sort ascending
        asort($hours);

        //return blocked hours
        return $hours;
    }

    /**
     * Get user avatar image
     *
     * @return string
     */
    public function getAvatar()
    {
        $avatar = file_get_contents(asset('/themes/admin/assets/admin/pages/media/profile/avatar.png'));
        if ($this->profile){
            if ($this->profile->avatar && Storage::disk('public_images')->exists($this->profile->avatar)){
                $avatar = Storage::disk('public_images')->get($this->profile->avatar);
            }
        }

        return $avatar;
    }

    /**
     * Add Avatar image attribute
     * @return string
     */
    public function getAvatarAttribute()
    {
        return $this->getAvatar();
    }

    /**
     * Add Mode of Transport attribute
     * @return string
     */
    public function getTransportModeAttribute()
    {
        return $this->profile->transport_mode;
    }

    /**
     * Add Avatar image attribute
     * @return string
     */
    public function getAvatarUrlAttribute()
    {
        $avatar = asset('/themes/admin/assets/admin/pages/media/profile/avatar.png');
        if ($this->profile){
            if ($this->profile->avatar && Storage::disk('public_images')->exists($this->profile->avatar)){
                $avatar = url('images/'.$this->profile->avatar);
            }
        }

        return $avatar;
    }

    /**
     * Add Avatar image attribute
     * @return string
     */
    public function getPublicAvatarUrlAttribute()
    {
        $avatar = null;
        if ($this->profile){
            if ($this->profile->avatar && Storage::disk('public_images')->exists($this->profile->avatar)){
                $avatar = url('images/'.$this->profile->avatar);
            }
        }

        return $avatar;
    }

    /**
     * Get all service durations commisions
     * @return \Illuminate\Support\Collection
     */
    public function getServicesCommisionsAttribute()
    {
        $allServicesDurations = ServiceDuration::all();
        $ServicesDurations = $this->servicesDurationCommisions;

        /*user services durations*/
        foreach ($ServicesDurations as $commision)
        {
            $ServiceCommisions[$commision->services_duration_id] = [
                'services_duration_id' => $commision->services_duration_id,
                'name' => $commision->service_duration->name,
                'price' => $commision->price,
                'commision_co' => $commision->commision_co,
                'commision_th' => $commision->commision_th,
                'is_default' => $commision->service_duration->is_default,
                'is_extra' => $commision->service_duration->is_extra,
            ];
        }

        /*all services durations*/
        foreach ($allServicesDurations as $servicesDuration)
        {
            if(!isset($ServiceCommisions[$servicesDuration->id]))
            {
                $ServiceCommisions[$servicesDuration->id] = [
                    'services_duration_id' => $servicesDuration->id,
                    'name' => $servicesDuration->name,
                    'price' => $servicesDuration->price,
                    'commision_co' => $servicesDuration->commision_co,
                    'commision_th' => $servicesDuration->commision_th,
                    'is_default' => $servicesDuration->is_default,
                    'is_extra' => $servicesDuration->is_extra,
                    'is_custom' => false,
                ];
            }
            elseif (($servicesDuration->commision_co==$ServiceCommisions[$servicesDuration->id]['commision_co']) && ($servicesDuration->commision_th==$ServiceCommisions[$servicesDuration->id]['commision_th']))
            {
                $ServiceCommisions[$servicesDuration->id]['is_custom'] = false;
            }
            else
            {
                $ServiceCommisions[$servicesDuration->id]['is_custom'] = true;
            }
        }
        $ServiceCommisions = collect($ServiceCommisions);

        return $ServiceCommisions;
    }

    /**
     * Add URL to therapist booking page
     *
     * @return string
     */
    public function getUrlBookingAttribute()
    {
        $url = route('bookings.book_now');

        return $url;
    }

    public function getHasMassageTableAttribute()
    {
        if($this->profile->massage_table_status)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
 * Scope a query to only include therapists users.
 *
 * @return \Illuminate\Database\Eloquent\Builder
 */
    public function scopeOfTherapists($query)
    {
        return $query->whereHas('roles',function($query){
            return $query->where('slug','therapist');
        });
    }

    /**
     * Scope a query to only include therapists users.
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeOfClients($query)
    {
        return $query->whereHas('roles',function($query){
            return $query->where('slug','customer');
        });
    }

    /**
     * Scope a query to only include therapists users.
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeOfName($query,$search=null)
    {
        if (!$search) return $query;
        return $query->where('name', 'like', "%$search%");
    }

    /**
     * Scope a query to only include therapists users.
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeOfPhone($query,$search=null)
    {
        if (!$search) return $query;
        return $query->whereHas('profile',function($query) use ($search){
            return $query->where('mobile_number','like',"%$search%");
        });
    }


    /**
     * Method to get a specific service duration commision
     * @param $service_duration_id
     */
    public function service_commision($service_duration_id)
    {
        /**
         * TBD
         */
    }
}

ZeroDay Forums Mini