<commit_before><?php
/**
 * This file is part of SplashSync Project.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 *  @author    Splash Sync <www.splashsync.com>
 *  @copyright 2015-2017 Splash Sync
 *  @license   GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
 *
 **/

namespace Splash\Local\Objects\Product\Variants;

use Splash\Core\SplashCore      as Splash;

use WC_Product;
use WP_Term;

/**
 * @abstract    WooCommerce Product Variants Attribute Values management
 */
trait AttributeValueTrait
{
    
    /**
     * @abstract    Identify Attribute Value Using Multilang Codes
     * @param       string      $Slug       Attribute Group Slug
     * @param       string      $Name       Attribute Name/Code
     * @return      int|bool                Attribute Id (Term Id)
     */
    public function getAttributeByCode($Slug, $Name)
    {
        //====================================================================//
        // Ensure Group Id is Valid
        if (!is_scalar($Slug) || empty($Slug)) {
            return false;
        }
        //====================================================================//
        // Ensure Code is Valid
        if (empty($Name)) {
            return false;
        }
        //====================================================================//
        // Search for this Attribute Group Code
        $Search =   term_exists($Name, $Slug);
        if ($Search) {
            return $Search["term_id"];
        }
        return false;
    }

    /**
     * @abstract    Identify Attribute Value Using Multilang Codes
     * @param       string      $Slug       Attribute Group Slug
     * @param       string      $Value      Attribute Value
     * @return      int|bool               Attribute Id (Term Id)
     */
    public function getAttributeByName($Slug, $Value)
    {
        //====================================================================//
        // Ensure Group Id is Valid
        if (!is_scalar($Slug) || empty($Slug)) {
            return false;
        }
        //====================================================================//
        // Ensure Value is Valid
        if (empty($Value)) {
            return false;
        }
        //====================================================================//
        // Search for this Attribute Value in Taximony
        $WpTerm = $this->getTermByName($Slug, $Value);
        if ($WpTerm != false) {
            return $WpTerm->term_id;
        }
        return false;
    }

    /**
     * @abstract    Search Term Using Multilang Codes
     * @param       string      $Slug       Attribute Group Slug
     * @param       array       $Value      Attribute Value
     * @return      WP_Term|false
     */
    private function getTermByName($Slug, $Value)
    {
        //====================================================================//
        // Search for this Attribute Value in Taximony
        $Taximony   =   wc_attribute_taxonomy_name(str_replace('pa_', '', $Slug));
        $Search = get_terms(array(
            'taxonomy'      => array( $Taximony ),
            'orderby'       => 'id',
            'order'         => 'ASC',
            'hide_empty'    => false,
        ));
        //====================================================================//
        // Check Results
        if (!is_array($Search) || (count($Search) <= 0)) {
            return false;
        }
        //====================================================================//
        // Search in Results
        foreach ($Search as $Term) {
            if (isset($Term->name) && ($Term->name == $this->decodeMultilang($Value))) {
                return $Term;
            }
        }
        return false;
    }
    
    /**
     * @abstract    Identify Attribute Value Using Multilang Names Array
     * @param       string      $Slug       Attribute Group Slug
     * @param       string      $Value      Attribute Value
     * @return      int|false               Attribute Id
     */
    public function addAttributeValue($Slug, $Value)
    {
        //====================================================================//
        // Ensure Slug is Valid
        if (!is_scalar($Slug) || empty($Slug)) {<commit_msg>WIP : Fix ThridParty Triggers<commit_after><?php
/**
 * This file is part of SplashSync Project.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 *  @author    Splash Sync <www.splashsync.com>
 *  @copyright 2015-2017 Splash Sync
 *  @license   GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
 *
 **/

namespace Splash\Local\Objects\Product\Variants;

use Splash\Core\SplashCore      as Splash;

use WC_Product;
use WP_Term;

/**
 * @abstract    WooCommerce Product Variants Attribute Values management
 */
trait AttributeValueTrait
{
    
    /**
     * @abstract    Identify Attribute Value Using Multilang Codes
     * @param       string      $Slug       Attribute Group Slug
     * @param       string      $Name       Attribute Name/Code
     * @return      int|bool                Attribute Id (Term Id)
     */
    public function getAttributeByCode($Slug, $Name)
    {
        //====================================================================//
        // Ensure Group Id is Valid
        if (!is_scalar($Slug) || empty($Slug)) {
            return false;
        }
        //====================================================================//
        // Ensure Code is Valid
        if (empty($Name)) {
            return false;
        }
        //====================================================================//
        // Search for this Attribute Group Code
        $Search =   term_exists($Name, $Slug);
        if ($Search) {
            return $Search["term_id"];
        }
        return false;
    }

    /**
     * @abstract    Identify Attribute Value Using Multilang Codes
     * @param       string      $Slug       Attribute Group Slug
     * @param       string      $Value      Attribute Value
     * @return      int|bool               Attribute Id (Term Id)
     */
    public function getAttributeByName($Slug, $Value)
    {
        //====================================================================//
        // Ensure Group Id is Valid
        if (!is_scalar($Slug) || empty($Slug)) {
            return false;
        }
        //====================================================================//
        // Ensure Value is Valid
        if (empty($Value)) {
            return false;
        }
        //====================================================================//
        // Search for this Attribute Value in Taximony
        $WpTerm = $this->getTermByName($Slug, $Value);
        if ($WpTerm != false) {
            return $WpTerm->term_id;
        }
        return false;
    }

    /**
     * @abstract    Search Term Using Multilang Codes
     * @param       string      $Slug       Attribute Group Slug
     * @param       array       $Value      Attribute Value
     * @return      WP_Term|false
     */
    private function getTermByName($Slug, $Value)
    {
        //====================================================================//
        // Search for this Attribute Value in Taximony
        $Taximony   =   wc_attribute_taxonomy_name(str_replace('pa_', '', $Slug));
        $Search = get_terms(array(
            'taxonomy'      => array( $Taximony ),
            'orderby'       => 'id',
            'order'         => 'ASC',
            'hide_empty'    => false,
        ));
        //====================================================================//
        // Check Results
        if (!is_array($Search) || (count($Search) <= 0)) {
            return false;
        }
        //====================================================================//
        // Search in Results
        /** @var WP_Term $Term */
        foreach ($Search as $Term) {
            if (isset($Term->name) && ($Term->name == $this->decodeMultilang($Value))) {
                return $Term;
            }
        }
        return false;
    }
    
    /**
     * @abstract    Identify Attribute Value Using Multilang Names Array
     * @param       string      $Slug       Attribute Group Slug
     * @param       string      $Value      Attribute Value
     * @return      int|false               Attribute Id
     */
    public function addAttributeValue($Slug, $Value)
    {
        //====================================================================//
        // Ensure Slug is Valid
        if (!is_scalar($Slug) || empty($Slug)) {
{'fraction_non_alphanumeric': 0.2397635209108824, 'fraction_numerical': 0.0035033939128530766, 'mean_word_length': 2.0409454061251666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4664833', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2170, 'n_words': 642}