<commit_before><?php

namespace Kula\Core\Bundle\FrameworkBundle\Service;

use \Kula\Core\Component\Record\RecordDelegateInterface;
use \Kula\Core\Component\Permission\Permission;

class Record {
  
  private $delegate;
  private static $record_object;
  
  private $record_type;
  private $add_mode;
  
  private $id_stack;
  private $selected_record_id;
  private $selected_record;
  
  public function __construct($db, $session, $schema, $focus, $request, $flash, $permission, $recordType, $searcher) {
    $this->db = $db;
    $this->session = $session;
    $this->schema = $schema;
    $this->focus = $focus;
    $this->requestService = $request;
    $this->request = $request->getCurrentRequest();
    $this->permission = $permission;
    $this->flash = $flash;
    $this->recordType = $recordType;
    $this->searcher = $searcher;
  }
  
  public function setRecordType($recordTypeName, $add_mode = null, $eager_search_data = null) {
    $recordType = $this->recordType->getRecordType($this->session->get('portal'), $recordTypeName);
    $delegate = $recordType->getClass();
    
    if (!isset($recordType))
      throw new \Exception('Record type ' . $record_type . ' does not exist in CORE_RECORD_TYPES.');
    
    // instantiate delegate
    $this->delegate = new $delegate($this->db, $this->session, $this->focus);
    
    $this->record_type = $recordType->getName();
    
    if ($this->session->get('portal') == 'core') {

      // set if in add mode
      $this->setAddMode($add_mode);
    
      if (!$add_mode) {
        $this->request = $this->requestService->getCurrentRequest();
        // try and set through existing record
        // get selected ID either through POST or GET
        if ($this->request->request->get('record_id')) {
          $this->selected_record_id = $this->request->request->get('record_id');
        } else {
          $this->selected_record_id = $this->request->query->get('record_id');
        }
      
        if ($this->request->request->get('record_type')) {
          $selected_record_type = $this->request->request->get('record_type');
        } else {
          $selected_record_type = $this->request->query->get('record_type');
        }
    
        // set record from id
        // if searching, process search, load first record returned
        if ($this->request->request->get('mode') == 'search') {
          $post_data = $this->searcher->startProcessing($this->db, $this->schema, $this->permission, $this->request);
          $this->selected_record_id = $this->_search($post_data);
        } else {
      
          if ((!isset($selected_record_type) || $selected_record_type == $this->record_type)) {
            // if looking for next record ID
            if ($this->request->request->get('scrub') == 'next' || $this->request->query->get('scrub') == 'next') {
              $this->selected_record_id = $this->_getNextRecordID();
            // if looking for previous record ID
            } elseif ($this->request->request->get('scrub') == 'previous' || $this->request->query->get('scrub') == 'previous') {
              $this->selected_record_id = $this->_getPreviousRecordID();
            } elseif ($eager_search_data) {
              $this->selected_record_id = $this->_search($eager_search_data);
            }
          } elseif ($selected_record_type != $this->record_type) {
            if (method_exists($this->delegate, 'getFromDifferentType')) {
              $this->selected_record_id = $this->delegate->getFromDifferentType($selected_record_type, $this->selected_record_id);
            } else {
              $this->selected_record_id = null;
            }
         
          } else {
            $this->selected_record_id = null;
          }
        }
    
      }
  
    }
    
    if ($this->session->get('portal') == 'student' AND $this->record_type == 'Student.HEd.Student.Status' AND $this->focus->getStudentStatusID() == '') {
      $this->focus->setStudentStatusFocus();
    }
    
    if ($this->session->get('portal') == 'teacher' OR $this->session->get('portal') == 'student') {
      
      $focus = $this->session->get('focus');
      
      if (isset($focus[$this->record_type])) {
        $this->selected_record_id = $focus[$this->record_type];
      }
    
      $selected_record_type = $this->record_type;<commit_msg>More eager loading changes.<commit_after><?php

namespace Kula\Core\Bundle\FrameworkBundle\Service;

use \Kula\Core\Component\Record\RecordDelegateInterface;
use \Kula\Core\Component\Permission\Permission;

class Record {
  
  private $delegate;
  private static $record_object;
  
  private $record_type;
  private $add_mode;
  
  private $id_stack;
  private $selected_record_id;
  private $selected_record;
  
  public function __construct($db, $session, $schema, $focus, $request, $flash, $permission, $recordType, $searcher) {
    $this->db = $db;
    $this->session = $session;
    $this->schema = $schema;
    $this->focus = $focus;
    $this->requestService = $request;
    $this->request = $request->getCurrentRequest();
    $this->permission = $permission;
    $this->flash = $flash;
    $this->recordType = $recordType;
    $this->searcher = $searcher;
  }
  
  public function setRecordType($recordTypeName, $add_mode = null, $eager_search_data = null) {
    $recordType = $this->recordType->getRecordType($this->session->get('portal'), $recordTypeName);
    $delegate = $recordType->getClass();
    
    if (!isset($recordType))
      throw new \Exception('Record type ' . $record_type . ' does not exist in CORE_RECORD_TYPES.');
    
    // instantiate delegate
    $this->delegate = new $delegate($this->db, $this->session, $this->focus);
    
    $this->record_type = $recordType->getName();
    
    if ($this->session->get('portal') == 'core') {

      // set if in add mode
      $this->setAddMode($add_mode);
    
      if (!$add_mode) {
        $this->request = $this->requestService->getCurrentRequest();
        // try and set through existing record
        // get selected ID either through POST or GET
        if ($this->request->request->get('record_id')) {
          $this->selected_record_id = $this->request->request->get('record_id');
        } else {
          $this->selected_record_id = $this->request->query->get('record_id');
        }
      
        if ($this->request->request->get('record_type')) {
          $selected_record_type = $this->request->request->get('record_type');
        } else {
          $selected_record_type = $this->request->query->get('record_type');
        }
    
        // set record from id
        // if searching, process search, load first record returned
        if ($this->request->request->get('mode') == 'search') {
          $post_data = $this->searcher->startProcessing($this->db, $this->schema, $this->permission, $this->request);
          $this->selected_record_id = $this->_search($post_data);
        } else {
      
          if ((!isset($selected_record_type) || $selected_record_type == $this->record_type)) {

            // if looking for next record ID
            if ($this->request->request->get('scrub') == 'next' || $this->request->query->get('scrub') == 'next') {
              $this->selected_record_id = $this->_getNextRecordID();
            // if looking for previous record ID
            } elseif ($this->request->request->get('scrub') == 'previous' || $this->request->query->get('scrub') == 'previous') {
              $this->selected_record_id = $this->_getPreviousRecordID();
            } elseif ($eager_search_data) {
              $this->selected_record_id = $this->_search($eager_search_data);
            }
          } elseif ($selected_record_type != $this->record_type) {
            if (method_exists($this->delegate, 'getFromDifferentType')) {
              $this->selected_record_id = $this->delegate->getFromDifferentType($selected_record_type, $this->selected_record_id);
            } elseif ($eager_search_data) {
              $this->selected_record_id = $this->_search($eager_search_data);
            } else {
              $this->selected_record_id = null;
            }
          } elseif ($eager_search_data) {
              $this->selected_record_id = $this->_search($eager_search_data);
          } else {
            $this->selected_record_id = null;
          }
        }
    
      }
  
    }
    
    if ($this->session->get('portal') == 'student' AND $this->record_type == 'Student.HEd.Student.Status' AND $this->focus->getStudentStatusID() == '') {
      $this->focus->setStudentStatusFocus();
    }
    
    if ($this->session->get('portal') == 'teacher' OR $this->session->get('portal') == 'student') {
      
      $focus = $this->session->get('focus');
      
      if (isset($focus[$this->record_type])) {
        $this->selected_record_id = $focus[$this->record_type];
      }
    
      $selected_record_type = $this->record_type;
{'fraction_non_alphanumeric': 0.16450850129489922, 'fraction_numerical': 0.0, 'mean_word_length': 2.760372565622354, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 213, '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': '5445150', 'n_tokens_mistral': 2629, 'n_tokens_neox': 2656, 'n_words': 458}