From: Philipp Holzer Date: Sat, 27 Jul 2019 22:19:38 +0000 (+0200) Subject: Refactoring Profile:: selectors X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2f5928f43af0ba5cd1be74d319d2305df9362744;p=friendica.git Refactoring Profile:: selectors --- diff --git a/include/api.php b/include/api.php index 7f8e85d022..bb241039ac 100644 --- a/include/api.php +++ b/include/api.php @@ -6206,13 +6206,13 @@ function api_friendica_profile_show($type) // get data of the specified profile id or all profiles of the user if not specified if ($profile_id != 0) { - $r = Profile::select(api_user(), $profile_id); + $r = Profile::getById(api_user(), $profile_id); // error message if specified gid is not in database if (!DBA::isResult($r)) { throw new BadRequestException("profile_id not available"); } } else { - $r = Profile::select(api_user()); + $r = Profile::getListByUser(api_user()); } // loop through all returned profiles and retrieve data and users $k = 0; diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 1437068f92..f215af1af5 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -46,22 +46,32 @@ class Profile } /** - * @brief Returns the profile based on a ID + * @brief Returns default profile for a given user ID and ID + * + * @param int $uid The contact ID + * @param int $id The contact owner ID + * @param array $fields The selected fields + * + * @return array Profile data for the ID + * @throws \Exception + */ + public static function getById(int $uid, int $id, array $fields = []) + { + return DBA::selectFirst('profile', $fields, ['uid' => $uid, 'id' => $id]); + } + + /** + * @brief Returns profile data for the contact owner * * @param int $uid The User ID - * @param int $id The id of the profile (optional) * @param array $fields The fields to retrieve * * @return array Array of profile data * @throws \Exception */ - public static function select(int $uid, int $id = null, array $fields = []) + public static function getListByUser(int $uid, array $fields = []) { - if (empty($id)) { - return DBA::selectToArray('profile', $fields, ['uid' => $uid]); - } else { - return DBA::selectFirst('profile', $fields, ['uid' => $uid, 'id' => $id]); - } + return DBA::selectToArray('profile', $fields, ['uid' => $uid]); } /**