public function indexInDB(User $u) { foreach ($this->userArray as $index => $user) { if ($u->isSame($user)) { return $index; } } return -1; }
/** * Given two users, can the first $user edit the status on the $anotherUser. This is important to check to keep * user's from deactivating themselves and deactivating administrators. * @param User $user * @param User $anotherUser * @return true/false */ public static function canUserEditStatusOnAnotherUser(User $user, User $anotherUser) { assert('$user->id > 0'); assert('$anotherUser->id > 0'); if ($user->isSame($anotherUser)) { return false; } if (Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME)->contains($anotherUser)) { return false; } if (!RightsUtil::canUserAccessModule('UsersModule', $user)) { return false; } return true; }
/** * @param Conversation $conversation * @param User $user * @return A|bool */ public static function hasUserReadConversationLatest(Conversation $conversation, User $user) { assert('$conversation->id > 0'); assert('$user->id > 0'); if ($user->isSame($conversation->owner)) { return $conversation->ownerHasReadLatest; } else { foreach ($conversation->conversationParticipants as $position => $participant) { if ($participant->person->getClassId('Item') == $user->getClassId('Item')) { return $participant->hasReadLatest; } } } return false; }