Count Trạng thái phân quyền Sidebar theo User ID

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 10/18/18 15:36

@param null $user_id                   User ID cần kiểm tra
@param null $authentication_sidebar_id ID quyền cần kiểm tra

@return int
16167
public function countAuthenticationSidebarMetaByUserId($user_id = NULL, $authentication_sidebar_id = NULL)
    {
        $this->connection();
        $db = DB::table('authentication_sidebar_by_user_id');
        if (!empty($user_id)) {
            $db->where('user_id', self::OPERATOR_EQUAL_TO, $user_id);
        }
        if (!empty($authentication_id)) {
            $db->where('authentication_sidebar_id', self::OPERATOR_EQUAL_TO, $authentication_sidebar_id);
        }
        $result = $db->count('id');

        return $result;
    }
137909
public static function get_by_user_id($user_id) {
	$mysql = bootstrap::get_library('mysql');
	
	$sql   = "SELECT * FROM `login_github` WHERE `user_id` = %d;";
	$login = $mysql::select('row', $sql, $user_id);
	if (empty($login)) {
		return false;
	}
	
	return new static($login['id']);
}
674608
public function usersCount($id) {

        // I know eloquent does this, but having trouble so hand crafting using DB
        // Note the pivot table
        $record =  DB::table('user_group')->where('group_id', '=', $id)->get();
        return count($record);
    }
181238
public function getByUser($product_id, $user_id)
    {
        $result = null;
        $this->hook->attach('rating.get.user.before', $product_id, $user_id, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $user_ids = (array) $user_id;
        $conditions = array_merge($user_ids, array($product_id));
        $placeholders = rtrim(str_repeat('?,', count($user_ids)), ',');

        $sql = "SELECT * FROM rating_user WHERE user_id IN($placeholders) AND product_id=?";

        $result = $this->db->fetchAll($sql, $conditions, array('index' => 'user_id'));

        if (!is_array($user_id) && isset($result[$user_id])) {
            $result = $result[$user_id];
        }

        $this->hook->attach('rating.get.user.after', $product_id, $user_id, $result, $this);
        return $result;
    }
776976
public static function loadUserInfoBypass($user_id)
    {
        global $CFG, $PDOX, $CONTEXT;
        $cacheloc = 'lti_user';
        $row = Cache::check($cacheloc, $user_id);
        if ( $row != false ) return $row;
        $stmt = $PDOX->queryDie(
            "SELECT displayname, email, user_key FROM {$CFG->dbprefix}lti_user AS U
            JOIN {$CFG->dbprefix}lti_membership AS M
            ON U.user_id = M.user_id AND M.context_id = :CID
            WHERE U.user_id = :UID",
            array(":UID" => $user_id, ":CID" => $CONTEXT->id)
        );
        $row = $stmt->fetch(\PDO::FETCH_ASSOC);
        if ( strlen($row['displayname']) < 1 && strlen($row['user_key']) > 0 ) {
            $row['displayname'] = 'user_key:'.substr($row['user_key'],0,25);
        }
        Cache::set($cacheloc, $user_id, $row);
        return $row;
    }
535253
public function getLogsByUserId($id, $page = 0, $pagesize = 100, $sort = 'id', $direction = 'asc')
    {
        if(is_null($id)) {
            throw new \Exception('User ID is required.');
        }

        $result = (Object)array(
            "logs" =>  array(),
            "total" => 0
        );

        $repo = $this->getRepository('\erdiko\users\entities\user\event\Log');

        $offset = 0;
        if ($page > 0) {
            $offset = ($page - 1) * $pagesize;
        }

        $result->logs = $repo->findBy(
            array("user_id" => $id),
            array(
                $sort => $direction
            ),
            $pagesize,
            $offset
        );

        // get total log count
        $result->total = (int)$repo->createQueryBuilder('u')
            ->select('count(u.id)')
            ->where('u.user_id = :user_id')
            ->setParameter("user_id", $id)
            ->getQuery()
            ->getSingleScalarResult();

        return $result;
    }
1266850
public static function find_by_user_id($user_id = null)
	{
		if (empty($user_id))
		{
			return false;
		}

		$l = self::blank()->getTableName();
		$d = Domain::blank()->getTableName();

		$results = self::all()
			->select($l . '.*')
			->select($d . '.authenticator', 'auth_domain_name')
			->join($d, $d . '.id', $l . '.auth_domain_id', 'inner')
			->whereEquals($l . '.user_id', $user_id)
			->rows();

		if (empty($results))
		{
			return false;
		}

		return $results->toArray();
	}
1322328
public function getClientUser($client_id, $user_id)
    {
        $sql = 'SELECT * from %s where client_id = :client_id and user_id = :user_id';
        $sql = sprintf($sql, $this->config['client_user_table']);

        return $this->fetch($sql, compact('client_id', 'user_id'));
    }
10798
public function countAllPostsThatHaveUserId($id)  {
        // How many posts did this user create (created_by)?
        $results = DB::table('posts')->where('created_by', '=', $id)->get();

        if ( (count($results)) == 0 || (empty($results)) ) {
            $created_by = 0;
        } else {
            $created_by = count($results);
        }

        // How many posts did this user update (updated_by)?
        $results = DB::table('posts')->where('updated_by', '=', $id)->get();

        if ( (count($results)) == 0 || (empty($results)) ) {
            $updated_by = 0;
        } else {
            $updated_by = count($results);
        }

        return ['created_by' => $created_by, 'updated_by' => $updated_by];
    }
1352409
public function getLimit($user_id)
    {
        if (is_numeric($user_id)) {
            $user = $this->user->get($user_id);
            if (isset($user['role_id'])) {
                return $this->getLimitByRole($user['role_id']);
            }
        }

        return $this->getDefaultLimit();
    }
15389
public function getPermissions($user_id = null)
    {
        static $permissions = array();

        if (!isset($user_id)) {
            $user_id = $this->uid;
        }

        if (isset($permissions[$user_id])) {
            return $permissions[$user_id];
        }

        $user = $this->get($user_id);

        if (empty($user['role_id'])) {
            return $permissions[$user_id] = array();
        }

        $role = array();
        if (isset($user['role_permissions'])) {
            $role['permissions'] = $user['role_permissions'];
        } else {
            $role = $this->role->get($user['role_id']);
        }

        if (empty($role['permissions'])) {
            return $permissions[$user_id] = array();
        }

        return $permissions[$user_id] = (array) $role['permissions'];
    }
1310093
public function userGet(int $user_id)
    {
        $value = get_user_meta($user_id, $this->getName(), ! $this->getOption('multiple', false));

        if (! empty($value)) {
            $this->setValue($value);
        }
    }
74150
public static function get_users_count($context, $search = '') {
        global $DB;

        list($sql, $params) = self::get_users_sql_and_params($context, $search, true);
        return $DB->count_records_sql($sql, $params);

    }
1342293
static function failedLoginAttemptsByUserID( $userID )
    {
        $db = eZDB::instance();
        $contentObjectID = (int) $userID;

        $userVisitArray = $db->arrayQuery( "SELECT failed_login_attempts FROM ezuservisit WHERE user_id=$contentObjectID" );

        $failedLoginAttempts = isset( $userVisitArray[0] ) ? $userVisitArray[0]['failed_login_attempts'] : 0;
        return $failedLoginAttempts;
    }
635188
public function getRequestCount(AuthenticationRecordInterface $authenticationRecord): int
    {
        $fiveMinutesAgo = new \DateTime('now', new \DateTimeZone('UTC'));
        $fiveMinutesAgo->modify('-5 minutes');

        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('COUNT(r.id) AS total')
            ->where('r.authentication = :authentication')
            ->andWhere('r.request_time > :since')
            ->setParameter('authentication', $authenticationRecord)
            ->setParameter('since', $fiveMinutesAgo)
            ->getQuery();

        return $query->getSingleScalarResult();
    }
533399
public static function count_user_subscriptions_for_course($courseid, $userid = 0) {
        global $DB, $USER;
        if ($userid == 0) {
            $userid = $USER->id;
        }
        $sql = self::get_subscription_join_rule_sql(true);
        $sql .= "WHERE s.courseid = :courseid AND s.userid = :userid";

        return $DB->count_records_sql($sql, array('courseid' => $courseid, 'userid' => $userid));
    }
527422
public function count($user)
    {
        if (!is_string($user)) {
            throw new \InvalidArgumentException();
        }

        if (!isset($this->keys[$user])) {
            return 0;
        }

        return count($this->keys[$user]);
    }