Removes the the access level for this group if
it is added to the access levels.

@access public
@param string $uuid
@param array $accessLevels
@return array
342287
protected function cleanAccessLevels($uuid, $accessLevels)
    {
        foreach ($accessLevels as $key => $accessLevel) {
            if ($this->hasGroupLoop($accessLevel, $uuid)) {
                unset($accessLevels[$key]);
            }
        }
        
        return $accessLevels;
    }
1092780
private function traverse($id, $level = -1)
    {
        $lft = $this->count;
        ++$this->count;
        if (isset($this->parents[$id])) {
            foreach ($this->parents[$id] as $child) {
                $this->traverse($child, $level + 1);
            }
            unset($this->parents[$id]);
        }
        $rgt = $this->count;
        ++$this->count;
        $this->update[$id] = array('level' => $level, 'lft' => $lft, 'rgt' => $rgt);
    }
1004030
@Override
	public CProduct removeByUUID_G(String uuid, long groupId)
		throws NoSuchCProductException {
		CProduct cProduct = findByUUID_G(uuid, groupId);

		return remove(cProduct);
	}
681600
public function migrateDown( $levels = NULL )
    {
        if ( NULL !== $levels )
        {
            $this->levels = $levels;
        }
        
        $migrations = $this->getAppliedMigrations( );
        
        $i = 0;
        
        if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $migrations ) )
        {
            $this->levels = count( $migrations );
        }
        
        while ( $i < $this->levels )
        {
            $class = $migrations[ $i ];
            
            $migration = new $class( );
            
            $method = new \ReflectionMethod( $class, 'migrateDown' );
            
            // run migrateDown
            if ( $class === $method->getDeclaringClass( )->name )
            {
                $migration->migrateDown( $this->db );
                
                // delete migration from table
                if ( FALSE === $this->_deleteMigrationRecord( $class ) )
                {
                    throw new MigrationException( 'Failed to delete migration record: ' . $class );
                }
            }
            else // run safeMigrateDown
            {
                $method = new \ReflectionMethod( $class, 'safeMigrateDown' );
            
                if ( $class === $method->getDeclaringClass( )->name )
                {
                    try
                    {
                        // start transaction
                        $this->db->startTransaction( );

                        // turn off auto commit
                        $this->db->setTransactionAutocommit( FALSE );

                        // run safeMigrateDown
                        $migration->safeMigrateDown( $this->db );

                        // delete migration record
                        if ( FALSE === $this->_deleteMigrationRecord( $class ) )
                        {
                            throw new MigrationException( 
                                    'Failed to delete migration record: ' . $class );
                            
                            $this->db->rollbackTransaction();
                        }

                        // commit transaction
                        $this->db->commitTransaction( );
                    }
                    catch ( \Exception $e )
                    {
                        // rollback transaction
                        $this->db->rollbackTransaction( );

                        throw $e;
                    }
                }
            }
            
            $i++;
            
            if ( $this->levels === $i )
            {
                $this->doAction( self::ON_MIGRATE_DOWN_ACTION );
                
                return;
            }
        }
    }
1206760
@Override
	public CPDefinitionVirtualSetting removeByUUID_G(String uuid, long groupId)
		throws NoSuchCPDefinitionVirtualSettingException {
		CPDefinitionVirtualSetting cpDefinitionVirtualSetting = findByUUID_G(uuid,
				groupId);

		return remove(cpDefinitionVirtualSetting);
	}
861513
public static function delete_instance($contextlevel, $instanceid) {
        global $DB;

        // double check the context still exists
        if ($record = $DB->get_record('context', array('contextlevel'=>$contextlevel, 'instanceid'=>$instanceid))) {
            $context = context::create_instance_from_record($record);
            $context->delete();
        } else {
            // we should try to purge the cache anyway
        }
    }
814471
@Override
	public void removeByUuid(String uuid) {
		for (CPInstance cpInstance : findByUuid(uuid, QueryUtil.ALL_POS,
				QueryUtil.ALL_POS, null)) {
			remove(cpInstance);
		}
	}
355944
public function delete($uuid, array $params = array())
	{
		$params['uuid'] = $uuid;
		if (!isset($params['type_name'])) {
			throw new MissingArgumentException('type_name');
		}

		return $this->_del($params);
	}
721743
public function grantPermission($accessEntityUuid, $accessEntityClass, $accessLevel, $grantedBy)
    {
        return $this->permissionsDataSource->grantPermission($accessEntityUuid, $accessEntityClass, $accessLevel, $grantedBy);
    }
268667
@Override
	public CPDefinitionLink removeByUUID_G(String uuid, long groupId)
		throws NoSuchCPDefinitionLinkException {
		CPDefinitionLink cpDefinitionLink = findByUUID_G(uuid, groupId);

		return remove(cpDefinitionLink);
	}
981423
public static function getAuthorisedViewLevels($userId)
	{
		// Get all groups that the user is mapped to recursively.
		$groups = self::getGroupsByUser($userId);

		// Only load the view levels once.
		if (empty(self::$viewLevels))
		{
			// Build the view levels array.
			$levels = Viewlevel::all()
				->rows();

			foreach ($levels as $level)
			{
				self::$viewLevels[$level->get('id')] = (array) json_decode($level->get('rules'));
			}
		}

		// Initialise the authorised array.
		$authorised = array(1);

		// Find the authorised levels.
		foreach (self::$viewLevels as $level => $rule)
		{
			foreach ($rule as $id)
			{
				if (($id < 0) && (($id * -1) == $userId))
				{
					$authorised[] = $level;
					break;
				}
				// Check to see if the group is mapped to the level.
				elseif (($id >= 0) && in_array($id, $groups))
				{
					$authorised[] = $level;
					break;
				}
			}
		}

		return $authorised;
	}
58749
public function my_removeUid($uid)
    {
        if (get_instance()->isCluster()) {
            $this->map[$this->node_name]->remove($uid);
            foreach ($this->client as $client) {
                $client->removeNodeUid($this->node_name, $uid);
            }
            if (Start::isLeader()) {
                get_instance()->pub('$SYS/uidcount', $this->countOnline());
            }
        }
        $this->my_clearUidSub($uid);
    }
142318
public function revokePermission($accessEntityUuid, $accessEntityClass, $accessLevel)
    {
        return $this->permissionsDataSource->revokePermission($accessEntityUuid, $accessEntityClass, $accessLevel);
    }
249381
protected function hasPermissionForModifiedGroup($modifiedUuid, $groupUuid)
    {
        $permissions = $this->accessControlManager->getPermissionsRawForUuid($groupUuid);
        
        if ($permissions === false) {
            return false;
        }
        
        foreach ($permissions as $permission) {
            $result = $this->hasGroupLoop($permission, $modifiedUuid);
            
            if ($result === true) {
                return true;
            }
        }
    }
420780
public function hasAccess($accessLevel)
    {
        foreach ($this->permissions as $permission) {
            /**
             * If the user has the \Globa\* access level he can
             * do everything
             */
            if ($permission == '\\Global\\*') {
                return true;
            }
            
            if ($permission == $accessLevel) {
                return true;
            }
            
            // If there is a star in the permission and everything before 
            // the star is equal with the access level, the user has access
            // to the given access level.
            $posStar = strpos($permission, '*');
            if ($posStar !== false) {
                $startPermission = substr($permission, 0, $posStar);
                $startAccessLevel = substr($accessLevel, 0, $posStar);
                
                if ($startPermission == $startAccessLevel) {
                    return true;
                }
            } 
        }
    
        return false;
    }
885590
@Override
	public void removeByUuid(String uuid) {
		for (CommerceSubscriptionEntry commerceSubscriptionEntry : findByUuid(
				uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceSubscriptionEntry);
		}
	}
362457
public function getPermissionsForUuid($accessEntityUuid)
    {
        // Do not check the database if we haven't all data
        if ($accessEntityUuid == '') {
            return array();
        }
    
        try {
            $accessLevels = $this->getPermissionsRawForUuid($accessEntityUuid);
    
            $accessLevels = $this->runtimeManager->executeFilter('\\Zepi\\Core\\AccessControl\\Filter\\PermissionsBackend\\ResolvePermissions', $accessLevels);

            return $accessLevels;
        } catch (\Exception $e) {
            throw new Exception('Cannot load the permission for the given uuid "' . $accessEntityUuid . '".', 0, $e);
        }
    }