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

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

@param null $id_group                  ID group cần kiểm tra
@param null $authentication_sidebar_id ID quyền cần kiểm tra

@return int
337188
public function countAuthenticationSidebarMetaByUserGroup($id_group = NULL, $authentication_sidebar_id = NULL)
    {
        $this->connection();
        $db = DB::table('authentication_sidebar_by_user_group');
        if (!empty($id_group)) {
            $db->where('id_group', self::OPERATOR_EQUAL_TO, $id_group);
        }
        if (!empty($authentication_sidebar_id)) {
            $db->where('authentication_sidebar_id', self::OPERATOR_EQUAL_TO, $authentication_sidebar_id);
        }
        $result = $db->count('id');

        return $result;
    }
14179
public function countOpenByIdentifier($identifier): int
    {
        $queryBuilder = $this->createQuery();
        $where = $queryBuilder->expr()->andX(
            $queryBuilder->expr()->eq('cache_url', $queryBuilder->createNamedParameter($identifier)),
            $queryBuilder->expr()->eq('call_date', $queryBuilder->createNamedParameter(0))
        );

        return (int)$queryBuilder->select('uid')
            ->from($this->getTableName())
            ->where($where)
            ->execute()
            ->rowCount();
    }
925056
public function get_from_course_module_id(int $id) : ?forum_entity {
        $records = $this->get_from_course_module_ids([$id]);
        return count($records) ? array_shift($records) : null;
    }
317239
public function countCustomerCustomerGroups(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collCustomerCustomerGroupsPartial && !$this->isNew();
        if (null === $this->collCustomerCustomerGroups || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collCustomerCustomerGroups) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getCustomerCustomerGroups());
            }

            $query = ChildCustomerCustomerGroupQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByCustomerGroup($this)
                ->count($con);
        }

        return count($this->collCustomerCustomerGroups);
    }
391088
public function loadOneById($id)
    {
        $stmt = $this->getMatchOneByIdCypher($id);
        $result = $this->_em->getDatabaseDriver()->run($stmt->text(), $stmt->parameters());
        $hydrator = $this->_em->getEntityHydrator($this->_className);
        $entities = $hydrator->hydrateAll($result);

        return count($entities) === 1 ? $entities[0] : null;
    }
1056473
public static function verify($categoryId = null, $forumId = null, $threadId = null, $id = null)
    {
        if (!is_numeric($categoryId) || $categoryId < 1
                || !is_numeric($forumId) || $forumId < 1
                || !is_numeric($threadId) || $threadId < 1
                || !is_numeric($id) || $id < 1) {
            return null;
        }
        return static::find()->joinWith(['thread', 'forum' => function ($query) use ($categoryId) {
                $query->joinWith(['category'])->andWhere([Category::tableName() . '.id' => $categoryId]);
            }])->where([
                static::tableName() . '.id' => $id,
                static::tableName() . '.thread_id' => $threadId,
                static::tableName() . '.forum_id' => $forumId,
            ])->limit(1)->one();
    }
535732
public function count()
    {
        $qb = $this->getLoadQuery()
            ->select('COUNT(' . $this->getAlias() . '.id) as count')
            ->resetQueryParts(['groupBy', 'join'])
        ;
        $result = $qb->execute()->fetchColumn(0);

        return (int) $result;
    }
129668
function getAccountInfoByUid($uid)
    {
        $response = $this->call( new Command\AccountInfo($uid, Command\AccountInfo::TYPE_UID) );
        if ( $ex = $response->hasException() )
            throw $ex;

        $r = $response->expected();
        $r = ($r instanceof iDataEntity) ? $r->get('result') : $r;
        return $r;
    }
796351
public function count_null_id_columns()
        {
            if (Arrays::is($this->_getIdColumnName())) {
                return count(array_filter($this->id(), 'is_null'));
            } else {
                return is_null($this->id()) ? 1 : 0;
            }
        }
946650
public static function find_by_id($id)
	{
		$hzad = self::oneOrNew($id);

		if (!$hzad->get('authenticator'))
		{
			return false;
		}

		return $hzad;
	}
451651
public function countRoleAssignmentsUsingSection($id)
    {
        try {
            return $this->innerGateway->countRoleAssignmentsUsingSection($id);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
126329
public function share_with_group(string $id, string $id_group, bool $cancel = false): ?int
  {
    if ( $cfg = $this->get($id) ){

      $id_share = $this->db->select_one($this->class_table, $this->fields['id'], [
        'id_alias' => $id,
        'id_group' => $id_group
      ]);
      if ( $cancel && $id_share ){
        return $this->db->delete($this->class_table, [$this->fields['id'] => $id_share]);
      }
      else if ( !$cancel && !$id_share ){
        return $this->db->insert($this->class_table, [
          'id_option' => $cfg['id_option'],
          'id_alias' => $id,
          'id_group' => $id_group
        ]);
      }
      return 0;
    }
    return null;
  }
422977
public function user_delete($id): int
  {
    if ( property_exists($this, 'user') && $this->check() ){
      return $this->db->delete('bbn_observers', ['id' => $id, 'id_user' => $this->user]);
    }
    return 0;
  }
867567
public function set_by_option(string $id_option, array $cfg): int
  {
    if ( $id = $this->retrieve_user_ids($id_option, $this->id_user) ){
      return $this->set($id[0], $cfg);
    }
    return $this->_insert($id_option, $cfg);
  }
1230249
public static function findPostsCount($id)
    {
        $cache = Podium::getInstance()->podiumCache->getElement('user.postscount', $id);
        if ($cache === false) {
            $cache = (new Query)->from(Post::tableName())->where(['author_id' => $id])->count();
            Podium::getInstance()->podiumCache->setElement('user.postscount', $id, $cache);
        }
        return $cache;
    }
1231670
public function countByStatus($status)
    {
        $qb = $this->createQueryBuilder('q');
        $qb->where($qb->expr()->eq('q.status', $qb->expr()->literal($status)));
        $qb->select('COUNT(q.id)');

        return (int) $qb->getQuery()->getSingleScalarResult();
    }
548515
public function member($group_id, $user = null)
	{
		// if it's not a group id, fetch it from the object
		if ( ! is_numeric($group_id))
		{
			$group_id = $group_id->id;
		}

		// do we know this group?
		if (isset(static::$_valid_groups[$group_id]))
		{
			// if no user is given
			if ($user === null)
			{
				// get the groups of the logged-in user
				$groups = \Auth::instance()->get_groups();
			}
			else
			{
				// get the groups if the given user instance
				$groups = \Auth::instance($user[0])->get_groups();
			}

			// if no group info could be retrieved, the user can't be a member
			if ( ! $groups)
			{
				return false;
			}

			// check for membership
			foreach($groups as $group)
			{
				if ($group[0] === $this->id and $group_id === (int) $group[1]->id)
				{
					return true;
				}
			}
		}

		return false;
	}