Source of file Entity.php
Size: 2,799 Bytes - Last Modified: 2021-12-24T05:18:55+00:00
/var/www/docs.ssmods.com/process/src/src/Traits/Entity.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | <?php namespace IQnection\BigCommerceApp\Traits; use SilverStripe\ORM\ArrayList; use SilverStripe\View\ArrayData; use SilverStripe\Forms; use SilverStripe\ORM\ValidationResult; use SilverStripe\ORM\ValidationException; use IQnection\BigCommerceApp\Client; use SilverStripe\Core\Injector\Injector; trait Entity { public function validate() { return $this->_validate(); } public function _validate() { $result = new ValidationResult(); return $result; } /** * Syncs/Pushes the entity data with BigCommerce * @returns object $this */ public function Sync() { return $this->_sync(); } public function _sync() { $result = $this->validate(); if (!$result->isValid()) { throw ValidationException::create($result); } return $this; } // public function getFrontEndRequiredFields() // { // return $this->_getFrontEndRequiredFields(); // } // // public function _getFrontEndRequiredFields() // { // return Forms\RequiredFields::create(); // } // // public function getFrontEndFields() // { // return $this->_getFrontEndFields(); // } // // public function _getFrontEndFields() // { // return Forms\FieldList::create(); // } public function delete() { } // public function loadApiData($data) // { // return $this->_loadApiData($data); // } // // public function _loadApiData($data) // { // $this->array = []; // $this->api_data = $data; // if ( (is_object($data)) && (method_exists($data, 'get')) ) // { // foreach($data->get() as $key => $value) // { // if ( (is_object($value)) && (method_exists($value, 'get')) ) // { // $value = $this->buildArrayData($value); // } // elseif (is_array($value)) // { // $newValue = ArrayList::create(); // foreach($value as $subValue) // { // $newSubInst = Injector::inst()->create(static::class, []); // $newSubInst->loadApiData($subValue); // $newValue->push($newSubInst); // } // $value = $newValue; // } // $this->setField($key, $value); // if (is_string($value)) // { // $this->setField($key, trim($value)); // } // } // } // return $this; // } // protected function buildArrayData($data) // { // $arrayData = Injector::inst()->create(static::class, []); // if ( (is_object($data)) && (method_exists($data, 'get')) ) // { // foreach($data->get() as $key => $value) // { // if ( (is_object($value)) && (method_exists($value, 'get')) ) // { // $value = $this->buildArrayData($value); // } // $arrayData->setField($key, $value); // if (is_string($value)) // { // $arrayData->setField($key, trim($value)); // $arrayData->setField('match-'.$key, preg_replace('/[^a-zA-Z0-9]/','',strtolower(trim($value)))); // } // } // } // return $arrayData; // } } |