Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update destruct models #59

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
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
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
Loading