<commit_before><?php defined('BASEPATH') OR exit('No direct script access allowed');

class CollectionModel extends CI_Model {

  var $table = "collection";

  public function getAllByAssociateId($associateId, $limit=null, $offset=null) {
    return $this->db
    ->order_by('duo_date_collection', 'ASC')
    ->get_where($this->table, ['id_associate'=>$associateId], $limit, $offset)
    ->result();
  }

  public function getById($collectionId) {
    return $this->db
      ->get_where($this->table, ['id_collection'=>$collectionId])
      ->row();
  }

  public function totalCountByAssociateId($associateId) {
    $this->db->where('id_associate', $associateId);
    return $this->db->count_all($this->table);
  }

  public function getAllByAssociateIdBetweenDate($associateId, $startDate, $endDate, $limit=null, $offset=null) {
    $this->db->where('duo_date_collection', $startDate);
    $this->db->where('duo_date_collection', $endDate);
    return $this->db->get_where($this->table, array('associate_id'=>$associateId), $limit, $offset)->result_array();
  }

  public function createCollections($associate) {
    $countFrequency = $this->FrequencyModel->getCountFrequencyByFrequencyId($associate->id_frequency);
    if ($countFrequency != null && $countFrequency != 0) {
      $collections = array();
      for ($i=0;$i<$countFrequency;$i++) {
        $duoDate = date('Y-m-d', strtotime($i ." months", strtotime($associate->duo_date)));
        $collection = (object) [
          'value_collection' => $associate->value_frequency,
          'duo_date_collection' => $duoDate,
          'id_associate' => $associate->id_associate
        ];
        array_push($collections, $collection);
      }
      $this->CollectionModel->saveBatch($collections);
    }
  }

  public function saveBatch($collections) {
    return $this->db->insert_batch($this->table, $collections);
  }

  public function save($collection) {
    $this->db->insert($this->table, $collection);
    return $this->db->insert_id();
  }<commit_msg>comment<commit_after><?php defined('BASEPATH') OR exit('No direct script access allowed');

class CollectionModel extends CI_Model {

  var $table = "collection";

  public function getAllByAssociateId($associateId, $limit=null, $offset=null) {
    return $this->db
    ->order_by('duo_date_collection', 'ASC')
    ->get_where($this->table, ['id_associate'=>$associateId], $limit, $offset)
    ->result();
  }

  public function getById($collectionId) {
    return $this->db
      ->get_where($this->table, ['id_collection'=>$collectionId])
      ->row();
  }

  public function totalCountByAssociateId($associateId) {
    $this->db->where('id_associate', $associateId);
    return $this->db->count_all($this->table);
  }

  public function getAllByAssociateIdBetweenDate($associateId, $startDate, $endDate, $limit=null, $offset=null) {
    $this->db->where('duo_date_collection', $startDate);
    $this->db->where('duo_date_collection', $endDate);
    return $this->db->get_where($this->table, array('associate_id'=>$associateId), $limit, $offset)->result_array();
  }

  /**
   * @author <NAME>, 29 nov, 2016
   * Cria um array de cobranças para o associado determinado pela quantia de parcelas.
   * @param (object) associate, requere que possua os campos:
   * @param associate->id_associate
   * @param associate->id_frequency
   * @param associate->value_frequency
   * @param associate->duo_date
   * @return insert_batch result
   */
  public function createCollections($associate) {
    $countFrequency = $this->FrequencyModel->getCountFrequencyByFrequencyId($associate->id_frequency);
    if ($countFrequency != null && $countFrequency != 0) {
      $collections = array();
      for ($i=0;$i<$countFrequency;$i++) {
        $duoDate = date('Y-m-d', strtotime($i ." months", strtotime($associate->duo_date)));
        $collection = (object) [
          'value_collection' => $associate->value_frequency,
          'duo_date_collection' => $duoDate,
          'id_associate' => $associate->id_associate
        ];
        array_push($collections, $collection);
      }
      $this->CollectionModel->saveBatch($collections);
    }
  }

  public function saveBatch($collections) {
    return $this->db->insert_batch($this->table, $collections);
  }

  public function save($collection) {
    $this->db->insert($this->table, $collection);
    return $this->db->insert_id();
  }
{'fraction_non_alphanumeric': 0.16609861395137468, 'fraction_numerical': 0.0022722108611679163, 'mean_word_length': 4.252983293556086, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 96, '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': '2218058', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1371, 'n_words': 243}