+ /**
+ * Returns all browsable albums for a given user
+ *
+ * @param int $uid The given user
+ *
+ * @return array An array of albums
+ * @throws \Exception
+ */
+ public static function getBrowsableAlbumsForUser(int $uid): array
+ {
+ $photos = DBA::toArray(
+ DBA::p(
+ "SELECT DISTINCT(`album`) AS `album` FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?)",
+ $uid,
+ static::CONTACT_AVATAR,
+ static::CONTACT_BANNER
+ )
+ );
+
+ return array_column($photos, 'album');
+ }
+
+ /**
+ * Returns browsable photos for a given user (optional and a given album)
+ *
+ * @param int $uid The given user id
+ * @param string|null $album (optional) The given album
+ *
+ * @return array All photos of the user/album
+ * @throws \Exception
+ */
+ public static function getBrowsablePhotosForUser(int $uid, string $album = null): array
+ {
+ $values = [
+ $uid,
+ Photo::CONTACT_AVATAR,
+ Photo::CONTACT_BANNER
+ ];
+
+ if (!empty($album)) {
+ $sqlExtra = "AND `album` = ? ";
+ $values[] = $album;
+ $sqlExtra2 = "";
+ } else {
+ $sqlExtra = '';
+ $sqlExtra2 = ' ORDER BY created DESC LIMIT 0, 10';
+ }
+
+ return DBA::toArray(
+ DBA::p(
+ "SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
+ min(`scale`) AS `hiq`, max(`scale`) AS `loq`, ANY_VALUE(`desc`) AS `desc`, ANY_VALUE(`created`) AS `created`
+ FROM `photo` WHERE `uid` = ? AND NOT `photo-type` IN (?, ?) $sqlExtra
+ GROUP BY `resource-id` $sqlExtra2",
+ $values
+ ));
+ }
+