public function getObjectsList($whereList = array(), $limit = 10, $offset = 0)
 {
     $this->load->database();
     $fields_query = $this->createFieldsListString();
     $this->db->select($fields_query["fields_list"]);
     if (count($fields_query["join_list"])) {
         foreach ($fields_query["join_list"] as $index => $join_field) {
             $condition = $join_field['table'] . "." . $join_field['field'] . " = " . $join_field['join_table'] . "." . $join_field['join_field'];
             $this->db->join($join_field['join_table'], $condition, $join_field['type']);
         }
     }
     if (count($whereList)) {
         foreach ($whereList as $where_field => $where_opt) {
             switch ($where_opt['data_type']) {
                 case SystemHelper::DATATYPE_DATE:
                     $where_opt['value'] = SystemHelper::convertDateFromBR($where_opt['value']);
                     if (isset($where_opt['or_where']) && $where_opt['or_where']) {
                         $this->db->or_where(array($where_field => $where_opt['value']));
                     } else {
                         $this->db->where(array($where_field => $where_opt['value']));
                     }
                     break;
                 case SystemHelper::DATATYPE_TEXT:
                     if (isset($where_opt['or_where']) && $where_opt['or_where']) {
                         $this->db->or_like($where_field, $where_opt['value']);
                     } else {
                         $this->db->like($where_field, $where_opt['value']);
                     }
                     break;
             }
         }
     }
     if ($this->debugMode) {
         AlertMessage::display(array('type' => AlertMessage::INFO, 'icon' => 'fa fa-bug', 'message' => '<b>SQL Debug:</b> <br><br>' . $this->db->get_compiled_select($this->getTable())));
     }
     // $limit = -1 is infinite
     if ($limit > -1) {
         if ($offset > 0) {
             $result = $this->db->get($this->getTable(), $limit, $offset);
         } else {
             $result = $this->db->get($this->getTable(), $limit);
         }
     } else {
         $result = $this->db->get($this->getTable());
     }
     $this->db->close();
     return $result->result_array();
 }
 public function beforeAdd($FORMDATA)
 {
     include_once "Address.php";
     include_once "Contact.php";
     include_once "BankAccount.php";
     if (isset($FORMDATA['idiomas'])) {
         $this->addToAfterData("idiomas", $FORMDATA['idiomas']);
         unset($FORMDATA['idiomas']);
     }
     if (isset($FORMDATA['disponibilidade_horario'])) {
         $FORMDATA['disponibilidade_horario'] = implode(",", $FORMDATA['disponibilidade_horario']);
     } else {
         $FORMDATA['disponibilidade_horario'] = null;
     }
     if (isset($FORMDATA['disponibilidade_veiculos'])) {
         $FORMDATA['disponibilidade_veiculos'] = implode(",", $FORMDATA['disponibilidade_veiculos']);
     } else {
         $FORMDATA['disponibilidade_veiculos'] = null;
     }
     if (isset($FORMDATA['dt_nascimento']) && !empty($FORMDATA['dt_nascimento'])) {
         $FORMDATA['dt_nascimento'] = SystemHelper::convertDateFromBR($FORMDATA['dt_nascimento']);
         $dt1 = date_create($FORMDATA['dt_nascimento']);
         $dt2 = date_create(date('Y-m-d'));
         $diff = $dt1->diff($dt2);
         $FORMDATA['idade'] = $diff->format("%y");
     }
     $this->address = new Address();
     $this->contact = new Contact();
     $this->bank_account = new BankAccount();
     $FORMDATA = $this->address->storeToProcess($FORMDATA);
     $FORMDATA = $this->contact->storeToProcess($FORMDATA);
     $FORMDATA = $this->bank_account->storeToProcess($FORMDATA);
     return $FORMDATA;
 }
 public function autoConvertDates($to_convert)
 {
     foreach ($to_convert as $field_name => $value) {
         if (substr($field_name, 0, 3) == "dt_") {
             $to_convert[$field_name] = SystemHelper::convertDateFromBR($value);
         }
     }
     return $to_convert;
 }
 public function beforeAdd($FORMDATA)
 {
     if (!isset($FORMDATA['administrador'])) {
         $FORMDATA['administrador'] = false;
     }
     if (!empty($FORMDATA['senha'])) {
         $FORMDATA['senha'] = md5($FORMDATA['senha']);
         unset($FORMDATA['senha_confirmacao']);
     } else {
         unset($FORMDATA['senha']);
         unset($FORMDATA['senha_confirmacao']);
     }
     if (!empty($FORMDATA['dt_nasc'])) {
         $FORMDATA['dt_nasc'] = SystemHelper::convertDateFromBR($FORMDATA['dt_nasc']);
     }
     return $FORMDATA;
 }