<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\SmartyHelper;

use ModulesGarden\HostingQuotaNotifications\App\Helper\DBModelsHelper;

/**
 * Description of Other
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class Other
{
    private $data;
    private $output;

    public function __construct()
    {
        global $CONFIG;

        $this->data['company_name']     = DBModelsHelper::getWHMCSConfigValue('CompanyName');
        $this->data['company_domain']   = DBModelsHelper::getWHMCSConfigValue('Domain');
        $this->data['company_logo_url'] = DBModelsHelper::getWHMCSConfigValue('LogoURL');
        $this->data['whmcs_url']        = DBModelsHelper::getWHMCSConfigValue('SystemURL');
        //$this->data['whmcs_link'] = "<a href=\"" . $this->data['whmcs_url'] . "\">" . $this->data['whmcs_url'] . "</a>";
        $this->data['whmcs_link']       = $this->data['whmcs_url'];
        $this->data['signature']        = strip_tags(html_entity_decode(DBModelsHelper::getWHMCSConfigValue('Signature'), ENT_QUOTES)); //nl2br
        $this->data['date']             = date("l, jS F Y");
        $this->data['time']             = date("g:ia");
        $adminurl                       = $CONFIG['SystemURL'];
        $adminurl                       .= '' . '/' . $GLOBALS['customadminpath'] . '/'; //TODO
        $this->data['whmcs_admin_url']  = $adminurl;
        $this->data['whmcs_admin_link'] = '<a href="' . $adminurl . '">' . $adminurl . '</a>';
    }

    public function getFormatedData()
    {
        $this->output = $this->data;

        return $this->output;
    }

    public function getMergeFields()
    {
        $map      = self::getMergeFieldsMap();
        $formated = $this->getFormatedData();
        $fields   = array();

        foreach ($map as $k => $v)
            $fields[$k] = $formated[$v];

        return $fields;
    }

    public static function getMergeFieldsNames()
    {
        return array_keys(self::getMergeFieldsMap());
    }

    private static function getMergeFieldsMap()
    {
        return array(
            'company_name'     => 'company_name',
            'company_domain'   => 'company_domain',
            'company_logo_url' => 'company_logo_url',
//            'whmcs_url'        => 'whmcs_url',
//            'whmcs_link'       => 'whmcs_link',
            'signature'        => 'signature',
            'date'             => 'date',
            'time'             => 'time',
//            'pw_reset_url'     => '',
//            'order_details'    => '',
//            'whmcs_admin_url'  => 'whmcs_admin_url',
//            'whmcs_admin_link' => 'whmcs_admin_link',
        );
    }
}
