<commit_before><?php
class Application_Model_StreamSetting {

    /* Returns the id's of all streams that are enabled in an array. An
     * example of the array returned in JSON notation is ["s1", "s2", "s3"] */
    public static function getEnabledStreamIds(){
        global $CC_DBC;
        $sql = "SELECT * "
                ."FROM cc_stream_setting "
                ."WHERE keyname LIKE '%_enable' "
                ."AND value='true'";

        $rows = $CC_DBC->getAll($sql);
        $ids = array();

        foreach ($rows as $row){
            $ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_"));
        }

        //Logging::log(print_r($ids, true));
        
        return $ids;
    }
    
    /* Retruns only global data as array*/
    public static function getGlobalData(){
        global $CC_DBC;
        $sql = "SELECT * "
        ."FROM cc_stream_setting "
        ."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')";
        
        $rows = $CC_DBC->getAll($sql);
        $data = array();
        
        foreach($rows as $row){
        $data[$row["keyname"]] = $row["value"];
        }
        
        return $data;
    }
    /* Returns all information related to a specific stream. An example
     * of a stream id is 's1' or 's2'. */
    public static function getStreamData($p_streamId){
        global $CC_DBC;
        $sql = "SELECT * "
                ."FROM cc_stream_setting "
                ."WHERE keyname LIKE '${p_streamId}_%'";

        $rows = $CC_DBC->getAll($sql);
        $data = array();

        foreach($rows as $row){
            $data[$row["keyname"]] = $row["value"];
        }

        return $data;
    }
    
    public static function getStreamSetting(){
        global $CC_DBC;
        $sql = "SELECT *"
                ." FROM cc_stream_setting"
                ." WHERE keyname not like '%_error'";

        $rows = $CC_DBC->getAll($sql);
        return $rows;
    }
    
    /*
     * function that take all the information of stream and sets them.
     * This is used by stream setting via UI.
     * 
     * @param $data - array that contains all the data. $data is [][] which
     * contains multiple stream information
     */
    public static function setStreamSetting($data){
        global $CC_DBC;
        foreach ($data as $key=>$d) {
            if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") {
                $v = $d == 1?"true":"false";
                $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'";
                $CC_DBC->query($sql);
            } else {
                $temp = explode('_', $key);
                $prefix = $temp[0];
                foreach ($d as $k=>$v) {
                    $keyname = $prefix . "_" . $k;
                    if ($k == 'enable') {
                        $v = $d['enable'] == 1 ? 'true' : 'false';
                    }
                    $v = trim($v);
                    $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
                    $CC_DBC->query($sql);
                }
            }
        }
    }<commit_msg>CC-3160: Once Hardware dropdown is changed, stream information does not refresh<commit_after><?php
class Application_Model_StreamSetting {

    /* Returns the id's of all streams that are enabled in an array. An
     * example of the array returned in JSON notation is ["s1", "s2", "s3"] */
    public static function getEnabledStreamIds(){
        global $CC_DBC;
        $sql = "SELECT * "
                ."FROM cc_stream_setting "
                ."WHERE keyname LIKE '%_enable' "
                ."AND value='true'";

        $rows = $CC_DBC->getAll($sql);
        $ids = array();

        foreach ($rows as $row){
            $ids[] = substr($row["keyname"], 0, strpos($row["keyname"], "_"));
        }

        //Logging::log(print_r($ids, true));
        
        return $ids;
    }
    
    /* Retruns only global data as array*/
    public static function getGlobalData(){
        global $CC_DBC;
        $sql = "SELECT * "
        ."FROM cc_stream_setting "
        ."WHERE keyname IN ('output_sound_device', 'icecast_vorbis_metadata')";
        
        $rows = $CC_DBC->getAll($sql);
        $data = array();
        
        foreach($rows as $row){
        $data[$row["keyname"]] = $row["value"];
        }
        
        return $data;
    }
    /* Returns all information related to a specific stream. An example
     * of a stream id is 's1' or 's2'. */
    public static function getStreamData($p_streamId){
        global $CC_DBC;
        $sql = "SELECT * "
                ."FROM cc_stream_setting "
                ."WHERE keyname LIKE '${p_streamId}_%'";

        $rows = $CC_DBC->getAll($sql);
        $data = array();

        foreach($rows as $row){
            $data[$row["keyname"]] = $row["value"];
        }

        return $data;
    }
    
    public static function getStreamSetting(){
        global $CC_DBC;
        $sql = "SELECT *"
                ." FROM cc_stream_setting"
                ." WHERE keyname not like '%_error'";

        $rows = $CC_DBC->getAll($sql);
        return $rows;
    }
    
    /*
     * function that take all the information of stream and sets them.
     * This is used by stream setting via UI.
     * 
     * @param $data - array that contains all the data. $data is [][] which
     * contains multiple stream information
     */
    public static function setStreamSetting($data){
        global $CC_DBC;
        
        foreach ($data as $key=>$d) {
            if ($key == "output_sound_device" || $key == "icecast_vorbis_metadata") {
                $v = $d == 1?"true":"false";
                $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$key'";
                $CC_DBC->query($sql);
            } else if ($key == "output_sound_device_type") {
                $sql = "UPDATE cc_stream_setting SET value='$d' WHERE keyname='$key'";
                $CC_DBC->query($sql);                
            } else {
                $temp = explode('_', $key);
                $prefix = $temp[0];
                foreach ($d as $k=>$v) {
                    $keyname = $prefix . "_" . $k;
                    if ($k == 'enable') {
                        $v = $d['enable'] == 1 ? 'true' : 'false';
                    }
                    $v = trim($v);
                    $sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'";
                    $CC_DBC->query($sql);
                }
            }
        }
    }
{'fraction_non_alphanumeric': 0.14126959963464758, 'fraction_numerical': 0.0033490637844420766, 'mean_word_length': 1.6301040832666134, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 20, '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': '3099983', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1911, 'n_words': 512}