HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //www/wwwroot/www.shooperm.com/Modules/GeneralSetting/Repositories/EmailTemplateRepository.php
<?php

namespace Modules\GeneralSetting\Repositories;

use Modules\GeneralSetting\Entities\EmailTemplate;
use Modules\GeneralSetting\Entities\EmailTemplateType;

class EmailTemplateRepository
{
    public function getEmailTemplates()
    {
        return EmailTemplate::orderBy('type_id', 'asc')->get();
    }

    public function getEmailTemplateTypes()
    {
        return EmailTemplateType::all();
    }

    public function createTemplate($data)
    {
        $relatable_type = null;
        $relatable_id = null;
        $reciepnt_type = ["customer"];

        if ($data['type_id'] == 7) {
            $relatable_type = "Modules\OrderManage\Entities\DeliveryProcess";
            $relatable_id = $data['delivery_process_id'];
        }
        if ($data['type_id'] == 8) {
            $relatable_type = "Modules\Refund\Entities\RefundProcess";
            $relatable_id = $data['refund_process_id'];
        }

        EmailTemplate::create([
            'type_id' => $data['type_id'],
            'subject' => $data['subject'],
            'value' => $data['template'],
            'reciepnt_type' => (!empty($data['reciepnt'])) ? json_encode($data['reciepnt']) : json_encode($reciepnt_type),
            'relatable_type' => $relatable_type,
            'relatable_id' => $relatable_id,
        ]);
    }

    public function find($id)
    {
        return EmailTemplate::findorFail($id);
    }

    public function updateEmailTemplate($data, $id)
    {
        $reciepnt_type = ["customer"];
        return EmailTemplate::findorFail($id)->update([
            'subject' => $data['subject'],
            'reciepnt_type' => (!empty($data['reciepnt'])) ? json_encode($data['reciepnt']) : json_encode($reciepnt_type),
            'value' => $data['template']
        ]);
    }

    public function updateEmailTemplateStatus($data)
    {
        $template = EmailTemplate::findorFail($data['id']);
        $active_check = EmailTemplate::where('type_id', $template->type_id)->where('is_active', 1)->where('id', '!=', $template->id)->first();
        if($data['status'] == 0 && !$active_check){
            return 'not_possible';

        }
        $template->update([
            'is_active' => $data['status']
        ]);

        $otherLists = EmailTemplate::where('type_id', $template->type_id)->where('id', '!=', $template->id)->get();
        if(count($otherLists) > 0){
            foreach($otherLists as $tem){
                $tem->update([
                    'is_active' => 0
                ]);
            }
        }
        return 1;

    }
}