<?php

/* * ********************************************************************
 * ProxmoxAddon product developed. (Oct 2, 2018)
 * *
 *
 *  CREATED BY MODULESGARDEN       ->       http://modulesgarden.com
 *  CONTACT                        ->       contact@modulesgarden.com
 *
 *
 * This software is furnished under a license and may be used and copied
 * only  in  accordance  with  the  terms  of such  license and with the
 * inclusion of the above copyright notice.  This software  or any other
 * copies thereof may not be provided or otherwise made available to any
 * other person.  No title to and  ownership of the  software is  hereby
 * transferred.
 *
 *
 * ******************************************************************** */

namespace ModulesGarden\ProxmoxAddon\App\UI\Servers\Pages;

use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Others\AjaxFieldForDataTable;

/**
 * Description of ResourcesRow
 *
 * @author Pawel Kopec <pawelk@modulesgardne.com>
 */
class SuspendedRow extends AjaxFieldForDataTable implements AdminArea
{

    use ServerResources;

    public function prepareAjaxData()
    {
        session_write_close();
        try
        {
            session_write_close();
            $serverId = $this->getRequestValue('index', '0');
            $this->setServerId($serverId);
            $this->setHostingStatus(["Suspended"]);
            if ($this->getServer()->disabled != 1)
            {
                $this->getApi()->setInstance();
                $this->ramDetails();
            }
            if ($this->errors)
            {
                throw new \Exception(implode("<br/> ", $this->errors));
            }
            $this->ajaxData = "{$this->ramAssignedToSring()} / {$this->ramSuspendedToSring()}</span>";
        }
        catch (\Exception $ex)
        {
            $this->ajaxData = sprintf('<span style="color:red;">%s</span>', $ex->getMessage());
        }
    }
}
