Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/Ecombricks/Inventory/Framework/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/Ecombricks/Inventory/Framework/Model/SourceAdditionalTrait.php
<?php
/**
 * Copyright © eComBricks. All rights reserved.
 * See LICENSE.txt for license details.
 */
namespace Ecombricks\Inventory\Framework\Model;

/**
 * Model source additional trait
 */
trait SourceAdditionalTrait
{
    
    /**
     * Get source additional data
     * 
     * @param string $sourceCode
     * @param string $key
     * @return mixed
     */
    public function getSourceAdditionalData($sourceCode, $key)
    {
        $value = $this->getData('source_'.$key);
        return (is_array($value) && isset($value[$sourceCode])) ? $value[$sourceCode] : null;
    }
    
    /**
     * Set source additional data
     * 
     * @param string $sourceCode
     * @param string $key
     * @param mixed $sourceValue
     * @return $this
     */
    public function setSourceAdditionalData($sourceCode, $key, $sourceValue)
    {
        $value = $this->getData('source_'.$key);
        if (!is_array($value)) {
            $value = [];
        }
        $value[$sourceCode] = $sourceValue;
        $this->setData('source_'.$key, $value);
        return $this;
    }
    
    /**
     * Get source codes
     * 
     * @return array
     */
    public function getSourceCodes()
    {
        return [];
    }
    
    /**
     * Filter source values
     * 
     * @param array $values
     * @param boolean $required
     * @return array
     */
    public function filterSourceValues($values, $required = true)
    {
        if (empty($values)) {
            return [];
        }
        $filteredValues = [];
        $sourceCodes = $this->getSourceCodes();
        if (empty($sourceCodes)) {
            $sourceCodes = array_keys($values);
        }
        foreach ($sourceCodes as $sourceCode) {
            if (empty($values[$sourceCode]) && $required) {
                $filteredValues = [];
                break;
            }
            if (empty($values[$sourceCode])) {
                continue;
            }
            $filteredValues[$sourceCode] = $values[$sourceCode];
        }
        return $filteredValues;
    }
    
    /**
     * After load
     * 
     * @return $this
     */
    public function inventoryAfterLoad()
    {
        $this->_getResource()->loadSourceAdditionalData($this);
        return $this;
    }
    
    /**
     * After save
     * 
     * @return $this
     */
    public function inventoryAfterSave()
    {
        $this->_getResource()->saveSourceAdditionalData($this);
        return $this;
    }
    
    /**
     * Before delete
     * 
     * @return $this
     */
    public function inventoryBeforeDelete()
    {
        $this->_getResource()->deleteSourceAdditionalData($this);
        return $this;
    }
    
}

Spamworldpro Mini