Skip to content

Commit

Permalink
Update packageS
Browse files Browse the repository at this point in the history
  • Loading branch information
hungnguyenhp committed Jun 15, 2022
1 parent 4c06672 commit 2962530
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,6 @@ class TestModule extends HungNG_CI_Base_Module
## Liên hệ

| Name | Email | Skype | Facebook |
| ----------- | -------------------- | ---------------- | ------------- |
|-------------|----------------------|------------------|---------------|
| Hung Nguyen | [email protected] | nguyenanhung5891 | @nguyenanhung |

38 changes: 33 additions & 5 deletions hungng/HungNG_Custom_Based_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function page_limit($size = 500, $page = 0)
{
if ($size !== 'no_limit') {
if ($page !== 0) {
if (!$page || $page <= 0 || empty($page)) {
if ($page <= 0 || empty($page)) {
$page = 1;
}
$start = ($page - 1) * $size;
Expand Down Expand Up @@ -235,6 +235,34 @@ public function get_last_id($field = 'id')
return 0;
}

public function get_first_id($field = 'id')
{
$this->db->select($field);
$this->db->from($this->tableName);
$this->db->limit(1);
$this->db->order_by($field, 'ASC');
$row = $this->db->get()->row();
if (is_object($row)) {
return $row->$field;
}

return 0;
}

public function get_random_id($field = 'id')
{
$this->db->select($field);
$this->db->from($this->tableName);
$this->db->limit(1);
$this->db->order_by($field, 'RANDOM');
$row = $this->db->get()->row();
if (is_object($row)) {
return $row->$field;
}

return 0;
}

/**
* Function get_all
*
Expand Down Expand Up @@ -325,7 +353,7 @@ public function get_list_distinct($field = '*')
/**
* Function get_data_simple_result
*
* @param string $selectField
* @param string $select
* @param array $wheres
* @param int $size
* @param int $page
Expand All @@ -336,9 +364,9 @@ public function get_list_distinct($field = '*')
* @copyright: 713uk13m <[email protected]>
* @time : 09/13/2021 16:49
*/
public function get_data_simple_result($selectField = '*', $wheres = [], $size = 75, $page = 0, $orderBy = ['id' => 'DESC'])
public function get_data_simple_result($select = '*', $wheres = [], $size = 75, $page = 0, $orderBy = ['id' => 'DESC'])
{
$this->db->select($selectField);
$this->db->select($select);
$this->db->from($this->tableName);
if (count($wheres) > 0) {
foreach ($wheres as $field => $value) {
Expand Down Expand Up @@ -372,7 +400,7 @@ public function get_data_simple_result($selectField = '*', $wheres = [], $size =
public function get_all_data_simple_result($options = null)
{
$this->db->from($this->tableName);
if (($options !== null) && is_array($options)) {
if (is_array($options)) {
foreach ($options as $field => $value) {
if (is_array($value)) {
$this->db->where_in($field, $value);
Expand Down

0 comments on commit 2962530

Please sign in to comment.