Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions core/MY_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down