Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/job-board.corals.io/Corals/modules/Jobs/database/seeds/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/job-board.corals.io/Corals/modules/Jobs/database/seeds/JobsDummyData.php
<?php

namespace Corals\Modules\Jobs\database\seeds;

use Carbon\Carbon;
use Corals\Modules\Jobs\Models\Branch;
use Corals\Modules\Jobs\Models\Candidate;
use Corals\Modules\Jobs\Models\Education;
use Corals\Modules\Jobs\Models\Employer;
use Corals\Modules\Jobs\Models\Job;
use Corals\Modules\Jobs\Models\JobApplication;
use Corals\Modules\Jobs\Models\Work;
use Corals\Modules\Subscriptions\Models\Feature;
use Corals\Modules\Subscriptions\Models\Plan;
use Corals\Modules\Subscriptions\Models\Product;
use Corals\Modules\Utility\Facades\ListOfValue\ListOfValues;
use Corals\Modules\Utility\Models\Address\Location;
use Corals\Modules\Utility\Models\Category\Category;
use Corals\User\Models\User;
use Faker\Generator as Faker;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class JobsDummyData extends Seeder
{
    /**
     * @var Faker|mixed
     */
    private $faker;
    protected array $locationIds;
    protected array $categoryIds;
    protected $users = null;

    /**
     * @return void
     * @throws BindingResolutionException
     */
    public function run()
    {
        $this->faker = app()->make(Faker::class);
        $this->createLocations();
        $this->createCategories();

        foreach (['member', 'jobs-admin'] as $role) {
            foreach (range(0, random_int(0, 20)) as $i) {
                try {
                    $this->createUsers($role);
                } catch (\Exception $exception) {
                    logger('users');
                    logger($exception->getMessage());
                }
            }
        }

        try {
            $this->createProducts();
        } catch (\Exception $exception) {
            logger('products');
            logger($exception->getMessage());
        }
    }

    protected function createLocations()
    {
        $locations = [];

        foreach (range(0, 20) as $i) {
            $address = $this->faker->streetAddress;

            $locations[] = [
                'address' => $address,
                'name' => $address,
                'slug' => Str::slug($address),
                'lat' => $this->faker->latitude,
                'long' => $this->faker->longitude,
                'module' => 'Jobs',
                'status' => 'active',
            ];
        }

        Location::query()->insert($locations);
        $this->locationIds = Location::query()->where('module', 'Jobs')->pluck('id')->toArray();
        $this->locationIds = array_combine($this->locationIds, $this->locationIds);
    }

    protected function createCategories()
    {
        $categories = [];

        $jobCategories = [
            'Web Development',
            'Web Design',
            'Logo Design',
            'Graphic Design',
            'Articles Writing',
            'Mobile Development',
            'Data Entry',
            'Database Administration',
            'Brochures Design',
            'Devops'
        ];

        foreach ($jobCategories as $jobCategory) {
            $categories[] = [
                'name' => $jobCategory,
                'slug' => Str::slug($jobCategory),
                'module' => 'Jobs',
                'status' => 'active',
                'properties' => '{"thumbnail_link":"https://placeimg.com/640/480/tech"}',
            ];
        }

        Category::query()->insert($categories);

        $this->categoryIds = Category::query()->where('module', 'Jobs')->pluck('id')->toArray();
        $this->categoryIds = array_combine($this->categoryIds, $this->categoryIds);
    }

    protected function createUsers($role)
    {
        tap([
            'name' => $this->faker->firstName,
            'last_name' => $this->faker->lastName,
            'email' => $this->faker->unique()->safeEmail,
            'password' => '123456',
            'phone_number' => $this->faker->numerify('(###) ### ###')
        ], function ($userData) use ($role) {
            $user = User::create($userData);
            $user->assignRole($role);

            if ($user->hasRole('jobs-admin')) {
                try {
                    $this->createEmployer($user);
                } catch (\Exception $exception) {
                    logger('employer');
                    logger($exception->getMessage());
                }
            }
            if ($user->hasRole('member')) {
                try {
                    $this->createCandidate($user);
                } catch (\Exception $exception) {
                    logger('candidate');
                    logger($exception->getMessage());
                }
            }
        });
    }

    protected function createEmployer($user)
    {
        $salaryMin = random_int(4, 7) * 1000;
        $salaryMax = random_int(8, 20) * 1000;
        tap(Employer::create([
            'user_id' => $user->id,
            'name' => $this->faker->name,
            'description' => $this->faker->text(),
            'location_id' => $this->faker->randomKey($this->locationIds),
            'salary' => "$salaryMin - $salaryMax",
            'field_code' => $this->faker->randomKey(ListOfValues::get('company-fields')),
            'properties' => ["thumbnail_link" => "https://placeimg.com/640/480/tech"],
        ]), function (Employer $employer) {
            foreach (range(1, random_int(20, 50)) as $i) {
                try {
                    $this->createJobs($employer);
                } catch (\Exception $exception) {
                    logger('jobs');
                    logger($exception->getMessage());
                }
            }
            foreach (range(1, 4) as $i) {
                try {
                    $this->createBranches($employer);
                } catch (\Exception $exception) {
                    logger('branches');
                    logger($exception->getMessage());
                }
            }
        });
    }

    protected function createJobs($employer)
    {
        $title = $this->faker->jobTitle();
        $startDate = Carbon::parse($this->faker->dateTimeThisYear());
        $endDate = $startDate->copy()->addDays(random_int(5, 50));
        $salary = random_int(3, 14) * 1000;

        tap(Job::create([
            'owner_id' => $employer->id,
            'title' => $title,
            'slug' => Str::slug($title),
            'description' => $this->faker->text(),
            'short_description' => $this->faker->text(),
            'job_type' => $this->faker->randomKey(ListOfValues::get('job-types')),
            'experience_level' => $this->faker->randomKey(ListOfValues::get('experience-level')),
            'starts_at' => $startDate->format('Y-m-d'),
            'ends_at' => $endDate->format('Y-m-d'),
            'location_id' => $this->faker->randomKey($this->locationIds),
            'salary' => $salary,
            'status' => $this->faker->randomKey(trans('Jobs::attributes.job.status_options')),
            'properties' => ["thumbnail_link" => "https://placeimg.com/640/480/tech"],
        ]), function (Job $job) use ($startDate, $endDate) {
            $this->createSchedule($job, $startDate, $endDate);

            $categories = array_slice($this->categoryIds, random_int(0, count($this->categoryIds)), random_int(1, 3));
            $job->categories()->sync($categories ?? []);
        });
    }

    protected function createSchedule($job, $start, $end)
    {
        $schedule = [];
        foreach (range(1, 5) as $i) {
            $schedule = [];
            $date = $this->faker->dateTimeBetween($start, $end)->format('Y-m-d');
            $schedule['date'] = $date;
            $schedule['times'] = [];
            foreach (range(1, 4) as $j) {
                $hour = random_int(10, 18);
                $minute = random_int(0, 1) ? '30' : '00';
                $time = $hour . ':' . $minute . ':00';
                $schedule['times'] [] = $time;
            }
            $schedules[] = $schedule;

            if ($job->status == 'published') {
                try {
                    $this->createJobApplication($job, $date, $time);
                } catch (\Exception $exception) {
                    logger('jobApplication');
                    logger($exception->getMessage());
                }
            }
        }

        $job->update(['schedule' => $schedules]);
    }

    protected function createJobApplication($job, $date, $time)
    {
        if (!$this->users) {
            $users = User::query()->whereHas('roles', function (Builder $query) {
                $query->where('name', 'member');
            })->pluck('id')->toArray();

            $this->users = array_combine($users, $users);
        }

        tap(JobApplication::create([
            'job_id' => $job->id,
            'user_id' => $this->faker->randomKey($this->users),
            'user_notes' => $this->faker->text(),
            'schedule_date' => $date,
            'schedule_time' => $time,
        ]), function (JobApplication $jobApplication) {
        });
    }

    protected function createCandidate($user)
    {
        $salaryMin = random_int(4, 5) * 1000;
        $salaryMax = random_int(6, 7) * 1000;

        tap(Candidate::create([
            'user_id' => $user->id,
            'profession' => $this->faker->randomKey(ListOfValues::get('professions')),
            'location_id' => $this->faker->randomKey($this->locationIds),
            'salary' => "$salaryMin - $salaryMax",
        ]), function (Candidate $candidate) {
            foreach (range(1, 4) as $i) {
                try {
                    $this->createWorkExperiences($candidate);
                } catch (\Exception $exception) {
                    logger('workExperiences');
                    logger($exception->getMessage());
                }

                try {
                    $this->createEducations($candidate);
                } catch (\Exception $exception) {
                    logger('educations');
                    logger($exception->getMessage());
                }
            }
        });
    }

    protected function createBranches($employer)
    {
        tap(Branch::create([
            'employer_id' => $employer->id,
            'name' => $this->faker->jobTitle(),
            'location_id' => $this->faker->randomKey($this->locationIds),
            'short_description' => $this->faker->text(),
        ]), function (Branch $branch) {
        });
    }

    protected function createWorkExperiences($candidate)
    {
        $startDate = Carbon::parse($this->faker->dateTimeThisYear());
        $endDate = $startDate->copy()->addDays(random_int(5, 50));

        tap(Work::create([
            'candidate_id' => $candidate->id,
            'title' => $this->faker->jobTitle(),
            'short_description' => $this->faker->text(),
            'starts_at' => $startDate->format('Y-m-d'),
            'ends_at' => $endDate->format('Y-m-d'),
        ]), function (Work $work) {
        });
    }

    protected function createEducations($candidate)
    {
        $startDate = Carbon::parse($this->faker->dateTimeThisYear());
        $endDate = $startDate->copy()->addDays(random_int(5, 50));
        $educations = [
            'Allergy and immunology',
            'Anesthesiology',
            'Dermatology',
            'Diagnostic radiology',
            'Emergency medicine',
            'Family medicine',
            'Internal medicine',
            'Medical genetics',
            'Neurology',
            'Nuclear medicine',
            'Obstetrics and gynecology',
            'Ophthalmology',
            'Pathology',
            'Pediatrics',
            'Physical medicine and rehabilitation',
            'Psychiatry',
            'Radiation oncology',
            'Surgery',
            'Urology'
        ];
        tap(Education::create([
            'candidate_id' => $candidate->id,
            'title' => $this->faker->randomElement($educations),
            'short_description' => $this->faker->text(),
            'starts_at' => $startDate->format('Y-m-d'),
            'ends_at' => $endDate->format('Y-m-d'),
        ]), function (Education $education) {
        });
    }


    protected function createProducts()
    {
        DB::table('products')->delete();

        tap(Product::create([
            'name' => 'Job Plans',
            'description' => $this->faker->text(),
        ]), function (Product $product) {
            $futures = [
                'Jobs' => [
                    'type' => 'quantity'
                ],
                'Job Applications' => [
                    'type' => 'text',
                ],
                'Talent Matching' => [],
                'Reports' => [],
                'Analytics' => [],
            ];
            foreach ($futures as $future => $details) {
                try {
                    $this->createFeatures($product, $future, $details);
                } catch (\Exception $exception) {
                    logger('features');
                    logger($exception->getMessage());
                }
            }

            $plans = [
                'Basic' => [
                    'details' => [
                        'freePlan' => 1,
                        'recommended' => 0,
                        'price' => 25 + random_int(20, 70),
                    ],
                    'features' => [
                        'Jobs' => random_int(5, 30),
                        'Job Applications' => $this->faker->randomElement(['limited', 'unlimited']),
                        'Talent Matching' => random_int(0, 1),
                        'Reports' => random_int(0, 1),
                        'Analytics' => random_int(0, 1),
                    ]
                ],
                'Pro' => [
                    'details' => [
                        'freePlan' => 0,
                        'recommended' => 0,
                        'price' => 25 + random_int(20, 70),
                    ],
                    'features' => [
                        'Jobs' => random_int(5, 30),
                        'Job Applications' => $this->faker->randomElement(['limited', 'unlimited']),
                        'Talent Matching' => random_int(0, 1),
                        'Reports' => random_int(0, 1),
                        'Analytics' => random_int(0, 1),
                    ]
                ],
                'Business' => [
                    'details' => [
                        'freePlan' => 0,
                        'recommended' => 1,
                        'price' => 25 + random_int(20, 70),
                    ],
                    'features' => [
                        'Jobs' => random_int(5, 30),
                        'Job Applications' => $this->faker->randomElement(['limited', 'unlimited']),
                        'Talent Matching' => random_int(0, 1),
                        'Reports' => random_int(0, 1),
                        'Analytics' => random_int(0, 1),
                    ]
                ],
                'Elite' => [
                    'details' => [
                        'freePlan' => 0,
                        'recommended' => 0,
                        'price' => 25 + random_int(20, 70),
                    ],
                    'features' => [
                        'Jobs' => random_int(5, 30),
                        'Job Applications' => $this->faker->randomElement(['limited', 'unlimited']),
                        'Talent Matching' => random_int(0, 1),
                        'Reports' => random_int(0, 1),
                        'Analytics' => random_int(0, 1),
                    ]
                ],
            ];

            foreach ($plans as $plan => $values) {
                try {
                    $this->createPlans($product, $plan, $values);
                } catch (\Exception $exception) {
                    logger('plans');
                    logger($exception->getMessage());
                }
            }
        });
    }

    protected function createPlans($product, $plan, $values)
    {
        tap(Plan::create([
            'name' => $plan,
            'code' => random_int(1000000, 9999999),
            'price' => $values['details']['price'],
            'product_id' => $product->id,
            'description' => $this->faker->text(),
            'free_plan' => $values['details']['freePlan'],
            'recommended' => $values['details']['recommended'],
        ]), function (Plan $plan) use ($product, $values) {
            $features = $values['features'];
            $allFeatures = Feature::where('product_id', $product->id)->get();

            foreach ($features as $feature => $value) {
                $featureId = $allFeatures->where('name', $feature)->first();
                $plan->features()->attach([
                    $featureId->id => ['value' => $value],
                ]);


            }
        });
    }

    protected function createFeatures($product, $future, $details)
    {
        tap(Feature::create([
            'name' => $future,
            'caption' => $future,
            'description' => $this->faker->text(),
            'product_id' => $product->id,
            'type' => data_get($details, 'type', 'boolean'),
        ]), function (Feature $feature) {
        });
    }

}

Spamworldpro Mini