|
| 1 | +<?php |
| 2 | +defined('BASEPATH') or exit('No direct script access allowed'); |
| 3 | +/** |
| 4 | + * Project codeigniter-framework |
| 5 | + * Created by PhpStorm |
| 6 | + * User: 713uk13m <dev@nguyenanhung.com> |
| 7 | + * Copyright: 713uk13m <dev@nguyenanhung.com> |
| 8 | + * Date: 11/02/2023 |
| 9 | + * Time: 19:25 |
| 10 | + */ |
| 11 | +if (!class_exists('HungNG_Basic_Custom_Model_Credentials_model')) { |
| 12 | + /** |
| 13 | + * Class HungNG_CI_Base_Custom_Model_Credentials_model |
| 14 | + * |
| 15 | + * @author 713uk13m <dev@nguyenanhung.com> |
| 16 | + * @copyright 713uk13m <dev@nguyenanhung.com> |
| 17 | + * |
| 18 | + * @property CI_DB_pdo_driver|CI_DB_mysqli_driver|CI_DB_query_builder|CI_DB_driver $db This is the platform-independent base Query Builder implementation class |
| 19 | + */ |
| 20 | + class HungNG_CI_Base_Custom_Model_Credentials_model extends HungNG_Custom_Based_model |
| 21 | + { |
| 22 | + const IS_ACTIVE = 1; |
| 23 | + const ROLE_PUSH = 1; |
| 24 | + const ROLE_PULL = 2; |
| 25 | + const ROLE_FULL = 3; |
| 26 | + |
| 27 | + protected $fieldUsername; |
| 28 | + protected $fieldStatus; |
| 29 | + protected $fieldRole; |
| 30 | + |
| 31 | + /** |
| 32 | + * HungNG_Basic_Custom_Credentials_model constructor. |
| 33 | + * |
| 34 | + * @author : 713uk13m <dev@nguyenanhung.com> |
| 35 | + * @copyright: 713uk13m <dev@nguyenanhung.com> |
| 36 | + */ |
| 37 | + public function __construct() |
| 38 | + { |
| 39 | + parent::__construct(); |
| 40 | + $this->db = $this->load->database('default', true, true); |
| 41 | + $this->tableName = 'credentials'; |
| 42 | + $this->primary_key = 'id'; |
| 43 | + $this->fieldUsername = 'username'; |
| 44 | + $this->fieldStatus = 'status'; |
| 45 | + $this->fieldRole = 'role'; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Function checkCredentials |
| 50 | + * |
| 51 | + * @param string $username |
| 52 | + * |
| 53 | + * @return int |
| 54 | + * @author : 713uk13m <dev@nguyenanhung.com> |
| 55 | + * @copyright: 713uk13m <dev@nguyenanhung.com> |
| 56 | + * @time : 09/03/2021 35:51 |
| 57 | + */ |
| 58 | + public function checkCredentials($username = '') |
| 59 | + { |
| 60 | + $this->db->select($this->primary_key); |
| 61 | + $this->db->from($this->tableName); |
| 62 | + $this->db->where($this->fieldUsername, $username); |
| 63 | + $this->db->where($this->fieldStatus, self::IS_ACTIVE); |
| 64 | + return $this->db->count_all_results(); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Function getInfoCredentials |
| 69 | + * |
| 70 | + * @param string $username |
| 71 | + * |
| 72 | + * @return array|mixed|object|null |
| 73 | + * @author : 713uk13m <dev@nguyenanhung.com> |
| 74 | + * @copyright: 713uk13m <dev@nguyenanhung.com> |
| 75 | + * @time : 09/03/2021 40:35 |
| 76 | + */ |
| 77 | + public function getInfoCredentials($username = '') |
| 78 | + { |
| 79 | + $this->db->select(); |
| 80 | + $this->db->from($this->tableName); |
| 81 | + $this->db->where($this->fieldUsername, $username); |
| 82 | + $this->db->where($this->fieldStatus, self::IS_ACTIVE); |
| 83 | + $info = $this->db->get()->row(); |
| 84 | + if (empty($info)) { |
| 85 | + return null; |
| 86 | + } |
| 87 | + |
| 88 | + return $info; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Function checkUserRoleIsFull |
| 93 | + * |
| 94 | + * @param string $username |
| 95 | + * |
| 96 | + * @return bool |
| 97 | + * @author : 713uk13m <dev@nguyenanhung.com> |
| 98 | + * @copyright: 713uk13m <dev@nguyenanhung.com> |
| 99 | + * @time : 09/03/2021 41:52 |
| 100 | + */ |
| 101 | + public function checkUserRoleIsFull($username = '') |
| 102 | + { |
| 103 | + $this->db->select($this->primary_key); |
| 104 | + $this->db->from($this->tableName); |
| 105 | + $this->db->where($this->fieldUsername, $username); |
| 106 | + $this->db->where($this->fieldStatus, self::IS_ACTIVE); |
| 107 | + $this->db->where($this->fieldRole, self::ROLE_FULL); |
| 108 | + $result = $this->db->count_all_results(); |
| 109 | + if ($result) { |
| 110 | + return true; |
| 111 | + } |
| 112 | + |
| 113 | + return false; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Function checkUserRoleIsPull |
| 118 | + * |
| 119 | + * @param string $username |
| 120 | + * |
| 121 | + * @return bool |
| 122 | + * @author : 713uk13m <dev@nguyenanhung.com> |
| 123 | + * @copyright: 713uk13m <dev@nguyenanhung.com> |
| 124 | + * @time : 09/03/2021 42:35 |
| 125 | + */ |
| 126 | + public function checkUserRoleIsPull($username = '') |
| 127 | + { |
| 128 | + $this->db->select($this->primary_key); |
| 129 | + $this->db->from($this->tableName); |
| 130 | + $this->db->where($this->fieldUsername, $username); |
| 131 | + $this->db->where($this->fieldStatus, self::IS_ACTIVE); |
| 132 | + $this->db->where_in($this->fieldRole, array(self::ROLE_FULL, self::ROLE_PULL)); |
| 133 | + $result = $this->db->count_all_results(); |
| 134 | + if ($result) { |
| 135 | + return true; |
| 136 | + } |
| 137 | + |
| 138 | + return false; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Function checkUserRoleIsPush |
| 143 | + * |
| 144 | + * @param string $username |
| 145 | + * |
| 146 | + * @return bool |
| 147 | + * @author : 713uk13m <dev@nguyenanhung.com> |
| 148 | + * @copyright: 713uk13m <dev@nguyenanhung.com> |
| 149 | + * @time : 09/03/2021 42:58 |
| 150 | + */ |
| 151 | + public function checkUserRoleIsPush($username = '') |
| 152 | + { |
| 153 | + $this->db->select($this->primary_key); |
| 154 | + $this->db->from($this->tableName); |
| 155 | + $this->db->where($this->fieldUsername, $username); |
| 156 | + $this->db->where($this->fieldStatus, self::IS_ACTIVE); |
| 157 | + $this->db->where_in($this->fieldRole, array(self::ROLE_FULL, self::ROLE_PUSH)); |
| 158 | + $result = $this->db->count_all_results(); |
| 159 | + if ($result) { |
| 160 | + return true; |
| 161 | + } |
| 162 | + |
| 163 | + return false; |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments