X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPost.php;h=9e137ae379496f54895ee79e372aad8be4baf011;hb=09a612670ad79960dba46b58d87780513e8e4c3f;hp=062f22db9c966937da6652726fe37e97fb39b032;hpb=4e0da578fa82b88bd521100fd7bcc934acf9779e;p=friendica.git diff --git a/src/Model/Post.php b/src/Model/Post.php index 062f22db9c..9e137ae379 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -226,6 +226,49 @@ class Post } } + /** + * Retrieve a single record from the post-user-view view and returns it in an associative array + * When the requested record is a reshare activity, the system fetches the reshared original post. + * Otherwise the function reacts similar to selectFirst + * + * @param array $fields + * @param array $condition + * @param array $params + * @param bool $user_mode true = post-user-view, false = post-view + * @return bool|array + * @throws \Exception + * @see DBA::select + */ + public static function selectOriginal(array $fields = [], array $condition = [], array $params = []) + { + $original_fields = $fields; + $remove = []; + if (!empty($fields)) { + foreach (['gravity', 'verb', 'thr-parent-id', 'uid'] as $field) { + if (!in_array($field, $fields)) { + $fields[] = $field; + $remove[] = $field; + } + } + } + $result = self::selectFirst($fields, $condition, $params); + if (empty($result)) { + return $result; + } + + if (($result['gravity'] != Item::GRAVITY_ACTIVITY) || ($result['verb'] != Activity::ANNOUNCE)) { + foreach ($remove as $field) { + unset($result[$field]); + } + return $result; + } + + $final_query_condition = ['uri-id' => $result['thr-parent-id']]; + $final_query_condition = DBA::mergeConditions($final_query_condition, ['uid != 0']); + $final_params = ['order' => ['id']]; + return self::selectFirst($original_fields, $final_query_condition, $final_params); + } + /** * Retrieve a single record from the post-view view and returns it in an associative array * @@ -505,6 +548,46 @@ class Post } } + /** + * Retrieve a single record from the post-user-view view for a given user and returns it in an associative array + * When the requested record is a reshare activity, the system fetches the reshared original post. + * Otherwise the function reacts similar to selectFirstForUser + * + * @param integer $uid User ID + * @param array $selected + * @param array $condition + * @param array $params + * @return bool|array + * @throws \Exception + * @see DBA::select + */ + public static function selectOriginalForUser(int $uid, array $selected = [], array $condition = [], array $params = []) + { + $original_selected = $selected; + $remove = []; + if (!empty($selected)) { + foreach (['gravity', 'verb', 'thr-parent-id'] as $field) { + if (!in_array($field, $selected)) { + $selected[] = $field; + $remove[] = $field; + } + } + } + $result = self::selectFirstForUser($uid, $selected, $condition, $params); + if (empty($result)) { + return $result; + } + + if (($result['gravity'] != Item::GRAVITY_ACTIVITY) || ($result['verb'] != Activity::ANNOUNCE)) { + foreach ($remove as $field) { + unset($result[$field]); + } + return $result; + } + + return self::selectFirstForUser($uid, $original_selected, ['uri-id' => $result['thr-parent-id'], 'uid' => [0, $uid]], $params); + } + /** * Update existing post entries *