<commit_before><?php
/**
 * @file
 * class to handle request for orders.
 * ors -service url:
 * http://ors-maintenance.iscrum-staging.svc.cloud.dbc.dk:8080/api/
 *
 * api documentation:
 * https://dbcjira.atlassian.net/wiki/spaces/IS/pages/18087971/ORS2-Maintenance+API+beskrivelse
 *
 */

// include class to look up pickupagencies
require_once "orsAgency.php";
require_once "xsdparse.php";

class orsClass {
  private $config;
  private $action;
  private $curl;
  private $xmlfields;
  
  private $query;
  private $response;
  private $start;
  private $step;
  private $total;
  private $status;
  private $message;
  private $error;
  private $err_msg;
  

  /**
   * orsClass constructor.
   * @param string $action
   * @param inifile $config
   */
  public function __construct($action, $config) {
    $this->config = $config;
    $this->action = $action;
    $this->curl = new curl();
    $this->curl->set_option(CURLOPT_TIMEOUT, 30);
    $this->step = NULL;
    $this->query = NULL;
    $this->start = NULL;
    $this->total = NULL;
    $this->error = FALSE;
    $this->err_msg = array();
    $this->status = NULL;
    $this->message = NULL;
    $this->response = FALSE;
    
    // get xml schema
    $schemafile = $config->get_value('schema', 'setup');
    if (!file_exists($schemafile)) {
      die('xsd not found: ' . $schemafile);
    }
    $schema = new xml_schema();
    $schema->get_from_file($schemafile);

    // set xml-fields
    $this->action = $action;
    if (in_array($this->action, array('getReceipts', 'formatReceipt'))) {
      $this->xmlfields = $schema->get_sequence_array('receipt');
    }
    else {
      $this->xmlfields = $schema->get_sequence_array('order');
    }
  }

  /**
   * @param $param
   */
  public function setQuery($param) {
    $orsAgency = new orsAgency($this->config->get_value('openagency_agency_list', 'setup'));
    
    // NB: $param->agency bruges kun hér??
    //     Så hvemsomhelst kan få alle data, hvis de kan logge ind, 
    //     og finde ud af at skrive requesterAgency's eller responderAgency's hovedbiblioteket ISIL-nr ??.
    $consistency = $orsAgency->check_agency_consistency($param);
    if ($consistency !== TRUE) {
      $this->setError("failed_agency_consistency_check : " . explode(", ", $orsAgency->getErrorMsg()));
      return false;
    }

    $ret = array();<commit_msg>Add better error handling<commit_after><?php
/**
 * @file
 * class to handle request for orders.
 * ors -service url:
 * http://ors-maintenance.iscrum-staging.svc.cloud.dbc.dk:8080/api/
 *
 * api documentation:
 * https://dbcjira.atlassian.net/wiki/spaces/IS/pages/18087971/ORS2-Maintenance+API+beskrivelse
 *
 */

// include class to look up pickupagencies
require_once "orsAgency.php";
require_once "xsdparse.php";

class orsClass {
  private $config;
  private $action;
  private $curl;
  private $xmlfields;
  
  private $query;
  private $response;
  private $start;
  private $step;
  private $total;
  private $status;
  private $message;
  private $error;
  private $err_msg;
  

  /**
   * orsClass constructor.
   * @param string $action
   * @param inifile $config
   */
  public function __construct($action, $config) {
    $this->config = $config;
    $this->action = $action;
    $this->curl = new curl();
    $this->curl->set_option(CURLOPT_TIMEOUT, 30);
    $this->step = NULL;
    $this->query = NULL;
    $this->start = NULL;
    $this->total = NULL;
    $this->error = FALSE;
    $this->err_msg = array();
    $this->status = NULL;
    $this->message = NULL;
    $this->response = FALSE;
    
    // get xml schema
    $schemafile = $config->get_value('schema', 'setup');
    if (!file_exists($schemafile)) {
      die('xsd not found: ' . $schemafile);
    }
    $schema = new xml_schema();
    $schema->get_from_file($schemafile);

    // set xml-fields
    $this->action = $action;
    if (in_array($this->action, array('getReceipts', 'formatReceipt'))) {
      $this->xmlfields = $schema->get_sequence_array('receipt');
    }
    else {
      $this->xmlfields = $schema->get_sequence_array('order');
    }
  }

  /**
   * @param $param
   */
  public function setQuery($param) {
    $orsAgency = new orsAgency($this->config->get_value('openagency_agency_list', 'setup'));
    
    // NB: $param->agency bruges kun hér??
    //     Så hvemsomhelst kan få alle data, hvis de kan logge ind, 
    //     og finde ud af at skrive requesterAgency's eller responderAgency's hovedbiblioteket ISIL-nr ??.
    $consistency = $orsAgency->check_agency_consistency($param);
    if (!$consistency) {
      $this->setError(implode("; ", $orsAgency->getErrorMsg()));
      return false;
    }

    $ret = array();
{'fraction_non_alphanumeric': 0.1570725444040231, 'fraction_numerical': 0.006419858763107212, 'mean_word_length': 3.1399468556244465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '1141700', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1586, 'n_words': 338}