| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\Forms\DataProviders;
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\FormDataProviderInterface;
- /**
- * BaseDataProvider - form controller witch CRUD implementation
- *
- * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
- */
- abstract class BaseDataProvider implements FormDataProviderInterface
- {
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\RequestObjectHandler;
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\RequestFormDataHandler;
- use \ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits\WhmcsParams;
-
- protected $data = [];
- protected $availableValues = [];
- protected $loaded = false;
- protected $disabledList = [];
- protected $parentFormType = null;
-
- public function __construct()
- {
- $this->loadFormDataFromRequest();
- }
-
- public function create()
- {
- //to be overwritten if needed
- }
- abstract public function read();
- abstract public function update();
- public function delete()
- {
- //to be overwritten if needed
- }
- public function reload()
- {
- //to be overwritten if needed
- $this->read();
- }
- public function getValueById($id)
- {
- if ($this->data[$id] || $this->data[$id] == 0)
- {
- return $this->data[$id];
- }
- return null;
- }
- public function getAvailableValuesById($id)
- {
- if (is_array($this->availableValues[$id]) || count($this->availableValues[$id]) > 0)
- {
- return $this->availableValues[$id];
- }
- return null;
- }
-
- public function getData()
- {
- return $this->data;
- }
- public function isDisabledById($id)
- {
- if (in_array($id, $this->disabledList))
- {
- return true;
- }
- return false;
- }
- public function initData()
- {
- if ($this->loaded === false)
- {
- $this->read();
- $this->loaded = true;
- }
- }
-
- protected function setData($data)
- {
- $this->data = $data;
-
- return $this;
- }
- protected function setDisabled($id)
- {
- if (!in_array($id, $this->disabledList))
- {
- $this->disabledList[] = $id;
- }
- }
- protected function removeFromDisabled($id)
- {
- if (in_array($id, $this->disabledList))
- {
- $key = array_search($id, $this->disabledList[]);
- if ($key)
- {
- unset($this->disabledList[$key]);
- }
- }
- }
-
- public function setParentFormType($formType = null)
- {
- if (is_string($formType) && $formType !== '')
- {
- $this->parentFormType = $formType;
- }
-
- return $this;
- }
-
- public function getParentFormType()
- {
- return $this->parentFormType;
- }
- }
|