<commit_before><commit_msg>+hostchild relation<commit_after><?php

namespace Models\Configuration\Relation\Host;

use \Models\Configuration\Relation;

class Hostchild extends Relation
{
    protected $relationTable = "host_hostparent_relation";
    protected $firstKey;
    protected $secondKey;
    public static $firstObject = "Models\\Configuration\\Host";
    public static $secondObject = "Models\\Configuration\\Host";

    /**
     * 
     * @param type $relationType
     */
    public function __construct()
    {
        $this->firstKey = "host_host_id";
        $this->secondKey = "host_parent_hp_id";
        parent::__construct();
        $this->firstObj = new static::$firstObject();
        $this->secondObj = new static::$secondObject();
    }
    
    /**
     * Get Merged Parameters from seperate tables
     *
     * @param array $firstTableParams
     * @param array $secondTableParams
     * @param int $count
     * @param string $order
     * @param string $sort
     * @param array $filters
     * @param string $filterType
     * @return array
     */
    public function getMergedParameters($firstTableParams = array(), $secondTableParams = array(), $count = -1, $offset = 0, $order = null, $sort = "ASC", $filters = array(), $filterType = "OR")
    {
        if (!isset($this->firstObj) || !isset($this->secondObj)) {
            throw new Exception('Unsupported method on this object');
        }
        $fString = "";
        $sString = "";
        foreach ($firstTableParams as $fparams) {
            if ($fString != "") {
                $fString .= ",";
            }
            $fString .= $this->firstObj->getTableName().".".$fparams;
        }
        foreach ($secondTableParams as $sparams) {
            if ($fString != "" || $sString != "") {
                $sString .= ",";
            }
            $sString .= $this->secondObj->getTableName().".".$sparams;
        }
        
        $sql = "SELECT ".$fString.$sString."
        		FROM host, ".$this->relationTable."
        		WHERE ".$this->firstObj->getTableName().".".$this->firstObj->getPrimaryKey()." = ".$this->relationTable.".".$this->firstKey;
        $filterTab = array();
        if (count($filters)) {
            foreach ($filters as $key => $rawvalue) {
                $sql .= " $filterType $key LIKE ? ";
                $value = trim ($rawvalue);
                $value = str_replace("\\", "\\\\", $value);
                $value = str_replace("_", "\_", $value);
                $value = str_replace(" ", "\ ", $value);
                $filterTab[] = $value;
            }
        }
        if (isset($order) && isset($sort) && (strtoupper($sort) == "ASC" || strtoupper($sort) == "DESC")) {
            $sql .= " ORDER BY $order $sort ";
        }
        if (isset($count) && $count != -1) {
            $sql = $this->db->limit($sql, $count, $offset);
        }
        $result = $this->getResult($sql, $filterTab);
        return $result;
    }
}
{'fraction_non_alphanumeric': 0.17116812964213368, 'fraction_numerical': 0.001012829169480081, 'mean_word_length': 2.0768431983385254, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6440922', 'n_tokens_mistral': 867, 'n_tokens_neox': 856, 'n_words': 181}