MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/ezwork/app/User.php
<?php

/**
 * This file will generate the resize version of an image
 *
 * PHP version 5.6.25
 *
 * @category Resize_Image
 * @package  TinyPNG
 * @author   Sajid <sajid@artisansweb.net>
 * @license  http://www.php.net/license/3_01.txt  PHP License 3.01
 * @link     https://artisansweb.net/resize-image-php-using-tinypng
 */

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Notifications\VerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
use DB;

class User extends Authenticatable implements JWTSubject, MustVerifyEmail
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password','fname','lname','avatar','mobile_country_code_id','mobile_no',
    ];

    /**
     * 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',
    ];

    //////////////  Start relations //////////////////

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

    /**
     * Get the experience_type for the user.
     */
    public function experienceTypes()
    {
        return $this->belongsToMany(
            'App\Models\ExperienceType',
            'user_experience_types',
            'user_id',
            'experience_type_id'
        );
    }

    /**
     * Get the comments for the blog post.
     */
    public function experienceDocs()
    {
        return $this->hasMany('App\Models\UserExperienceDoc', 'user_id');
    }
    
    //////////////  End relations //////////////////
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    /**
     * Override the mail body for reset password notification mail.
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new \App\Notifications\MailResetPasswordNotification($token));
    }

    /**
     * Override the mail body for email verification notification mail.
     */
    public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail()); // my notification
    }

    /**
     * Return the user object .
     *
     * @param  Array of data to be searched
     * @return user object
     */
    public static function getUsers($data)
    {
        $user_id = $data['id'];
        $user = User::
        select(
            "users.*",
            'profiles.bio_data',
            'profiles.gender_id',
            'profiles.nationality_country_id',
            'profiles.residence_country_id',
            'profiles.profile_status_id',
            'profiles.translator_status_id',
            'translator_status.translator_status_name',
            'profiles.info_status as info_status',
            DB::raw('IF(user_skills.id > 0 , 1 ,0 ) as skill_status'),
            DB::raw('IF(user_evaluations.id > 0 , 1 ,0 ) as evaluation_status'),
            'residence_country.country as country',
            'nationality_country.nationality as nationality',
            'whatup_country.country_code_mobile as whatup_country_code',
            'mobile_country.country_code_mobile as mobile_country_code',
            'genders.gender_l',
            'user_identifications.photo_proof_type_id',
            'user_identifications.photo_proof_file',
            'user_identifications.photo_proof_status_id',
            'user_identifications.address_proof_type_id',
            'user_identifications.address_proof_file',
            'user_identifications.address_proof_status_id',
            'photo_proof_types.photo_proof_type',
            'address_proof_types.address_proof_type',
            'photo_proof_status.status_urv as photo_proof_status',
            'address_proof_status.status_urv as address_proof_status'
        )
            ->leftJoin('profiles', 'profiles.user_id', '=', 'users.id')
            ->leftJoin('translator_status', 'translator_status.id', '=', 'profiles.translator_status_id')
            ->leftJoin(
                'countrys as residence_country',
                'residence_country.id',
                '=',
                'profiles.residence_country_id'
            )
            ->leftJoin(
                'countrys as nationality_country',
                'nationality_country.id',
                '=',
                'profiles.nationality_country_id'
            )
            ->leftJoin(
                'countrys as whatup_country',
                'whatup_country.id',
                '=',
                'users.whatup_country_code_id'
            )
            ->leftJoin(
                'countrys as mobile_country',
                'mobile_country.id',
                '=',
                'users.mobile_country_code_id'
            )
            ->leftJoin('genders', 'genders.id', '=', 'profiles.gender_id')
            ->leftJoin('user_identifications', 'user_identifications.user_id', '=', 'users.id')
            ->leftJoin('photo_proof_types', 'photo_proof_types.id', '=', 'user_identifications.photo_proof_type_id')
            ->leftJoin(
                'address_proof_types',
                'address_proof_types.id',
                '=',
                'user_identifications.address_proof_type_id'
            )
            ->leftJoin(
                'status as photo_proof_status',
                'photo_proof_status.id',
                '=',
                'user_identifications.photo_proof_status_id'
            )
            ->leftJoin(
                'status as address_proof_status',
                'address_proof_status.id',
                '=',
                'user_identifications.address_proof_status_id'
            )
            ->leftJoin('user_skills', 'user_skills.user_id', '=', 'users.id')
            ->leftJoin(
                'user_evaluations',
                function ($join) use ($user_id) {
                    $join->on('user_evaluations.user_id', '=', 'users.id')
                        ->where('user_evaluations.evaluation_status_id', '=', 4);
                }
            )

        ->where('users.id', $data['id'])->groupBy('users.id')->first();
        return $user;
    }

    /**
     * Return the translators list .
     *
     * @param  Array of data to be searched
     * @return translators list
     */
    public static function getTranslators($request)
    {
        $translators = User::
        select(
            "users.*",
            'profiles.bio_data',
            'profiles.gender_id',
            'profiles.nationality_country_id',
            'profiles.residence_country_id',
            'profiles.info_status',
            'profiles.skill_status',
            'profiles.evaluation_status',
            'profiles.translator_status_id',
            'translator_status.translator_status_name',
            'profiles.profile_status_id',
            'residence_country.country as country',
            'nationality_country.nationality as nationality',
            'whatup_country.country_code_mobile as whatup_country_code',
            'mobile_country.country_code_mobile as mobile_country_code',
            'genders.gender_l',
            'status.status_ab as status_active_block',
            DB::raw('concat(UPPER(LEFT(users.fname,1)),UPPER(LEFT(users.lname,1))) as short_name'),
            DB::raw(
                'group_concat(DISTINCT CONCAT(from_languages.language_s,"-",to_languages.language_s)
                SEPARATOR ", ") as languages_short'
            ),
            DB::raw("COUNT(user_contracts.id) AS no_of_contract")
        )
            ->join('status', 'status.id', '=', 'users.status_id')
            ->leftJoin('profiles', 'profiles.user_id', '=', 'users.id')
            ->leftJoin(
                'countrys as residence_country',
                'residence_country.id',
                '=',
                'profiles.residence_country_id'
            )
            ->leftJoin(
                'countrys as nationality_country',
                'nationality_country.id',
                '=',
                'profiles.nationality_country_id'
            )
            ->leftJoin(
                'countrys as whatup_country',
                'whatup_country.id',
                '=',
                'users.whatup_country_code_id'
            )
            ->leftJoin(
                'countrys as mobile_country',
                'mobile_country.id',
                '=',
                'users.mobile_country_code_id'
            )
            ->leftJoin('genders', 'genders.id', '=', 'profiles.gender_id')
            ->leftJoin('user_skills', 'user_skills.user_id', '=', 'users.id')
            ->leftJoin(
                'translator_status',
                'translator_status.id',
                '=',
                'profiles.translator_status_id'
            )
            ->leftJoin('user_skill_pairs', 'user_skill_pairs.user_id', '=', 'users.id')
            ->leftJoin(
                'languages as from_languages',
                'from_languages.id',
                '=',
                'user_skill_pairs.from_language_id'
            )
            ->leftJoin(
                'languages as to_languages',
                'to_languages.id',
                '=',
                'user_skill_pairs.to_language_id'
            )
            ->leftJoin('user_contracts', 'user_contracts.user_id', '=', 'users.id')

            
            ->where('users.role', 2);

        if ($request->search_by && $request->search_by != '') {
            $searchBy = $request->search_by ;
            $translators = $translators->where(
                function ($query) use ($searchBy) {
                    $query->where('users.name', 'like', "%$searchBy%");
                    $query->orWhere('from_languages.language_l', 'like', "%$searchBy%");
                    $query->orWhere('to_languages.language_l', 'like', "%$searchBy%");
                    $query->orWhere('translator_status.translator_status_name', 'like', "%$searchBy%");
                }
            );
            /*->orWhere('languages_short', 'like', "%$searchBy%")*/;
        }
        $translators = $translators->groupBy('users.id');
        if ($request->sort_by) {
            $sortBy = explode('_', $request->sort_by);
            $sortOrder = $sortBy[1];
            if ($sortBy[0] == 'name') {
                $translators = $translators->orderBy('users.name', "$sortOrder");
            } elseif ($sortBy[0] == 'date') {
                $translators = $translators->orderBy('users.created_at', "$sortOrder");
            } else {
                $translators = $translators->orderBy('users.id', 'desc');
            }
        } else {
            $translators = $translators->orderBy('users.id', 'desc');
        }
        $page = 0 ;
        if ($request->page) {
            $page = $request->page ;
        }
        $translators = $translators->offset($page * 10)->limit(10);

        $translators = $translators->get();
        return $translators;
    }
}