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 MGProvision\Proxmox\v2\models; use MGProvision\Proxmox\v2 as proxmox; /** * Description of File * * @author Pawel Kopec * @version 1.0.0 */ class File extends AbstractObject { protected $content; protected $size; protected $format; protected $volid; protected $ctime; private $path; public function getContent() { return $this->content; } public function getSize() { return $this->size; } public function getFormat() { return $this->format; } public function getVolid() { return $this->volid; } public function setContent($content) { $this->content = $content; return $this; } public function setSize($size) { $this->size = $size; return $this; } public function setFormat($format) { $this->format = $format; return $this; } public function setVolid($volid) { $this->volid = $volid; return $this; } public function getFriendlyName() { $ex = explode("/", $this->getVolid()); $friendlyName = end($ex); $s = array("-", "_", ".tar.gz", ".iso", '.tar.xz'); $r = array(" ", " ", "", "", ""); $friendlyName = str_replace($s, $r, $friendlyName); $friendlyName = ucwords($friendlyName); return $friendlyName; } /** * * @param string $path i.e. /nodes/proxmox/storage/local/content/local:backup/vzdump-lxc-100-2017_01_18-10_33_18.tar.lzo * @throws proxmox\ProxmoxApiException */ public function setPath($path) { if (!preg_match('/\/content\//', $path)) { throw new proxmox\ProxmoxApiException(sprintf("File Path ('%s') is not valid", $path)); } $this->path = $path; } public function getDate() { if($this->ctime){ return date("Y-m-d", $this->ctime); } preg_match('/[0-9]{4}_[0-9]{2}_[0-9]{2}/', $this->volid, $matches); return str_replace("_", "-", $matches[0]); } public function getHour() { if($this->ctime){ return date("H:i:s", $this->ctime); } preg_match('/-[0-9]{2}_[0-9]{2}_[0-9]{2}/', $this->volid, $matches); return str_replace(array("-", "_"), array("", ":"), $matches[0]); } public function getTimestamp() { return strtotime($this->getDate() . " " . $this->getHour()); } public function getAttributes() { return array( "content" => $this->getContent(), "size" => $this->getSize(), "format" => $this->getFormat(), "volid" => $this->getVolid(), "date" => $this->getDate(), "hour" => $this->getHour() ); } public function delete() { if (empty($this->path)) throw new proxmox\ProxmoxApiException('File [path] - property is missing and it is not optional'); return $this->api()->delete($this->path); } /** * @return mixed */ public function getCtime() { return $this->ctime; } /** * @param mixed $ctime * @return File */ public function setCtime($ctime) { $this->ctime = $ctime; return $this; } }