<commit_before><?php namespace models;
use \Exception, \RuntimeException;

class LoadQ extends \core\model {
  
  public static function main($owner, $offset = 0){
    if (!is_numeric($offset) or $offset < 0)
      throw new InvalidArgumentException('The offset is not of correct type.');
    $offset = intval($offset);
    
    try {
      if (!($owner instanceof User))
        $owner = new User($owner);
      
      if ($owner->deactivated)
        throw new Exception('This user has deactivated their account.');
      
      if (! $owner->profileVisibleBy($GLOBALS['user']))
        throw new Exception("You are not allowed to view this user's questions", 403);
      
      $query = "SELECT id FROM questions WHERE answer IS NOT NULL AND touser".
        " = '$owner->username' ORDER BY timeanswered DESC LIMIT 11 OFFSET $offset;";
      $res = self::$_db->query($query);
      if (!$res)
        throw new RuntimeException(self::$_db->error);
      
    } catch (Exception $e) {
      throw $e;
      // TODO anything better?
    }
    
    if ($res->num_rows === 0)
      http_response_code(204); //No content
    else {
      
      $i = 1;
      while(($row = $res->fetch_array()) and $i++ !== 11){
        $q = new Question($row['id']);
        
        $q->writeOut();
      }
      
      return $res;
    }
  }
}
?>
<commit_msg>Rewrote m\LoadQ::main()<commit_after><?php namespace models;
use \Exception;

class LoadQ extends \core\model {
  
  public static function main($owner, $offset = 0){
    if (!is_numeric($offset) or $offset < 0)
      throw new \InvalidArgumentException('The offset is not of correct type.');
    $offset = intval($offset);
    
    
    if (!($owner instanceof User))
      $owner = new User($owner);
    
    if ($owner->deactivated)
      throw new Exception('This user has deactivated their account.');
    
    if (! $owner->profileVisibleBy($GLOBALS['user']))
      throw new Exception("You are not allowed to view this user's questions", 403);
    
    $query = "SELECT * FROM questions WHERE answer IS NOT NULL AND touser".
      " = '$owner->username' ORDER BY timeanswered DESC LIMIT 11 OFFSET $offset;";
    
    $qset = new QuestionSet($query);
    
    $count = count($qset->members);
    
    return $qset->members; // array of \model\Questions
  }
}
?>

{'fraction_non_alphanumeric': 0.13976633491994808, 'fraction_numerical': 0.009086975335352661, 'mean_word_length': 2.573415765069552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, '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': '7618133', 'n_tokens_mistral': 701, 'n_tokens_neox': 673, 'n_words': 213}