HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/app/Model/AutomationElement.php
<?php

/**
 * Automation class.
 *
 * Model for automation elements
 *
 * LICENSE: This product includes software developed at
 * the Acelle Co., Ltd. (http://acellemail.com/).
 *
 * @category   MVC Model
 *
 * @author     N. Pham <[email protected]>
 * @author     L. Pham <[email protected]>
 * @copyright  Acelle Co., Ltd
 * @license    Acelle Co., Ltd
 *
 * @version    1.0
 *
 * @link       http://acellemail.com
 */

namespace App\Model;

use Carbon\Carbon;

// @important: this is not a model (no db table)
class AutomationElement
{
    protected $data;

    /**
     * Constructor.
     *
     * @return the associated automation2
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Get options.
     *
     * @return string
     */
    public function getOptions()
    {
        if (isset($this->data) && isset($this->data->options)) {
            return (array) $this->data->options;
        }

        return;
    }

    /**
     * Get options.
     *
     * @return string
     */
    public function getOption($name)
    {
        if (isset($this->data) && isset($this->data->options) && isset($this->data->options->$name)) {
            return $this->data->options->$name;
        }

        return;
    }

    /**
     * Get value.
     *
     * @return string
     */
    public function get($name)
    {
        if (isset($this->data) && isset($this->data->$name)) {
            return $this->data->$name;
        }

        return;
    }

    /**
     * Get value.
     *
     * @return string
     */
    public function getName()
    {
        switch ($this->get('type')) {
            case 'ElementTrigger':
                return trans('messages.automation.trigger.title', [
                    'title' => trans('messages.automation.trigger.'.$this->getOption('key')),
                ]);
                break;
            case 'ElementAction':
                $email = AutomationEmail::findByUid($this->getOption('email_uid'));
                if ($email) {
                    return trans('messages.automation.send_a_email', ['title' => $email->subject]);
                } else {
                    return trans('messages.automation.no_email');
                }

                break;
            case 'ElementWait':
                return trans('messages.automation.wait.delay.'.$this->getOption('time'));
                break;
            case 'ElementWaitUntil':
                return trans('messages.automation.wait_until', [
                    'datetime' => $this->getOption('datetime'),
                ]);
                break;
            case 'ElementOperation':
                return __('messages.automation.stats.operation_executed');
                break;
            case 'ElementCondition':
                if ($this->getOption('type') == 'open') {
                    return trans('messages.automation.action.condition.read_email.title');
                } elseif ($this->getOption('type') == 'click') {
                    return trans('messages.automation.action.condition.click_link.title');
                }
                break;
            default:
        }
    }

    /**
     * Get value.
     *
     * @return string
     */
    public function getIcon()
    {
        return self::getIconByType($this->get('type'));
    }

    /**
     * Get value.
     *
     * @return string
     */
    public static function getIconByType($type)
    {
        switch ($type) {
            case 'ElementTrigger':
                return '<span class="material-symbols-rounded">alt_route</span>';
                break;
            case 'ElementAction':
                return '<span class="material-symbols-rounded">forward_to_inbox</span>';
                break;
            case 'ElementWait':
                return '<span class="material-symbols-rounded">timer</span>';
                break;
            case 'ElementCondition':
                return '<span class="material-symbols-rounded">call_split</span>';
                break;
            case 'ElementOperation':
                return '<span class="material-symbols-rounded">checklist_rtl</span>';
                break;
            case 'ElementWaitUntil':
                return '<span class="material-symbols-rounded">forward_to_inbox</span>';
                break;
            default:
        }
    }

    /**
     * Get value.
     *
     * @return string
     */
    public function getIconWithoutBg($class = '')
    {
        switch ($this->get('type')) {
            case 'ElementTrigger':
                return '<span class="material-symbols-rounded">alt_route</span>';
                break;
            case 'ElementAction':
                return '<span class="material-symbols-rounded">forward_to_inbox</span>';
                break;
            case 'ElementWait':
                return '<span class="material-symbols-rounded">timer</span>';
                break;
            case 'ElementCondition':
                return '<span class="material-symbols-rounded">call_split</span>';
                break;
            case 'ElementOperation':
                return '<span class="material-symbols-rounded">checklist_rtl</span>';
                break;
            default:
        }
    }

    /**
     * Get abandoned cart.
     *
     * @return string
     */
    public function wooGetAbandonedCart()
    {
        $client = new \GuzzleHttp\Client();
        $uri = $this->getOption('connect_url');
        $response = $client->request('GET', $uri, [
            'headers' => [
                "content-type" => "application/json"
            ],
        ]);

        return json_decode($response->getBody(), true);
    }
}