<commit_before><?php

if (!defined('STATUSNET')) {
    exit(1);
}

class Translate_notice extends Managed_DataObject {
    public $__table = 'translate_notice'; // table name
    public $user_id; // int(11) not_null
    public $target_lang; // varchar(255) -- probably overkill...

    public static function schemaDef() {
        return array(
            'fields' => array(
                'user_id' => array(
                    'type' => 'int',
                    'not null' => true
                ),
                'target_lang' => array(
                    'type' => 'varchar',
                    'length' => 255
                ),
            ),
            'primary key' => array('user_id'),
        );
    }

    public static function getByUserId($userid) {
        return self::getKV('user_id', $userid);
    }

    public static function saveTargetLanguage($user, $language) {
        $tn = new Translate_notice();
        $tn->user_id = $user->id;
        $tn->target_lang = $language;

        // User never chose a language; insert().
        if (empty(self::getByUserId($user->id))) {
            $tn->insert();
        } else { // User is updating language; update().
            $tn->update();
        }
    }
}<commit_msg>Adds method to get user's target language<commit_after><?php

if (!defined('STATUSNET')) {
    exit(1);
}

class Translate_notice extends Managed_DataObject {
    public $__table = 'translate_notice'; // table name
    public $user_id; // int(11) not_null
    public $target_lang; // varchar(255) -- probably overkill...

    public static function schemaDef() {
        return array(
            'fields' => array(
                'user_id' => array(
                    'type' => 'int',
                    'not null' => true
                ),
                'target_lang' => array(
                    'type' => 'varchar',
                    'length' => 255
                ),
            ),
            'primary key' => array('user_id'),
        );
    }

    public static function getByUserId($userid) {
        return self::getKV('user_id', $userid);
    }

    public static function getTargetLanguage($user) {
        $tn = self::getByUserId($user->id);

        if (empty($tn)) {
            return null;
        } else {
            return $tn->target_lang;
        }
    }

    public static function saveTargetLanguage($user, $language) {
        $tn = new Translate_notice();
        $tn->user_id = $user->id;
        $tn->target_lang = $language;

        // User never chose a language; insert().
        if (empty(self::getByUserId($user->id))) {
            $tn->insert();
        } else { // User is updating language; update().
            $tn->update();
        }
    }
}
{'fraction_non_alphanumeric': 0.14301349872309377, 'fraction_numerical': 0.006566946369937978, 'mean_word_length': 1.654404646660213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '1048849', 'n_tokens_mistral': 796, 'n_tokens_neox': 762, 'n_words': 181}