From f2a4e9e1d0fa0ab28fcac06f6623dab641e60321 Mon Sep 17 00:00:00 2001 From: manotheus Date: Tue, 4 Jun 2019 11:03:05 -0300 Subject: [PATCH] Add Filter on Get Options method This is a simple improvement on method GetOptions, now is possible filter records created by specific user. --- core/MY_Model.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/MY_Model.php b/core/MY_Model.php index e17a24d..9359f82 100644 --- a/core/MY_Model.php +++ b/core/MY_Model.php @@ -2066,6 +2066,46 @@ private function _parse_model_dir($foreign_model) return $data; } + /** + * Public Get Options Select + * + * The method is util for get option in database return + * @param $table + * @param $primary_key + * @param $label + * @param $soft_delete + * @param $owner + * @return $data + */ + public function GetOptions($table = null, $primary_key = 'id', $label = 'label', $soft_delete = TRUE, $owner_id = false){ + + $criteria = ' 1'; + + if(is_null($table)){ + show_error('Table not found'); + return false; + } + + if($owner_id != false){ + $criteria = ' created_by = ' . $owner_id; + } + + if($soft_delete){ + $query = $this->db->query('SELECT ' . $primary_key . ','. $label . ' FROM ' . $table .' where deleted_at = "0000-00-00 00:00:00" AND' . $criteria)->result_array(); + }else{ + $query = $this->db->query('SELECT ' . $primary_key . ','. $label . ' FROM ' . $table . ' WHERE ' . $criteria)->result_array(); + } + + if($query){ + $dropdown[''] = 'Selecione uma opção:'; + foreach($query as $row){ + $dropdown[$row[$primary_key]] = $row[$label]; + } + } + + return $dropdown; + + } /* public function add_creator($data)