@param Element $element
@param string  $notUserId

@return ElementLock[]
552424
public function findByElementAndNotUserId(Element $element, $notUserId)
    {
        $qb = $this->createQueryBuilder('l');
        $qb
            ->where($qb->expr()->eq('l.element', $element->getEid()))
            ->andWhere($qb->expr()->neq('l.userId', $qb->expr()->literal($notUserId)));

        return $qb->getQuery()->getResult();
    }
206648
public function getUsersWithEntityVersionLock(LockableEntityInterface $entity, User $userToExclude = null)
    {
        /** @var LockableEntity $lockable */
        $lockable = $this->getLockableEntity($entity);

        return  array_reduce(
            $this->getEntityVersionLocksByLockableEntity($lockable, $userToExclude),
            function ($return, EntityVersionLock $item) {
                $return[] = $item->getOwner();

                return $return;
            },
            []
        );
    }
46349
public function addElement(ListElement $element)
    {
        if ($this->hasElement($element->getUuid())) {
            throw new ListElementDuplicateKeyException('Key '.$element->getUuid()->getUuid().' already in use.');
        }

        if (!ListElementConsistencyChecker::isConsistent($element, $this->elements)) {
            throw new ListElementNotConsistentException('Element '.$element->getUuid()->getUuid().' is not consistent with list data.');
        }

        $this->elements[$element->getUuid()->getUuid()] = $element;
    }
528721
public function insertAfter($element)
    {
        $e = self::create($element);
        $newnodes = array();
        foreach ($e as $i => $node) {
            /** @var \DOMNode $node */
            $refnode = $node->nextSibling;
            foreach ($this as $newnode) {
                /** @var \DOMNode $newnode */
                $newnode = static::importNewnode($newnode, $node, $i);
                if ($refnode === null) {
                    $node->parentNode->appendChild($newnode);
                } else {
                    $node->parentNode->insertBefore($newnode, $refnode);
                }
                $newnodes[] = $newnode;
            }
        }
        return self::create($newnodes);
    }
1186642
protected function defineElement($element, $name = null, $description = null, array $values = [], array $options = [], array $params = [])
    {
        return [
            'name' => $name ?: $element,
            'description' => $description,
            'element' => $element,
            'values' => $values,
            'params' => $params,
        ];
    }
772384
public static function lock_submissions($assignmentid, $userids) {
        global $CFG;

        $params = self::validate_parameters(self::lock_submissions_parameters(),
                        array('assignmentid' => $assignmentid,
                              'userids' => $userids));

        list($assignment, $course, $cm, $context) = self::validate_assign($params['assignmentid']);

        $warnings = array();
        foreach ($params['userids'] as $userid) {
            if (!$assignment->lock_submission($userid)) {
                $detail = 'User id: ' . $userid . ', Assignment id: ' . $params['assignmentid'];
                $warnings[] = self::generate_warning($params['assignmentid'],
                                                     'couldnotlock',
                                                     $detail);
            }
        }

        return $warnings;
    }
534035
protected function element($element = null)
    {
        return is_null($element)
            ? $this->element
            : ($this->element = $element);
    }
1122307
public function load($userId)
    {
        $data = $this->userGateway->load($userId);

        if (empty($data)) {
            throw new NotFound('user', $userId);
        }

        return $this->mapper->mapUser(reset($data));
    }
1062151
public function syncMappingUser(int $userId): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/admin/ldap/user/:user_id/sync', (string)$userId),
            Request::METHOD_POST);
    }
701577
public static function block_user(int $userid, int $usertoblockid) {
        global $DB;

        $blocked = new \stdClass();
        $blocked->userid = $userid;
        $blocked->blockeduserid = $usertoblockid;
        $blocked->timecreated = time();
        $blocked->id = $DB->insert_record('message_users_blocked', $blocked);

        // Trigger event for blocking a contact.
        $event = \core\event\message_user_blocked::create(array(
            'objectid' => $blocked->id,
            'userid' => $userid,
            'relateduserid' => $usertoblockid,
            'context' => \context_user::instance($userid)
        ));
        $event->add_record_snapshot('message_users_blocked', $blocked);
        $event->trigger();
    }
175745
public function getValidationMessageFor($element)
    {
        $errorLabel = $this->getElement($element)->getParent()->find('css', '.sylius-validation-error');

        if (null === $errorLabel) {
            throw new ElementNotFoundException(
                $this->getSession(),
                'Validation message', 'css', '.sylius-validation-error')
            ;
        }

        return $errorLabel->getText();
    }
1183490
public function remove($element) {
		$index = array_search($element, $this->collection, true);
		if ($index !== null) {
			unset($this->collection[$index]);
		}

		return $this;
	}
1020632
public static function get_blocked_users($userid) {
        global $CFG, $USER, $PAGE;

        // Warnings array, it can be empty at the end but is mandatory.
        $warnings = array();

        // Validate params.
        $params = array(
            'userid' => $userid
        );
        $params = self::validate_parameters(self::get_blocked_users_parameters(), $params);
        $userid = $params['userid'];

        // Validate context.
        $context = context_system::instance();
        self::validate_context($context);

        // Check if private messaging between users is allowed.
        if (empty($CFG->messaging)) {
            throw new moodle_exception('disabled', 'message');
        }

        $user = core_user::get_user($userid, '*', MUST_EXIST);
        core_user::require_active_user($user);

        // Check if we have permissions for retrieve the information.
        $capability = 'moodle/site:manageallmessaging';
        if (($USER->id != $userid) && !has_capability($capability, $context)) {
            throw new required_capability_exception($context, $capability, 'nopermissions', '');
        }

        // Now, we can get safely all the blocked users.
        $users = \core_message\api::get_blocked_users($user->id);

        $blockedusers = array();
        foreach ($users as $user) {
            $newuser = array(
                'id' => $user->id,
                'fullname' => fullname($user),
            );

            $userpicture = new user_picture($user);
            $userpicture->size = 1; // Size f1.
            $newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false);

            $blockedusers[] = $newuser;
        }

        $results = array(
            'users' => $blockedusers,
            'warnings' => $warnings
        );
        return $results;
    }
577203
private function validateValue($element, $userInput) : array
    {
        $valid = true;
        $value = null;
        $typedValue = null;

        if ($element->isRequired() && is_null($userInput)) {
            $valid = false;
        }

        if ($element->getPrimitiveType() && !is_null($userInput)) {
            $typedValue = $this->validateType($userInput, $element->getPrimitiveType());
            if (is_null($typedValue)) {
                $valid = false;
            } else {
                $value = $typedValue;
            }
        } else {
            $value = $userInput;
        }

        if (method_exists($element, 'transformValue') && $value) {
            $value = $element->transformValue($value);
        }

        if (method_exists($element, 'isValid') && $valid == true && $element->getValue()) {
            $valid = $element->isValid();
        }

        if (!$valid) {
            $value = null;
        }

        return [$valid, $value, $typedValue];
    }
1154569
public function delete($id)
    {
        if ($id === '1') {
            throw new ForbiddenException();
        }
        if (!$this->request->is(['post'])) {
            throw new MethodNotAllowedException();
        }

        /** @var Connection $connection */
        $connection = $this->Groups->connection();

        $connection->begin();
        $group = $this->Groups->get($id);

        $users = $this->Groups->UsersGroups->Users->find()
            ->matching('UsersGroups', function (Query $q) use ($id) {
                return $q->where(['UsersGroups.group_id' => $id]);
            });

        // Filter the resulting users to match only users assigned to more than one user group.
        $skipUserIds = $this->Groups->UsersGroups->findUserIdsWithOnlyOneGroup();
        if (!empty($skipUserIds)) {
            $users->where([
                $this->Groups->Users->aliasField('id') . ' IN' => $skipUserIds
            ]);
        }

        $userCount = $users->all()->count();
        $groupCanBeDeleted = ($userCount === 0);

        if (($alternativeGroupIds = $this->request->data('alternative_group_id')) !== null) {
            // check if a valid alternative group has been selected for every user
            $valid = true;
            $validAlternativeGroupIds = [];
            foreach ($users as $user) {
                if (!isset($alternativeGroupIds[$user->id]) ||
                    (int)$alternativeGroupIds[$user->id] === (int)$id ||
                    !$this->Groups->exists(['id' => $alternativeGroupIds[$user->id]])
                ) {
                    $valid = false;
                } else {
                    $validAlternativeGroupIds[$user->id] = (int)$alternativeGroupIds[$user->id];
                }
            }
            if ($valid) {
                // move existing users of the group to the submitted alternative group
                $groupCanBeDeleted = (bool)$this->Groups->moveUsersToAlternativeGroups($validAlternativeGroupIds);
            } else {
                $this->Flash->error(__d('wasabi_core', 'Please select an alternative user group for every listed user.'));
            }
        }

        if ($groupCanBeDeleted === true) {
            if ($this->Groups->delete($group)) {
                $connection->commit();
                if ($userCount > 0) {
                    $this->Flash->success(__d('wasabi_core', 'The group <strong>{0}</strong> has been deleted. Prior <strong>{1}</strong> group member(s) ha(s/ve) been moved to another group.', $group->name, $userCount));
                } else {
                    $this->Flash->success(__d('wasabi_core', 'The group <strong>{0}</strong> has been deleted.', $group->name));
                }
            } else {
                $connection->rollback();
                $this->Flash->error($this->dbErrorMessage);
            }
            $this->redirect($this->Filter->getBacklink(['action' => 'index'], $this->request));
            return;
        } else {
            $connection->rollback();
            $this->Flash->warning(__d('wasabi_core', 'The group <strong>{0}</strong> has <strong>{1}</strong> member(s) that need to be moved to another group.', $group->name, $userCount));
            $this->set([
                'users' => $users,
                'group' => $group,
                'groups' => $this->Groups->find('list')->where(['not' => ['id' => $id]])
            ]);
        }
    }
1234787
public function getNotifications($id = null, $userId = null, $userRole = null) {
		$fields = [
			$this->alias . '.id',
			$this->alias . '.user_id',
			$this->alias . '.user_role',
			$this->alias . '.tag',
			$this->alias . '.title',
			$this->alias . '.body',
			$this->alias . '.data',
		];
		$conditions = [
			'AND' => [
				$this->alias . '.expires >=' => date('Y-m-d H:i:s'),
				'OR' => [
					[
						'AND' => [
							$this->alias . '.user_id' => '',
							$this->alias . '.user_role' => '',
						]
					]
				]
			]
		];
		if (!empty($id)) {
			$conditions['AND'][][$this->alias . '.id >'] = (int)$id;
		}
		if (!empty($userId)) {
			$conditions['AND']['OR'][][$this->alias . '.user_id'] = (int)$userId;
		}
		if (!empty($userRole)) {
			$conditions['AND']['OR'][]['AND'] = [
				$this->alias . '.user_role & ' . (int)$userRole . ' > 0',
				$this->alias . '.user_id' => '',
			];
		}

		$order = [$this->alias . '.id' => 'asc'];

		return $this->find('all', compact('fields', 'conditions', 'order'));
	}
303511
public function indexOfByUid($element, $useIntIndex = false)
    {
        if ($element instanceof AbstractClassContent) {
            /* find content */
            $index = 0;
            foreach ($this->getData() as $key => $content) {
                if ($content instanceof AbstractClassContent && $element->getUid() === $content->getUid()) {
                    $index = ($useIntIndex) ? (int) $key : $index;

                    return $index;
                }
                $index++;
            }

            return false;
        }

        return array_search($element, $this->_data, true);
    }