- * @param Image $Image image
- * @param integer $uid uid
- * @param integer $cid cid
- * @param integer $rid rid
- * @param string $filename filename
- * @param string $album album name
- * @param integer $scale scale
- * @param integer $profile optional, default = 0
- * @param string $allow_cid optional, default = ''
- * @param string $allow_gid optional, default = ''
- * @param string $deny_cid optional, default = ''
- * @param string $deny_gid optional, default = ''
- * @param string $desc optional, default = ''
- * @return object
+ * @brief Select rows from the photo table
+ *
+ * @param array $fields Array of selected fields, empty for all
+ * @param array $conditions Array of fields for conditions
+ * @param array $params Array of several parameters
+ *
+ * @return boolean|array
+ *
+ * @see \Friendica\Database\DBA::select
+ */
+ public static function select(array $fields = [], array $conditions = [], array $params = [])
+ {
+ if (empty($fields)) {
+ $selected = self::getFields();
+ }
+
+ $r = DBA::select("photo", $fields, $conditions, $params);
+ return DBA::toArray($r);
+ }
+
+ /**
+ * @brief Retrieve a single record from the photo table
+ *
+ * @param array $fields Array of selected fields, empty for all
+ * @param array $conditions Array of fields for conditions
+ * @param array $params Array of several parameters
+ *
+ * @return bool|array
+ *
+ * @see \Friendica\Database\DBA::select
+ */
+ public static function selectFirst(array $fields = [], array $conditions = [], array $params = [])
+ {
+ if (empty($fields)) {
+ $fields = self::getFields();
+ }
+
+ return DBA::selectFirst("photo", $fields, $conditions, $params);
+ }
+
+ /**
+ * @brief Get photos for user id
+ *
+ * @param integer $uid User id
+ * @param string $resourceid Rescource ID of the photo
+ * @param array $conditions Array of fields for conditions
+ * @param array $params Array of several parameters
+ *
+ * @return bool|array
+ *
+ * @see \Friendica\Database\DBA::select
+ */
+ public static function getPhotosForUser($uid, $resourceid, array $conditions = [], array $params = [])
+ {
+ $conditions["resource-id"] = $resourceid;
+ $conditions["uid"] = $uid;
+
+ return self::select([], $conditions, $params);
+ }
+
+ /**
+ * @brief Get a photo for user id
+ *
+ * @param integer $uid User id
+ * @param string $resourceid Rescource ID of the photo
+ * @param integer $scale Scale of the photo. Defaults to 0
+ * @param array $conditions Array of fields for conditions
+ * @param array $params Array of several parameters
+ *
+ * @return bool|array
+ *
+ * @see \Friendica\Database\DBA::select
+ */
+ public static function getPhotoForUser($uid, $resourceid, $scale = 0, array $conditions = [], array $params = [])
+ {
+ $conditions["resource-id"] = $resourceid;
+ $conditions["uid"] = $uid;
+ $conditions["scale"] = $scale;
+
+ return self::selectFirst([], $conditions, $params);
+ }
+
+ /**
+ * @brief Get a single photo given resource id and scale
+ *
+ * This method checks for permissions. Returns associative array
+ * on success, "no sign" image info, if user has no permission,
+ * false if photo does not exists
+ *
+ * @param string $resourceid Rescource ID of the photo
+ * @param integer $scale Scale of the photo. Defaults to 0
+ *
+ * @return boolean|array
+ */
+ public static function getPhoto($resourceid, $scale = 0)
+ {
+ $r = self::selectFirst(["uid"], ["resource-id" => $resourceid]);
+ if ($r === false) {
+ return false;
+ }
+
+ $sql_acl = Security::getPermissionsSQLByUserId($r["uid"]);
+
+ $conditions = [
+ "`resource-id` = ? AND `scale` <= ? " . $sql_acl,
+ $resourceid, $scale
+ ];
+
+ $params = ["order" => ["scale" => true]];
+
+ $photo = self::selectFirst([], $conditions, $params);
+ if ($photo === false) {
+ return self::createPhotoForSystemResource("images/nosign.jpg");
+ }
+ return $photo;
+ }
+
+ /**
+ * @brief Check if photo with given resource id exists
+ *
+ * @param string $resourceid Resource ID of the photo
+ *
+ * @return boolean