<commit_before><?php

class Application_Model_Preference
{

    public static function SetValue($key, $value, $isUserValue = false){
        global $CC_CONFIG, $CC_DBC;

        //called from a daemon process
        if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
            $id = NULL;
        }
        else {
            $auth = Zend_Auth::getInstance();
            $id = $auth->getIdentity()->id;
        }

        $key = pg_escape_string($key);
        $value = pg_escape_string($value);

        //Check if key already exists
        $sql = "SELECT COUNT(*) FROM cc_pref"
        ." WHERE keystr = '$key'";
        
        //For user specific preference, check if id matches as well
        if($isUserValue) {
        	$sql .= " AND subjid = '$id'";
        }
        
        $result = $CC_DBC->GetOne($sql);

        if($result == 1) {
        	// result found
	        if(is_null($id) || !$isUserValue) {
	        	// system pref
	            $sql = "UPDATE cc_pref"
	            ." SET subjid = NULL, valstr = '$value'"
	            ." WHERE keystr = '$key'";
	        } else {
	        	// user pref
	            $sql = "UPDATE cc_pref" 
	            . " SET valstr = '$value'" 
	            . " WHERE keystr = '$key' AND subjid = $id";
	        }
        } else {
        	// result not found
	        if(is_null($id) || !$isUserValue) {
	        	// system pref
	            $sql = "INSERT INTO cc_pref (keystr, valstr)"
	            ." VALUES ('$key', '$value')";
	        } else {
	        	// user pref
	            $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
	            ." VALUES ($id, '$key', '$value')";
	        }
        }
        
        return $CC_DBC->query($sql);
    }

    public static function GetValue($key, $isUserValue = false){
        global $CC_CONFIG, $CC_DBC;
        
        //Check if key already exists
        $sql = "SELECT COUNT(*) FROM cc_pref"
        ." WHERE keystr = '$key'";
    	//For user specific preference, check if id matches as well
        if($isUserValue) {
	        $auth = Zend_Auth::getInstance();
	        if($auth->hasIdentity()) {
		        $id = $auth->getIdentity()->id;
	        	$sql .= " AND subjid = '$id'";
		    }
        }
        $result = $CC_DBC->GetOne($sql);

        if ($result == 0)
            return "";
        else {
            $sql = "SELECT valstr FROM cc_pref"
            ." WHERE keystr = '$key'";
            
	        //For user specific preference, check if id matches as well
	        if($isUserValue && $auth->hasIdentity()) {
	        	$sql .= " AND subjid = '$id'";
	        }
	        
            $result = $CC_DBC->GetOne($sql);
            return $result;
        }
    }

    public static function GetHeadTitle(){
        $title = self::GetValue("station_name");
        $defaultNamespace->title = $title;
        if (strlen($title) > 0)
            $title .= " - ";

        return $title."Airtime";
    }

    public static function SetHeadTitle($title, $view=null){
        self::SetValue("station_name", $title);

        // in case this is called from airtime-saas script
        if($view !== null){
            //set session variable to new station name so that html title is updated.
            //should probably do this in a view helper to keep this controller as minimal as possible.
            $view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject
            $view->headTitle(self::GetHeadTitle());
        }
				
        $eventType = "update_station_name";
        $md = array("station_name"=>$title);
		
        Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
    }

    /**
     * Set the furthest date that a never-ending show 
     * should be populated until.
     * 
     * @param DateTime $dateTime
     *        A row from cc_show_days table
     */ 
    public static function SetShowsPopulatedUntil($dateTime) {
        self::SetValue("shows_populated_until", $dateTime->format("Y-m-d H:i:s"));
    }

    /**
     * Get the furthest date that a never-ending show 
     * should be populated until.
     *
     * Returns null if the value hasn't been set, otherwise returns
     * a DateTime object representing the date. 
     * 
     * @return DateTime (in UTC Timezone)
     */
    public static function GetShowsPopulatedUntil() {
        $date = self::GetValue("shows_populated_until");
        
        if ($date == ""){
            return null;
        } else {
            return new DateTime($date, new DateTimeZone("UTC"));
        }
    }

    public static function SetDefaultFade($fade) {
        self::SetValue("default_fade", $fade);
    }

    public static function GetDefaultFade() {
        $fade = self::GetValue("default_fade");
        
        if ($fade === "") {
            return null;
        } 
        
        $fade = number_format($fade, 6);
        return $fade;
    }
    
    public static function SetDefaultTransitionFade($fade) {<commit_msg>CC-3666: Default Playlist fade in/out time is not zero.<commit_after><?php

class Application_Model_Preference
{

    public static function SetValue($key, $value, $isUserValue = false){
        global $CC_CONFIG, $CC_DBC;

        //called from a daemon process
        if(!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
            $id = NULL;
        }
        else {
            $auth = Zend_Auth::getInstance();
            $id = $auth->getIdentity()->id;
        }

        $key = pg_escape_string($key);
        $value = pg_escape_string($value);

        //Check if key already exists
        $sql = "SELECT COUNT(*) FROM cc_pref"
        ." WHERE keystr = '$key'";
        
        //For user specific preference, check if id matches as well
        if($isUserValue) {
        	$sql .= " AND subjid = '$id'";
        }
        
        $result = $CC_DBC->GetOne($sql);

        if($result == 1) {
        	// result found
	        if(is_null($id) || !$isUserValue) {
	        	// system pref
	            $sql = "UPDATE cc_pref"
	            ." SET subjid = NULL, valstr = '$value'"
	            ." WHERE keystr = '$key'";
	        } else {
	        	// user pref
	            $sql = "UPDATE cc_pref" 
	            . " SET valstr = '$value'" 
	            . " WHERE keystr = '$key' AND subjid = $id";
	        }
        } else {
        	// result not found
	        if(is_null($id) || !$isUserValue) {
	        	// system pref
	            $sql = "INSERT INTO cc_pref (keystr, valstr)"
	            ." VALUES ('$key', '$value')";
	        } else {
	        	// user pref
	            $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
	            ." VALUES ($id, '$key', '$value')";
	        }
        }
        
        return $CC_DBC->query($sql);
    }

    public static function GetValue($key, $isUserValue = false){
        global $CC_CONFIG, $CC_DBC;
        
        //Check if key already exists
        $sql = "SELECT COUNT(*) FROM cc_pref"
        ." WHERE keystr = '$key'";
    	//For user specific preference, check if id matches as well
        if($isUserValue) {
	        $auth = Zend_Auth::getInstance();
	        if($auth->hasIdentity()) {
		        $id = $auth->getIdentity()->id;
	        	$sql .= " AND subjid = '$id'";
		    }
        }
        $result = $CC_DBC->GetOne($sql);

        if ($result == 0)
            return "";
        else {
            $sql = "SELECT valstr FROM cc_pref"
            ." WHERE keystr = '$key'";
            
	        //For user specific preference, check if id matches as well
	        if($isUserValue && $auth->hasIdentity()) {
	        	$sql .= " AND subjid = '$id'";
	        }
	        
            $result = $CC_DBC->GetOne($sql);
            return $result;
        }
    }

    public static function GetHeadTitle(){
        $title = self::GetValue("station_name");
        $defaultNamespace->title = $title;
        if (strlen($title) > 0)
            $title .= " - ";

        return $title."Airtime";
    }

    public static function SetHeadTitle($title, $view=null){
        self::SetValue("station_name", $title);

        // in case this is called from airtime-saas script
        if($view !== null){
            //set session variable to new station name so that html title is updated.
            //should probably do this in a view helper to keep this controller as minimal as possible.
            $view->headTitle()->exchangeArray(array()); //clear headTitle ArrayObject
            $view->headTitle(self::GetHeadTitle());
        }
				
        $eventType = "update_station_name";
        $md = array("station_name"=>$title);
		
        Application_Model_RabbitMq::SendMessageToPypo($eventType, $md);
    }

    /**
     * Set the furthest date that a never-ending show 
     * should be populated until.
     * 
     * @param DateTime $dateTime
     *        A row from cc_show_days table
     */ 
    public static function SetShowsPopulatedUntil($dateTime) {
        self::SetValue("shows_populated_until", $dateTime->format("Y-m-d H:i:s"));
    }

    /**
     * Get the furthest date that a never-ending show 
     * should be populated until.
     *
     * Returns null if the value hasn't been set, otherwise returns
     * a DateTime object representing the date. 
     * 
     * @return DateTime (in UTC Timezone)
     */
    public static function GetShowsPopulatedUntil() {
        $date = self::GetValue("shows_populated_until");
        
        if ($date == ""){
            return null;
        } else {
            return new DateTime($date, new DateTimeZone("UTC"));
        }
    }

    public static function SetDefaultFade($fade) {
        self::SetValue("default_fade", $fade);
    }

    public static function GetDefaultFade() {
        $fade = self::GetValue("default_fade");
        
        if ($fade === "") {
            // the default value of the fade is 00.500000
            return "00.500000";
        } 
        
        $fade = number_format($fade, 6);
        return $fade;
    }
    
    public static function SetDefaultTransitionFade($fade) {
{'fraction_non_alphanumeric': 0.13186813186813187, 'fraction_numerical': 0.002772002772002772, 'mean_word_length': 1.7638850889192887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '3945031', 'n_tokens_mistral': 3071, 'n_tokens_neox': 2873, 'n_words': 772}