<commit_before><?php
/**
 * Accept and Match user scores to those recieved from ETS
 * @author <NAME> <<EMAIL>>
 * @license http://jazzee.org/license.txt
 * @package jazzee
 * @subpackage apply
 */
class ETSMatchPage extends StandardPage {

  /**
   * Create the ETS form
   * @return Form
   */
  protected function makeForm(){
    $form = new Form;
    $field = $form->newField();
    $field->legend = $this->applicationPage->title;
    $field->instructions = $this->applicationPage->instructions;
    
    $e = $field->newElement('RadioList', 'scoreType');
    $e->label = 'Test Type';
    $e->addValidator('NotEmpty');
    $e->addItem('gre', 'GRE/GRE Subject');
    $e->addItem('toefl', 'TOEFL');
    
    $e = $field->newElement('TextInput', 'registrationNumber');
    $e->label = 'ETS Registration Number';
    $e->format = 'no leading zeros';
    $e->addValidator('NotEmpty');
    $e->addValidator('Integer');
    $e->addFilter('PHPSanitize', FILTER_SANITIZE_NUMBER_INT);
    
    $e = $field->newElement('ShortDateInput', 'testDate');
    $e->label = 'Test Date';
    $e->format = date('F Y', strtotime('3 months ago'));
    $e->addValidator('NotEmpty');
    $e->addValidator('Date');
    $e->addFilter('DateFormat', 'n/Y');
    
    $form->newButton('submit', 'Save');
    $form->newButton('reset', 'Clear Form');
    return $form;
  }
  
  public function newAnswer($input){
    $a = new Answer;
    $a->pageID = $this->applicationPage->Page->id;
    $this->applicant['Answers'][] = $a;
    $answer = new ETSAnswer($a);
    $answer->update($input);
    $this->applicant->save();
    $this->form->applyDefaultValues();
    return true;
  }
  
  public function updateAnswer($input, $answerID){
    if($a = $this->applicant->getAnswerByID($answerID)){
      $answer = new ETSAnswer($a);
      $answer->update($input);
      $a->save();
      $this->form->applyDefaultValues();
    }
  }
  
  public function fill($answerID){
    if($a = $this->applicant->getAnswerByID($answerID)){
      $answer = new ETSAnswer($a);
      $this->form->elements['scoreType']->value = $answer->getFormValueForElement('scoreType');
      $this->form->elements['registrationNumber']->value = $answer->getFormValueForElement('registrationNumber');
      $this->form->elements['testDate']->value = $answer->getFormValueForElement('testDate');
    }
  }
  
  public function getAnswers(){
    $answers = array();
    foreach($this->applicant->getAnswersForPage($this->applicationPage->Page->id) as $a){
      $answers[] = new ETSAnswer($a);
    }
    return $answers;
  }
  
}

/**
 * ETS Answers
 */
class ETSAnswer extends StandardAnswer {
   
  public function update(FormInput $input){
    $this->answer->Score->scoreType = $input->scoreType;
    $this->answer->Score->registrationNumber = $input->registrationNumber;
    $arr = explode('/', $input->testDate);
    $this->answer->Score->testMonth = $arr[0];
    $this->answer->Score->testYear = $arr[1];
    $this->answer->Score->scoreID = null; //reset the score ID in case we already had a match
    $this->answer->Score->makeMatch();
  }
  
  public function getElements(){
    return array(
      'scoreType' => 'Test Type',
      'registrationNumber' => 'ETS Registration Number',
      'testDate' => 'Test Date'
    );
  }
  
  public function getDisplayValueForElement($name){
    if($name == 'scoreType'){
      switch($this->answer->Score->scoreType){
        case 'gre':
          return 'GRE/GRE Subject';
        case 'toefl':
          return 'TOEFL';
      }
    } else if($name == 'testDate'){
      return date('F Y', strtotime($this->answer->Score->testMonth . '/1/' . $this->answer->Score->testYear));
    } else {
      return $this->answer->Score->$name;
    }
  }
  
  public function getFormValueForElement($name){
    if($name == 'testDate'){
      return date('F Y', strtotime($this->answer->Score->testMonth . '/1/' . $this->answer->Score->testYear));
    } else {
      return $this->answer->Score->$name;
    }
  }
  
  public function applyStatus(){
    $arr = parent::applyStatus();
    if($this->answer->Score->Score){
      $arr['Score Status'] = 'ETS Score recieved for test taken on ' . date('m/d/Y', strtotime($this->answer->Score->Score->testDate));
    } else {
      $arr['Score Status'] = 'This score has not been matched to one sent from ETS';
    }
    return $arr;
  }
  
  public function applicantStatus(){
    $arr = parent::applicantStatus();
    if($this->answer->Score->Score){
      $arr['Score Status'] = 'ETS Score recieved for test taken on ' . date('m/d/Y', strtotime($this->answer->Score->Score->testDate));
    } else {
      $arr['Score Status'] = 'This score has not been matched to one sent from ETS';
    }
    return $arr;
  }
}
?><commit_msg>Fix ETSMatchPage to work with updated ShortDateInputElement.<commit_after><?php
/**
 * Accept and Match user scores to those recieved from ETS
 * @author <NAME> <<EMAIL>>
 * @license http://jazzee.org/license.txt
 * @package jazzee
 * @subpackage apply
 */
class ETSMatchPage extends StandardPage {

  /**
   * Create the ETS form
   * @return Form
   */
  protected function makeForm(){
    $form = new Form;
    $field = $form->newField();
    $field->legend = $this->applicationPage->title;
    $field->instructions = $this->applicationPage->instructions;
    
    $e = $field->newElement('RadioList', 'scoreType');
    $e->label = 'Test Type';
    $e->addValidator('NotEmpty');
    $e->addItem('gre', 'GRE/GRE Subject');
    $e->addItem('toefl', 'TOEFL');
    
    $e = $field->newElement('TextInput', 'registrationNumber');
    $e->label = 'ETS Registration Number';
    $e->format = 'no leading zeros';
    $e->addValidator('NotEmpty');
    $e->addValidator('Integer');
    $e->addFilter('PHPSanitize', FILTER_SANITIZE_NUMBER_INT);
    
    $e = $field->newElement('ShortDateInput', 'testDate');
    $e->label = 'Test Date';
    $e->addValidator('NotEmpty');
    $e->addValidator('Date');
    $e->addFilter('DateFormat', 'm/d/Y');
    
    $form->newButton('submit', 'Save');
    $form->newButton('reset', 'Clear Form');
    return $form;
  }
  
  public function newAnswer($input){
    $a = new Answer;
    $a->pageID = $this->applicationPage->Page->id;
    $this->applicant['Answers'][] = $a;
    $answer = new ETSAnswer($a);
    $answer->update($input);
    $this->applicant->save();
    $this->form->applyDefaultValues();
    return true;
  }
  
  public function updateAnswer($input, $answerID){
    if($a = $this->applicant->getAnswerByID($answerID)){
      $answer = new ETSAnswer($a);
      $answer->update($input);
      $a->save();
      $this->form->applyDefaultValues();
    }
  }
  
  public function fill($answerID){
    if($a = $this->applicant->getAnswerByID($answerID)){
      $answer = new ETSAnswer($a);
      $this->form->elements['scoreType']->value = $answer->getFormValueForElement('scoreType');
      $this->form->elements['registrationNumber']->value = $answer->getFormValueForElement('registrationNumber');
      $this->form->elements['testDate']->value = $answer->getFormValueForElement('testDate');
    }
  }
  
  public function getAnswers(){
    $answers = array();
    foreach($this->applicant->getAnswersForPage($this->applicationPage->Page->id) as $a){
      $answers[] = new ETSAnswer($a);
    }
    return $answers;
  }
  
}

/**
 * ETS Answers
 */
class ETSAnswer extends StandardAnswer {
   
  public function update(FormInput $input){
    $this->answer->Score->scoreType = $input->scoreType;
    $this->answer->Score->registrationNumber = $input->registrationNumber;
    $this->answer->Score->testMonth = date('n', strtotime($input->testDate));
    $this->answer->Score->testYear = date('Y', strtotime($input->testDate));
    $this->answer->Score->scoreID = null; //reset the score ID in case we already had a match
    $this->answer->Score->makeMatch();
  }
  
  public function getElements(){
    return array(
      'scoreType' => 'Test Type',
      'registrationNumber' => 'ETS Registration Number',
      'testDate' => 'Test Date'
    );
  }
  
  public function getDisplayValueForElement($name){
    if($name == 'scoreType'){
      switch($this->answer->Score->scoreType){
        case 'gre':
          return 'GRE/GRE Subject';
        case 'toefl':
          return 'TOEFL';
      }
    } else if($name == 'testDate'){
      return date('F Y', strtotime($this->answer->Score->testMonth . '/1/' . $this->answer->Score->testYear));
    } else {
      return $this->answer->Score->$name;
    }
  }
  
  public function getFormValueForElement($name){
    if($name == 'testDate'){
      return "{$this->answer->Score->testYear}-{$this->answer->Score->testMonth}";
    } else {
      return $this->answer->Score->$name;
    }
  }
  
  public function applyStatus(){
    $arr = parent::applyStatus();
    if($this->answer->Score->Score){
      $arr['Score Status'] = 'ETS Score recieved for test taken on ' . date('m/d/Y', strtotime($this->answer->Score->Score->testDate));
    } else {
      $arr['Score Status'] = 'This score has not been matched to one sent from ETS';
    }
    return $arr;
  }
  
  public function applicantStatus(){
    $arr = parent::applicantStatus();
    if($this->answer->Score->Score){
      $arr['Score Status'] = 'ETS Score recieved for test taken on ' . date('m/d/Y', strtotime($this->answer->Score->Score->testDate));
    } else {
      $arr['Score Status'] = 'This score has not been matched to one sent from ETS';
    }
    return $arr;
  }
}
?>
{'fraction_non_alphanumeric': 0.1855256207078711, 'fraction_numerical': 0.0006339144215530904, 'mean_word_length': 3.326325411334552, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 251, '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': '923552', 'n_tokens_mistral': 3105, 'n_tokens_neox': 3014, 'n_words': 607}