Skip to content

Commit

Permalink
Merge pull request #59 from nguyenanhung/v3.2.0-develop
Browse files Browse the repository at this point in the history
Update destruct models
  • Loading branch information
nguyenanhung authored Sep 13, 2024
2 parents fd6535b + 769c307 commit 4e4ae0b
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 164 deletions.
324 changes: 166 additions & 158 deletions custom/HungNG_CI_Base_Custom_Model_Credentials_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,162 +10,170 @@
* Time: 19:25
*/
if (!class_exists('HungNG_CI_Base_Custom_Model_Credentials_model')) {
/**
* Class HungNG_CI_Base_Custom_Model_Credentials_model
*
* @author 713uk13m <[email protected]>
* @copyright 713uk13m <[email protected]>
*
* @property CI_DB_pdo_driver|CI_DB_query_builder|CI_DB_driver $db This is the platform-independent base Query Builder implementation class
*/
class HungNG_CI_Base_Custom_Model_Credentials_model extends HungNG_Custom_Based_model
{
const IS_ACTIVE = 1;
const ROLE_PUSH = 1;
const ROLE_PULL = 2;
const ROLE_FULL = 3;

protected $fieldUsername;
protected $fieldStatus;
protected $fieldRole;

/**
* HungNG_Basic_Custom_Credentials_model constructor.
*
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
*/
public function __construct()
{
parent::__construct();

log_message('info', 'HungNG_CI_Base_Custom_Model_Credentials_model Class Initialized');

$this->db = $this->load->database('default', true, true);
$this->tableName = 'credentials';
$this->primary_key = 'id';
$this->fieldUsername = 'username';
$this->fieldStatus = 'status';
$this->fieldRole = 'role';
}

/**
* Function checkCredentials
*
* @param string $username
*
* @return int
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 35:51
*/
public function checkCredentials($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);

return $this->db->count_all_results();
}

/**
* Function getInfoCredentials
*
* @param string $username
*
* @return array|mixed|object|null
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 40:35
*/
public function getInfoCredentials($username = '')
{
$this->db->select();
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$info = $this->db->get()->row();
if (empty($info)) {
return null;
}

return $info;
}

/**
* Function checkUserRoleIsFull
*
* @param string $username
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 41:52
*/
public function checkUserRoleIsFull($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$this->db->where($this->fieldRole, self::ROLE_FULL);
$result = $this->db->count_all_results();
if ($result) {
return true;
}

return false;
}

/**
* Function checkUserRoleIsPull
*
* @param string $username
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 42:35
*/
public function checkUserRoleIsPull($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$this->db->where_in($this->fieldRole, array(self::ROLE_FULL, self::ROLE_PULL));
$result = $this->db->count_all_results();
if ($result) {
return true;
}

return false;
}

/**
* Function checkUserRoleIsPush
*
* @param string $username
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 42:58
*/
public function checkUserRoleIsPush($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$this->db->where_in($this->fieldRole, array(self::ROLE_FULL, self::ROLE_PUSH));
$result = $this->db->count_all_results();
if ($result) {
return true;
}

return false;
}
}
/**
* Class HungNG_CI_Base_Custom_Model_Credentials_model
*
* @author 713uk13m <[email protected]>
* @copyright 713uk13m <[email protected]>
*
* @property CI_DB_pdo_driver|CI_DB_query_builder|CI_DB_driver $db This is the platform-independent base Query Builder implementation class
*/
class HungNG_CI_Base_Custom_Model_Credentials_model extends HungNG_Custom_Based_model
{
const IS_ACTIVE = 1;
const ROLE_PUSH = 1;
const ROLE_PULL = 2;
const ROLE_FULL = 3;

protected $fieldUsername;
protected $fieldStatus;
protected $fieldRole;

/**
* HungNG_Basic_Custom_Credentials_model constructor.
*
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
*/
public function __construct()
{
parent::__construct();

log_message('info', 'HungNG_CI_Base_Custom_Model_Credentials_model Class Initialized');

$this->db = $this->load->database('default', true, true);
$this->tableName = 'credentials';
$this->primary_key = 'id';
$this->fieldUsername = 'username';
$this->fieldStatus = 'status';
$this->fieldRole = 'role';
}

public function __destruct()
{
if ($this->db->conn_id) {
$this->db->close();
log_message('info', 'HungNG_CI_Base_Custom_Model_Credentials_model Class Destructed');
}
}

/**
* Function checkCredentials
*
* @param string $username
*
* @return int
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 35:51
*/
public function checkCredentials($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);

return $this->db->count_all_results();
}

/**
* Function getInfoCredentials
*
* @param string $username
*
* @return array|mixed|object|null
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 40:35
*/
public function getInfoCredentials($username = '')
{
$this->db->select();
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$info = $this->db->get()->row();
if (empty($info)) {
return null;
}

return $info;
}

/**
* Function checkUserRoleIsFull
*
* @param string $username
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 41:52
*/
public function checkUserRoleIsFull($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$this->db->where($this->fieldRole, self::ROLE_FULL);
$result = $this->db->count_all_results();
if ($result) {
return true;
}

return false;
}

/**
* Function checkUserRoleIsPull
*
* @param string $username
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 42:35
*/
public function checkUserRoleIsPull($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$this->db->where_in($this->fieldRole, array(self::ROLE_FULL, self::ROLE_PULL));
$result = $this->db->count_all_results();
if ($result) {
return true;
}

return false;
}

/**
* Function checkUserRoleIsPush
*
* @param string $username
*
* @return bool
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 09/03/2021 42:58
*/
public function checkUserRoleIsPush($username = '')
{
$this->db->select($this->primary_key);
$this->db->from($this->tableName);
$this->db->where($this->fieldUsername, $username);
$this->db->where($this->fieldStatus, self::IS_ACTIVE);
$this->db->where_in($this->fieldRole, array(self::ROLE_FULL, self::ROLE_PUSH));
$result = $this->db->count_all_results();
if ($result) {
return true;
}

return false;
}
}
}
12 changes: 6 additions & 6 deletions hungng/HungNG_Custom_Based_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ public function __construct()
/**
* __destruct models
*/
public function __destruct()
{
if (is_object($this->db)) {
$this->close();
}
}
public function __destruct()
{
if ($this->db->conn_id) {
$this->db->close();
}
}

/**
* Function setDb
Expand Down

0 comments on commit 4e4ae0b

Please sign in to comment.