HEX
Server: LiteSpeed
System: Linux sv4.hami.host 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User: armgroup (1008)
PHP: 8.2.32
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, mail, socket_create, socket_create_listen, socket_create_pair, link, dl, openlog, syslog, stream_socket_server, curl_multi_init
Upload Files
File: /home/armgroup/libs/app/Http/Livewire/Admin/SendingDay/Index.php
<?php

namespace App\Http\Livewire\Admin\SendingDay;

use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Index extends Component
{
    use ConvertEmptyStringsToNull, General;

    public $sending_days;

    public $selected = [false, false, false, false, false, false, false, false, false];

    public function mount()
    {
        $this->sending_days = DB::table('sending_days')->get()->pluck('day', 'day')->toArray();
    }

    public function check(int $day)
    {
        if ($day > 7 || $day < 0) {
            return;
        }

        if ($day == 7) {
            if ($this->selected[$day]) {
                $this->sending_days = [];
            } else {
                for ($i = 0; $i < settings('sending-days-limit'); $i++) {
                    $date = now()->addDays($i)->format('Y-m-d');
                    $this->sending_days[$date] = $date;
                }
            }
            $this->selected = array_fill(0, 8, ! $this->selected[$day]);

            return;
        }

        $method = ['isSaturday', 'isSunday', 'isMonday', 'isTuesday', 'isWednesday', 'isThursday', 'isFriday'][$day];

        for ($i = 0; $i < settings('sending-days-limit'); $i++) {
            $date = now()->addDays($i);
            if ($date->{$method}()) {
                if ($this->selected[$day]) {
                    unset($this->sending_days[$date->format('Y-m-d')]);
                } else {
                    $this->sending_days[$date->format('Y-m-d')] = $date->format('Y-m-d');
                }
            }
        }

        $this->selected[$day] = ! $this->selected[$day];
    }

    public function updatedSendingDays($value, $index)
    {
        if (! $value) {
            unset($this->sending_days[$index]);
        }
    }

    public function render()
    {
        return view('livewire.admin.sending-day.index');
    }

    protected function rules()
    {
        return [
            'sending_days' => ['nullable', 'array'],
            'sending_days.*' => ['required', 'date', 'distinct'],
        ];
    }

    public function store()
    {
        $this->validate();

        DB::table('sending_days')->truncate();

        if ($this->sending_days) {
            $data = [];
            foreach ($this->sending_days as $day) {
                $data[] = ['day' => $day];
            }

            DB::table('sending_days')->insert($data);

            saveActivity('روزهای ارسال مقداردهی شد');
        }

        $this->doneMessage();

        return redirect()->route('admin.sending-days.index');
    }
}