+ /**
+ * Page/profile types
+ *
+ * PAGE_FLAGS_NORMAL is a typical personal profile account
+ * PAGE_FLAGS_SOAPBOX automatically approves all friend requests as Contact::SHARING, (readonly)
+ * PAGE_FLAGS_COMMUNITY automatically approves all friend requests as Contact::SHARING, but with
+ * write access to wall and comments (no email and not included in page owner's ACL lists)
+ * PAGE_FLAGS_FREELOVE automatically approves all friend requests as full friends (Contact::FRIEND).
+ *
+ * @{
+ */
+ const PAGE_FLAGS_NORMAL = 0;
+ const PAGE_FLAGS_SOAPBOX = 1;
+ const PAGE_FLAGS_COMMUNITY = 2;
+ const PAGE_FLAGS_FREELOVE = 3;
+ const PAGE_FLAGS_BLOG = 4;
+ const PAGE_FLAGS_PRVGROUP = 5;
+ /**
+ * @}
+ */
+
+ /**
+ * Account types
+ *
+ * ACCOUNT_TYPE_PERSON - the account belongs to a person
+ * Associated page types: PAGE_FLAGS_NORMAL, PAGE_FLAGS_SOAPBOX, PAGE_FLAGS_FREELOVE
+ *
+ * ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
+ * Associated page type: PAGE_FLAGS_SOAPBOX
+ *
+ * ACCOUNT_TYPE_NEWS - the account is a news reflector
+ * Associated page type: PAGE_FLAGS_SOAPBOX
+ *
+ * ACCOUNT_TYPE_COMMUNITY - the account is community forum
+ * Associated page types: PAGE_COMMUNITY, PAGE_FLAGS_PRVGROUP
+ *
+ * ACCOUNT_TYPE_RELAY - the account is a relay
+ * This will only be assigned to contacts, not to user accounts
+ * @{
+ */
+ const ACCOUNT_TYPE_PERSON = 0;
+ const ACCOUNT_TYPE_ORGANISATION = 1;
+ const ACCOUNT_TYPE_NEWS = 2;
+ const ACCOUNT_TYPE_COMMUNITY = 3;
+ const ACCOUNT_TYPE_RELAY = 4;
+ /**
+ * @}
+ */
+
+ /**
+ * Returns true if a user record exists with the provided id
+ *
+ * @param integer $uid
+ * @return boolean
+ * @throws Exception
+ */
+ public static function exists($uid)
+ {
+ return DBA::exists('user', ['uid' => $uid]);
+ }
+
+ /**
+ * @param integer $uid
+ * @param array $fields
+ * @return array|boolean User record if it exists, false otherwise
+ * @throws Exception
+ */
+ public static function getById($uid, array $fields = [])
+ {
+ return DBA::selectFirst('user', $fields, ['uid' => $uid]);
+ }
+
+ /**
+ * Returns a user record based on it's GUID
+ *
+ * @param string $guid The guid of the user
+ * @param array $fields The fields to retrieve
+ * @param bool $active True, if only active records are searched
+ *
+ * @return array|boolean User record if it exists, false otherwise
+ * @throws Exception
+ */
+ public static function getByGuid(string $guid, array $fields = [], bool $active = true)
+ {
+ if ($active) {
+ $cond = ['guid' => $guid, 'account_expired' => false, 'account_removed' => false];
+ } else {
+ $cond = ['guid' => $guid];
+ }
+
+ return DBA::selectFirst('user', $fields, $cond);
+ }
+
+ /**
+ * @param string $nickname
+ * @param array $fields
+ * @return array|boolean User record if it exists, false otherwise
+ * @throws Exception
+ */
+ public static function getByNickname($nickname, array $fields = [])
+ {
+ return DBA::selectFirst('user', $fields, ['nickname' => $nickname]);
+ }
+
+ /**
+ * @brief Returns the user id of a given profile URL
+ *
+ * @param string $url
+ *
+ * @return integer user id
+ * @throws Exception
+ */
+ public static function getIdForURL($url)
+ {
+ $self = DBA::selectFirst('contact', ['uid'], ['nurl' => Strings::normaliseLink($url), 'self' => true]);
+ if (!DBA::isResult($self)) {
+ return false;
+ } else {
+ return $self['uid'];
+ }
+ }
+
+ /**
+ * Get a user based on its email
+ *
+ * @param string $email
+ * @param array $fields
+ *
+ * @return array|boolean User record if it exists, false otherwise
+ *
+ * @throws Exception
+ */
+ public static function getByEmail($email, array $fields = [])
+ {
+ return DBA::selectFirst('user', $fields, ['email' => $email]);
+ }
+